【Openstack Train】十六、swift安装

OpenStack Swift是一个分布式对象存储系统,它可以为大规模的数据存储提供高可用性、可扩展性和数据安全性。Swift是OpenStack的一个核心组件,它允许用户将大量的数据存储在云上,并且可以随时访问、检索和管理这些数据。

Swift的设计目标是为了处理海量数据和大规模数据的高并发访问,它采用了一些独特的技术和架构,如分布式存储、数据冗余、负载均衡、数据分片、对象容器等。

在先前的教程中,介绍了安装openstack及其相关组件的具体过程,本文介绍如何安装swift。

在按照本教程操作之前,请确保完成以下配置:

【Openstack Train安装】一、虚拟机创建

【Openstack Train安装】二、NTP安装

【Openstack Train安装】三、openstack安装

【Openstack Train安装】四、MariaDB/RabbitMQ 安装

【Openstack Train安装】五、Memcached/Etcd安装

【Openstack Train安装】六、Keystone安装

【Openstack Train安装】七、glance安装

【Openstack Train安装】八、placement安装

【Openstack Train安装】九、Nova安装

【Openstack Train安装】十、Neutron安装

【Openstack Train安装】十一、Dashboard 安装

【Openstack Train安装】十二、Cinder安装

安装环境如下

|--------------------|------------|
| VMware Workstation | V17.0 |
| 本机系统 | win11 |
| 虚拟机系统 | CentOS 7.5 |

一、控制节点

以下操作在控制节点运行

登录admin:

bash 复制代码
. admin-openrc

创建swift用户:

bash 复制代码
openstack user create --domain default --password-prompt swift

如下图:

bash 复制代码
openstack service create --name swift --description "OpenStack Object Storage" object-store

添加admin权限:

bash 复制代码
openstack role add --project service --user swift admin

创建服务入口:

bash 复制代码
openstack service create --name swift --description "OpenStack Object Storage" object-store

如下图:

创建API端点:

bash 复制代码
openstack endpoint create --region RegionOne object-store public http://controller:8080/v1/AUTH_%\(project_id\)s
openstack endpoint create --region RegionOne object-store internal http://controller:8080/v1/AUTH_%\(project_id\)s
openstack endpoint create --region RegionOne object-store admin http://controller:8080/v1

如下图:

安装swift:

bash 复制代码
yum install openstack-swift-proxy python-swiftclient python-keystoneclient python-keystonemiddleware memcached -y

获取代理服务配置:

bash 复制代码
curl -o /etc/swift/proxy-server.conf https://opendev.org/openstack/swift/raw/branch/master/etc/proxy-server.conf-sample

如下图:

备份并删除配置文件的注释:

bash 复制代码
mv /etc/swift/proxy-server.conf /etc/swift/proxy-server.conf.source
cat /etc/swift/proxy-server.conf.source | grep -Ev "^#|^$" > /etc/swift/proxy-server.conf

编辑/etc/swift/proxy-server.conf,删除[pipeline:main]tempurltempauth ,完成以下内容:

bash 复制代码
[DEFAULT]
bind_port = 8080
user = swift
swift_dir = /etc/swift

[pipeline:main]
pipeline = catch_errors gatekeeper healthcheck proxy-logging cache container_sync bulk ratelimit authtoken keystoneauth container-quotas account-quotas slo dlo versioned_writes proxy-logging proxy-server

[app:proxy-server]
use = egg:swift#proxy
account_autocreate = True


[filter:keystoneauth]
use = egg:swift
operator_roles = admin,user

[filter:authtoken]
paste.filter_factory = keystonemiddleware.auth_token:filter_factory
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_id = default
user_domain_id = default
project_name = service
username = swift
password = 123456
delay_auth_decision = True

[filter:cache]
use = egg:swift
memcache_servers = controller:11211

二、计算节点

本教程只包含控制节点和计算节点,计算节点也做存储节点用,以下操作在计算节点运行。

安装相关库:

bash 复制代码
yum install xfsprogs rsync -y

