swift分片储存
Swift分片存储实操手册
3.实战案例——Swift分片存储
3.1 案例目标
(1)了解Swift对象存储的基本使用。
(2)了解Swift对象存储如何对大文件进行分片存储。
3.2 案例分析
1.规划节点
Swift分片存储的节点规划,见表3-1-1。
表3-1-1 节点规划
IP |
主机名 |
节点 |
172.33.16.10 |
controller |
OpenStack控制节点 |
172.33.16.20 |
compute |
OpenStack计算节点 |
2.基础准备
使用OpenStack平台的两台节点,自行使用脚本安装Swift对象存储服务。然后使用这两台进行实验。节点规划表中的IP地址为作者的IP地址,在进行实操案例的时候,按照自己的环境规划网络与IP地址。
3.3 案例实施
1.Swift分片存储
(1)查询Swift ring的配置
使用远程连接工具连接到controller节点,使用命令查看swift ring的Region、partition、Replica配置分别为多少,具体命令如下:
首先查询swfit的状态:
[root@controller ~]# source /etc/keystone/admin-openrc.sh
[root@controller ~]# swift stat
Account: AUTH_f3a4fbd6a85848be8aab2773fdbcaf2f
Containers: 2
Objects: 0
Bytes: 0
Containers in policy "policy-0": 2
Objects in policy "policy-0": 0
Bytes in policy "policy-0": 0
X-Account-Project-Domain-Id: 362fafdb6a4046f1874757d26e183b80
X-Openstack-Request-Id: tx2eb51990b11249599bb22-005f900188
X-Timestamp: 1603231872.80367
X-Trans-Id: tx2eb51990b11249599bb22-005f900188
Content-Type: application/json; charset=utf-8
Accept-Ranges: bytes
进入/etc/swift目录,使用命令查看:
[root@controller ~]# cd /etc/swift/
[root@controller swift]# swift-ring-builder object.builder
object.builder, build version 2, id 93794180e60a4dcebf63098cad3c7fed
1024 partitions, 1.000000 replicas, 1 regions, 1 zones, 1 devices, 0.00 balance, 0.00 dispersion
The minimum number of hours before a partition can be reassigned is 1 (0:00:00 remaining)
The overload factor is 0.00% (0.000000)
Ring file object.ring.gz is up-to-date
Devices: id region zone ip address:port replication ip:port name weight partitions balance flags meta
0 1 1 172.33.16.20:6000 172.33.16.20:6000 sda5 100.00 1024 0.00
可以看到swift的存储区域是172.33.16.20这台服务器,也就是计算节点,使用盘符是/dev/sda5大小是100G。
(2)创建容器
使用命令创建一个容器test并查看容器的状态信息,命令如下:
[root@controller ~]# swift post test
[root@controller ~]# swift stat test
Account: AUTH_f3a4fbd6a85848be8aab2773fdbcaf2f
Container: test
Objects: 0
Bytes: 0
Read ACL:
Write ACL:
Sync To:
Sync Key:
Accept-Ranges: bytes
X-Storage-Policy: Policy-0
Last-Modified: Wed, 21 Oct 2020 17:27:34 GMT
X-Timestamp: 1603231872.83676
X-Trans-Id: txc4ada2c7aee0456fbe47a-005f906f8b
Content-Type: application/json; charset=utf-8
X-Openstack-Request-Id: txc4ada2c7aee0456fbe47a-005f906f8b
(3)上传镜像并分片存储
将提供的cirros-0.3.4-x86_64-disk.img镜像上传至controller节点的/root目录下,并使用命令上传至test容器中,进行分片存储,每个片段的大小为10M,命令如下:
[root@controller ~]# ll
total 8088152
-rw-------. 1 root root 1741 Oct 20 16:11 anaconda-ks.cfg
-rw-r--r--. 1 root root 13287936 Oct 21 14:23 cirros-0.3.4-x86_64-disk.img
上传镜像至容器并进行分片:
[root@controller ~]# swift upload test -S 10000000 cirros-0.3.4-x86_64-disk.img
cirros-0.3.4-x86_64-disk.img segment 0
cirros-0.3.4-x86_64-disk.img segment 1
cirros-0.3.4-x86_64-disk.img
查看cirros镜像的存储路径:
[root@controller ~]# swift stat test cirros-0.3.4-x86_64-disk.img
Account: AUTH_f3a4fbd6a85848be8aab2773fdbcaf2f
Container: test
Object: cirros-0.3.4-x86_64-disk.img
Content Type: application/octet-stream
Content Length: 13287936
Last Modified: Wed, 21 Oct 2020 18:24:08 GMT
ETag: "cca17a689bfcd70118fabc833af0d033"
Manifest: test_segments/cirros-0.3.4-x86_64-disk.img/1603304613.782459/13287936/10000000/
Meta Mtime: 1603304613.782459
Accept-Ranges: bytes
X-Timestamp: 1603304647.94130
X-Trans-Id: txfe2a87fc27e24968853dc-005f907cd8
X-Openstack-Request-Id: txfe2a87fc27e24968853dc-005f907cd8
查看存储路径中的数据片:
[root@controller ~]# swift list test_segments
cirros-0.3.4-x86_64-disk.img/1603304613.782459/13287936/10000000/00000000
cirros-0.3.4-x86_64-disk.img/1603304613.782459/13287936/10000000/00000001
可以看到,cirros镜像在上传至swfit对象存储中被分片存储了,单个存储片的大小为10M,因为该镜像大小为13M左右,所有分成了两个存储片。