kolla部署swift

kolla部署swift

kolla实现对象存储方式有两种:

  • 利用ceph_rgw实现
  • 部署swift实现

本篇博客介绍利用kolla部署swift实现openstack对象存储

环境准备

我这是一个all-in-one的环境,利用kolla部署了一个pike版本,部署方法请参考kolla部署openstack Pike版
我这台虚拟机一共有5块盘,分别为sda,sdb,sdc,sdd,sde。sda为系统盘,sdb,sdc,sdd,为ceph的osd用,sde用于做swift

打标签

swift要求可用的块设备用来存储,所以我事先准备了一个硬盘sde作为存储设备,在部署需要给这块盘打一个特殊的标签。

1
2
3
4
5
6
7
index=0
for d in sde; do
# 因为我这就有一块用于swift存储的盘sde。
parted /dev/${d} -s -- mklabel gpt mkpart KOLLA_SWIFT_DATA 1 -1
sudo mkfs.xfs -f -L d${index} /dev/${d}1
(( index++ ))
done

Rings

kolla在部署swift前,需要生成rings,这是一种二进制压缩文件,在较高的级别上,让各种快速服务知道集群中的数据在哪里,这里官方给了一个脚本,简单的配置一下即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# STORAGE_NODES=(192.168.0.2 192.168.0.3 192.168.0.4)
# 这里是swift走的存储网络的ip,因为我是all-in-one环境,所以IP只有一个,这里我的swift存储用网将和管理网在一起
STORAGE_NODES=(192.168.10.139)
# KOLLA_SWIFT_BASE_IMAGE="docker_registry/docker_namespace/centos-source-swift-base:openstack_release"
# 这里按照需求填写
KOLLA_SWIFT_BASE_IMAGE="192.168.10.139:4000/lokolla/centos-source-swift-base:5.0.1"

mkdir -p /etc/kolla/config/swift

# Object ring
docker run \
--rm \
-v /etc/kolla/config/swift/:/etc/kolla/config/swift/ \
$KOLLA_SWIFT_BASE_IMAGE \
swift-ring-builder \
/etc/kolla/config/swift/object.builder create 10 3 1

for node in ${STORAGE_NODES[@]}; do
for i in {0..2}; do
docker run \
--rm \
-v /etc/kolla/config/swift/:/etc/kolla/config/swift/ \
$KOLLA_SWIFT_BASE_IMAGE \
swift-ring-builder \
/etc/kolla/config/swift/object.builder add r1z1-${node}:6000/d${i} 1;
done
done

# Account ring
docker run \
--rm \
-v /etc/kolla/config/swift/:/etc/kolla/config/swift/ \
$KOLLA_SWIFT_BASE_IMAGE \
swift-ring-builder \
/etc/kolla/config/swift/account.builder create 10 3 1

for node in ${STORAGE_NODES[@]}; do
for i in {0..2}; do
docker run \
--rm \
-v /etc/kolla/config/swift/:/etc/kolla/config/swift/ \
$KOLLA_SWIFT_BASE_IMAGE \
swift-ring-builder \
/etc/kolla/config/swift/account.builder add r1z1-${node}:6001/d${i} 1;
done
done

# Container ring
docker run \
--rm \
-v /etc/kolla/config/swift/:/etc/kolla/config/swift/ \
$KOLLA_SWIFT_BASE_IMAGE \
swift-ring-builder \
/etc/kolla/config/swift/container.builder create 10 3 1

for node in ${STORAGE_NODES[@]}; do
for i in {0..2}; do
docker run \
--rm \
-v /etc/kolla/config/swift/:/etc/kolla/config/swift/ \
$KOLLA_SWIFT_BASE_IMAGE \
swift-ring-builder \
/etc/kolla/config/swift/container.builder add r1z1-${node}:6002/d${i} 1;
done
done

for ring in object account container; do
docker run \
--rm \
-v /etc/kolla/config/swift/:/etc/kolla/config/swift/ \
$KOLLA_SWIFT_BASE_IMAGE \
swift-ring-builder \
/etc/kolla/config/swift/${ring}.builder rebalance;
done

globals.yml文件

1
2
3
4
# vim /etc/kolla/globals.yml
#enable_ceph_rgw: "no"
enable_swift: "yes"
#enable_ceph_rgw_keystone: "no"

这里需要说下,ceph_rgw实现的对象存储和swift实现的对象存储二者不能共存。如果要想用ceph_rgw实现以上步骤均不要做直接修改globals文件后deploy即可

1
2
3
4
# vim /etc/kolla/globals.yml
enable_ceph_rgw: "yes"
# enable_swift: "no"
enable_ceph_rgw_keystone: "yes"

部署

1
# kolla-ansible deploy

验证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# source /etc/kolla/admin-openrc.sh 
# openstack container create mycontainer
+---------------------------------------+-------------+------------------------------------+
| account | container | x-trans-id |
+---------------------------------------+-------------+------------------------------------+
| AUTH_2a568be969b34c288ef52a2987973145 | mycontainer | txc68d723c0c934a7282cfe-005a1e5d11 |
+---------------------------------------+-------------+------------------------------------+
[[email protected] ~]# openstack object create mycontainer README.rst
+------------+-------------+----------------------------------+
| object | container | etag |
+------------+-------------+----------------------------------+
| README.rst | mycontainer | a2f288979d0af55c5e9313f525c75615 |
+------------+-------------+----------------------------------+
# openstack container show mycontainer
+--------------+---------------------------------------+
| Field | Value |
+--------------+---------------------------------------+
| account | AUTH_2a568be969b34c288ef52a2987973145 |
| bytes_used | 39 |
| container | mycontainer |
| object_count | 1 |
+--------------+---------------------------------------+
# openstack object store account show
+------------+---------------------------------------+
| Field | Value |
+------------+---------------------------------------+
| Account | AUTH_2a568be969b34c288ef52a2987973145 |
| Bytes | 0 |
| Containers | 1 |
| Objects | 0 |
+------------+---------------------------------------+

参考文章

https://docs.openstack.org/kolla-ansible/latest/reference/swift-guide.html#rings