添加4个20GB的硬盘,添加的教程可以参考【Openstack Train安装】十二、Cinder安装,一共6块硬盘(cinder添加一个,本文添加4个):

使用以下命令扫描硬盘:

bash 复制代码
for i in /sys/class/scsi_host/host*/scan;do echo "- - -" >$i;done

查看硬盘列表:

bash 复制代码
fdisk -l

如下图:

转换/dev/sdc为XFS格式(因为我的前两块硬盘被用了,所以这里使用第三个硬盘,请根据自己的情况调整):

bash 复制代码
mkfs.xfs /dev/sdc
mkfs.xfs /dev/sdd
mkfs.xfs /dev/sde
mkfs.xfs /dev/sdf

如下图:

创建挂载的目录:

bash 复制代码
mkdir -p /srv/node/sdc
mkdir -p /srv/node/sdd
mkdir -p /srv/node/sde
mkdir -p /srv/node/sdf

编辑 /etc/fstab,添加以下内容:

bash 复制代码
/dev/sdc /srv/node/sdc xfs noatime,nodiratime,logbufs=8 0 2
/dev/sdd /srv/node/sdd xfs noatime,nodiratime,logbufs=8 0 2
/dev/sde /srv/node/sde xfs noatime,nodiratime,logbufs=8 0 2
/dev/sdf /srv/node/sdf xfs noatime,nodiratime,logbufs=8 0 2

如下图:

挂载硬盘:

bash 复制代码
mount /srv/node/sdc
mount /srv/node/sdd
mount /srv/node/sde
mount /srv/node/sdf

创建文件或者编辑/etc/rsyncd.conf ,并添加以下内容:

bash 复制代码
uid = swift
gid = swift
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
address = 10.0.0.31

[account]
max connections = 2
path = /srv/node/
read only = False
lock file = /var/lock/account.lock

[container]
max connections = 2
path = /srv/node/
read only = False
lock file = /var/lock/container.lock

[object]
max connections = 2
path = /srv/node/
read only = False
lock file = /var/lock/object.lock

设置开机自启,并启动该服务:

bash 复制代码
systemctl enable rsyncd.service
systemctl start rsyncd.service

安装包:

bash 复制代码
yum install openstack-swift-account openstack-swift-container openstack-swift-object -y

获取相关信息:

bash 复制代码
curl -o /etc/swift/account-server.conf https://opendev.org/openstack/swift/raw/branch/master/etc/account-server.conf-sample
curl -o /etc/swift/container-server.conf https://opendev.org/openstack/swift/raw/branch/master/etc/container-server.conf-sample
curl -o /etc/swift/object-server.conf https://opendev.org/openstack/swift/raw/branch/master/etc/object-server.conf-sample

保存并备份/etc/swift/account-server.conf:

bash 复制代码
mv /etc/swift/account-server.conf /etc/swift/account-server.conf.source
cat /etc/swift/account-server.conf.source | grep -Ev "^#|^$" > /etc/swift/account-server.conf

编辑/etc/swift/account-server.conf,并设置以下信息:

bash 复制代码
[DEFAULT]
bind_ip = 10.0.0.31
bind_port = 6202
user = swift
swift_dir = /etc/swift
devices = /srv/node
mount_check = True

[pipeline:main]
pipeline = healthcheck recon account-server

[filter:recon]
use = egg:swift#recon
recon_cache_path = /var/cache/swift

备份并删除/etc/swift/container-server.conf的注释:

bash 复制代码
mv /etc/swift/container-server.conf /etc/swift/container-server.conf.source
cat /etc/swift/container-server.conf.source | grep -Ev "^#|^$" > /etc/swift/container-server.conf

编辑/etc/swift/container-server.conf,做出如下改动:

bash 复制代码
[DEFAULT]
bind_ip = 10.0.0.31
bind_port = 6201
user = swift
swift_dir = /etc/swift
devices = /srv/node
mount_check = True

[pipeline:main]
pipeline = healthcheck recon container-server

[filter:recon]
use = egg:swift#recon
recon_cache_path = /var/cache/swift

备份/etc/swift/object-server.conf:

bash 复制代码
mv /etc/swift/object-server.conf /etc/swift/object-server.conf.source
cat /etc/swift/object-server.conf.source | grep -Ev "^#|^$" > /etc/swift/object-server.conf

编辑/etc/swift/object-server.conf,添加以下内容:

bash 复制代码
[DEFAULT]
bind_ip = 10.0.0.31
bind_port = 6200
user = swift
swift_dir = /etc/swift
devices = /srv/node
mount_check = True

[pipeline:main]
pipeline = healthcheck recon object-server

[filter:recon]
use = egg:swift#recon
recon_cache_path = /var/cache/swift
recon_lock_path = /var/lock

修改文件权限:

bash 复制代码
chown -R swift:swift /srv/node

创建相关目录并授予权限:

bash 复制代码
mkdir -p /var/cache/swift
chown -R root:swift /var/cache/swift
chmod -R 775 /var/cache/swift

三、完成安装

在控制节点运行以下命令。

进入/etc/swift 目录:

创建账户account.builder:

bash 复制代码
swift-ring-builder account.builder create 10 3 1

将存储节点添加到ring:

bash 复制代码
swift-ring-builder account.builder add --region 1 --zone 1 --ip 10.0.0.31 --port 6202 --device sdc --weight 100
swift-ring-builder account.builder add --region 1 --zone 1 --ip 10.0.0.31 --port 6202 --device sdd --weight 100
swift-ring-builder account.builder add --region 1 --zone 1 --ip 10.0.0.31 --port 6202 --device sde --weight 100
swift-ring-builder account.builder add --region 1 --zone 1 --ip 10.0.0.31 --port 6202 --device sdf --weight 100

查看ring:

bash 复制代码
swift-ring-builder account.builder

如下图:

rebalance ring:

bash 复制代码
swift-ring-builder account.builder rebalance

如下图:

创建容器ring:

bash 复制代码
swift-ring-builder container.builder create 10 3 1

添加到ring:

bash 复制代码
swift-ring-builder container.builder add --region 1 --zone 1 --ip 10.0.0.31 --port 6201 --device sdc --weight 100
swift-ring-builder container.builder add --region 1 --zone 1 --ip 10.0.0.31 --port 6201 --device sdd --weight 100
swift-ring-builder container.builder add --region 1 --zone 1 --ip 10.0.0.31 --port 6201 --device sde --weight 100
swift-ring-builder container.builder add --region 1 --zone 1 --ip 10.0.0.31 --port 6201 --device sdf --weight 100

查看ring:

bash 复制代码
swift-ring-builder container.builder

如下图:

rebalance ring:

bash 复制代码
swift-ring-builder container.builder rebalance

如下图:

创建对象ring:

bash 复制代码
swift-ring-builder object.builder create 10 3 1

添加到ring:

bash 复制代码
swift-ring-builder object.builder add --region 1 --zone 1 --ip 10.0.0.31 --port 6200 --device sdc --weight 100
swift-ring-builder object.builder add --region 1 --zone 1 --ip 10.0.0.31 --port 6200 --device sdd --weight 100
swift-ring-builder object.builder add --region 1 --zone 1 --ip 10.0.0.31 --port 6200 --device sde --weight 100
swift-ring-builder object.builder add --region 1 --zone 1 --ip 10.0.0.31 --port 6200 --device sdf --weight 100

查看ring:

bash 复制代码
swift-ring-builder object.builder

如下:

rebalance ring:

bash 复制代码
swift-ring-builder object.builder rebalance

如下图:

将account.ring.gz, container.ring.gz和object.ring.gz三个文件拷贝到其他节点的/etc/swift目录,使用下面的命令(Ip地址要换成自己的,本教程计算节点是10.0.0.31):

bash 复制代码
scp /etc/swift/*.ring.gz root@10.0.0.31:/etc/swift/

如下图,复制成功:

在控制节点运行以下命令:

bash 复制代码
curl -o /etc/swift/swift.conf https://opendev.org/openstack/swift/raw/branch/master/etc/swift.conf-sample

备份/etc/swift/swift.conf,并删除注释:

bash 复制代码
mv /etc/swift/swift.conf /etc/swift/swift.conf.source
cat /etc/swift/swift.conf.source | grep -Ev "^#|^$" > /etc/swift/swift.conf

编辑/etc/swift/swift.conf,完成以下配置(该文件默认已经配置好了):

bash 复制代码
[swift-hash]
...
swift_hash_path_suffix = changeme
swift_hash_path_prefix = changeme

[storage-policy:0]
...
name = Policy-0
default = yes

swift.conf 复制到其他存储节点的 /etc/swift 目录下,本教程只需要复制到计算节点,运行以下命令:

bash 复制代码
scp /etc/swift/swift.conf root@10.0.0.31:/etc/swift/

在所有节点,修改文件权限:

bash 复制代码
chown -R root:swift /etc/swift

控制节点运行:

bash 复制代码
systemctl enable openstack-swift-proxy.service memcached.service
systemctl start openstack-swift-proxy.service memcached.service

计算节点修改权限:

bash 复制代码
chown -R swift:swift /srv/node

计算节点运行:

bash 复制代码
systemctl enable openstack-swift-account.service openstack-swift-account-auditor.service openstack-swift-account-reaper.service openstack-swift-account-replicator.service
systemctl start openstack-swift-account.service openstack-swift-account-auditor.service openstack-swift-account-reaper.service openstack-swift-account-replicator.service
systemctl enable openstack-swift-container.service openstack-swift-container-auditor.service openstack-swift-container-replicator.service openstack-swift-container-updater.service
systemctl start openstack-swift-container.service openstack-swift-container-auditor.service openstack-swift-container-replicator.service openstack-swift-container-updater.service
systemctl enable openstack-swift-object.service openstack-swift-object-auditor.service openstack-swift-object-replicator.service openstack-swift-object-updater.service
systemctl start openstack-swift-object.service openstack-swift-object-auditor.service openstack-swift-object-replicator.service openstack-swift-object-updater.service

四、验证

登录demo用户:

bash 复制代码
. demo-openrc

查看swift状态(如果权限有问题就登录admin账户):

bash 复制代码
swift stat

如下图:

创建container1 容器:

bash 复制代码
openstack container create container1

如下图:

上传文件到container1容器(我传的cirros):

bash 复制代码
openstack object create container1 cirros-0.4.0-x86_64-disk.img

如下图:

查看容器中的文件:

bash 复制代码
openstack object list container1

如下图:

下载容器中的文件(cirros镜像):

bash 复制代码
openstack object save container1 cirros-0.4.0-x86_64-disk.img

如下图:

相关推荐
南宫理的日知录1 天前
「Python数据科学」标量、向量、矩阵、张量与多维数组的辨析
python·numpy·数据科学
m0_748238921 天前
webgis入门实战案例——智慧校园
开发语言·ios·swift
aherhuo1 天前
基于openEuler22.09部署OpenStack Yoga云平台(一)
linux·运维·服务器·openstack
ROBOT玲玉2 天前
Milvus 中,FieldSchema 的 dim 参数和索引参数中的 “nlist“ 的区别
python·机器学习·numpy
GocNeverGiveUp2 天前
机器学习2-NumPy
人工智能·机器学习·numpy
Swift社区2 天前
Excel 列名称转换问题 Swift 解答
开发语言·excel·swift
AI小白白猫3 天前
20241230 基础数学-线性代数-(1)求解特征值(numpy, scipy)
线性代数·numpy·scipy
东坡肘子3 天前
肘子的 Swift 周报 #063|异种肾脏移植取得突破
swiftui·swift·apple
威化饼的一隅4 天前
【多模态】swift-3框架使用
人工智能·深度学习·大模型·swift·多模态
終不似少年遊*6 天前
云计算HCIP-OpenStack01
云原生·云计算·学习笔记·openstack·hcip·虚拟化