注意要 按顺序 搭建服务,在 CentOS 7 安装 Openstack Rocky 版本 - 环境搭建 的基础上安装服务。
Object Storage service - 对象存储服务(Swift)
在 控制节点 和 对象存储节点 安装
对象存储节点(管理网络)
object1:10.0.0.51/24
object2:10.0.0.52/24
控制节点
For simplicity, this guide installs and configures the proxy service on the controller node.
身份认证和 API 配置
创建用户 swift
并添加到 admin
角色
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 . admin-openrc openstack user create --domain default --password-prompt swift openstack role add --project service --user swift admin
创建 swift
服务实体和端点(endpoint)
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 openstack service create --name swift --description "OpenStack Object Storage" object-store 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 客户端
巨坑 x 2
安装软件包
1 2 3 4 yum install openstack-swift-proxy python-swiftclient \ python-keystoneclient python-keystonemiddleware \ memcached -y
下载配置文件
1 2 curl -o /etc/swift/proxy-server.conf https://opendev.org/openstack/swift/raw/branch/stable/rocky/etc/proxy-server.conf-sample
编辑配置文件 /etc/swift/proxy-server.conf
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 [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#keystoneauth # user -> myrole operator_roles = admin,myrole [filter:authtoken] paste.filter_factory = keystonemiddleware.auth_token:filter_factory www_authenticate_uri = http://controller:5000 # 35357 -> 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 = swift delay_auth_decision = True [filter:cache] use = egg:swift#memcache memcache_servers = controller:11211
对象存储节点
For simplicity, this configuration references two storage nodes, each containing two empty local block storage devices. The instructions use /dev/sdb and /dev/sdc, but you can substitute different values for your particular nodes.
在 所有对象存储节点 执行相同操作。
创建存储设备
添加 2 块新硬盘
安装软件包
1 2 yum install xfsprogs rsync -y
格式化硬盘,并创建挂载点
1 2 3 4 5 6 7 mkfs.xfs /dev/sdb mkfs.xfs /dev/sdc mkdir -p /srv/node/sdbmkdir -p /srv/node/sdc
编辑 /etc/fstab
文件系统信息
1 2 3 # 添加内容 /dev/sdb /srv/node/sdb xfs noatime,nodiratime,nobarrier,logbufs=8 0 2 /dev/sdc /srv/node/sdc xfs noatime,nodiratime,nobarrier,logbufs=8 0 2
挂载设备
1 2 3 mount /srv/node/sdb mount /srv/node/sdc
编辑配置文件 /etc/rsyncd.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 # 添加配置,注意修改 IP 地址 uid = swift gid = swift log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid address = 10.0.0.51 [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
启用同步服务
1 2 3 systemctl enable rsyncd.service systemctl start rsyncd.service
安装和配置 swift
安装软件包
1 2 yum install openstack-swift-account openstack-swift-container openstack-swift-object -y
下载配置文件
1 2 3 4 curl -o /etc/swift/account-server.conf https://opendev.org/openstack/swift/raw/branch/stable/rocky/etc/account-server.conf-sample curl -o /etc/swift/container-server.conf https://opendev.org/openstack/swift/raw/branch/stable/rocky/etc/container-server.conf-sample curl -o /etc/swift/object-server.conf https://opendev.org/openstack/swift/raw/branch/stable/rocky/etc/object-server.conf-sample
编辑账户服务配置文件 /etc/swift/account-server.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # 注意修改 IP 地址 [DEFAULT] bind_ip = 10.0.0.51 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # 注意修改 IP 地址 [DEFAULT] bind_ip = 10.0.0.51 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # 注意修改 IP 地址 [DEFAULT] bind_ip = 10.0.0.51 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
设置目录权限
1 2 3 4 5 6 7 chown -R swift:swift /srv/nodemkdir -p /var/cache/swiftchown -R root:swift /var/cache/swiftchmod -R 775 /var/cache/swift
创建和分发初始化 rings
在 控制节点 上执行操作
创建账户 ring
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 cd /etc/swiftswift-ring-builder account.builder create 10 3 1 swift-ring-builder account.builder add --region 1 --zone 1 --ip 10.0.0.51 --port 6202 --device sdb --weight 100 swift-ring-builder account.builder add --region 1 --zone 1 --ip 10.0.0.51 --port 6202 --device sdc --weight 100 swift-ring-builder account.builder add --region 1 --zone 2 --ip 10.0.0.52 --port 6202 --device sdb --weight 100 swift-ring-builder account.builder add --region 1 --zone 2 --ip 10.0.0.52 --port 6202 --device sdc --weight 100 swift-ring-builder account.builder swift-ring-builder account.builder rebalance
创建容器 ring
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 cd /etc/swiftswift-ring-builder container.builder create 10 3 1 swift-ring-builder container.builder add --region 1 --zone 1 --ip 10.0.0.51 --port 6201 --device sdb --weight 100 swift-ring-builder container.builder add --region 1 --zone 1 --ip 10.0.0.51 --port 6201 --device sdc --weight 100 swift-ring-builder container.builder add --region 1 --zone 2 --ip 10.0.0.52 --port 6201 --device sdb --weight 100 swift-ring-builder container.builder add --region 1 --zone 2 --ip 10.0.0.52 --port 6201 --device sdc --weight 100 swift-ring-builder container.builder swift-ring-builder container.builder rebalance
创建对象 ring
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 cd /etc/swiftswift-ring-builder object.builder create 10 3 1 swift-ring-builder object.builder add --region 1 --zone 1 --ip 10.0.0.51 --port 6200 --device sdb --weight 100 swift-ring-builder object.builder add --region 1 --zone 1 --ip 10.0.0.51 --port 6200 --device sdc --weight 100 swift-ring-builder object.builder add --region 1 --zone 2 --ip 10.0.0.52 --port 6200 --device sdb --weight 100 swift-ring-builder object.builder add --region 1 --zone 2 --ip 10.0.0.52 --port 6200 --device sdc --weight 100 swift-ring-builder object.builder swift-ring-builder object.builder rebalance
分发配置文件
将 /etc/swift
目录中的以下文件复制到每个对象存储节点的 /etc/swift
目录
1 2 3 account.ring.gz container.ring.gz object.ring.gz
使用 scp
复制
1 2 3 scp account.ring.gz container.ring.gz object.ring.gz root@object1:/etc/swift scp account.ring.gz container.ring.gz object.ring.gz root@object2:/etc/swift
完成安装
在 控制节点 上执行操作
下载配置文件
1 2 curl -o /etc/swift/swift.conf https://opendev.org/openstack/swift/raw/branch/stable/rocky/etc/swift.conf-sample
编辑配置文件 /etc/swift/swift.conf
1 2 3 4 5 6 7 8 [swift-hash] swift_hash_path_suffix = HASH_PATH_SUFFIX swift_hash_path_prefix = HASH_PATH_PREFIX [storage-policy:0] name = Policy-0 default = yes
将该配置文件复制到每个对象存储节点的 /etc/swift
目录
1 2 scp /etc/swift/swift.conf root@object1:/etc/swift scp /etc/swift/swift.conf root@object2:/etc/swift
在 所有节点 上设置 swift 配置文件目录的权限(如果有)
1 chown -R root:swift /etc/swift
在 控制节点 启用对象存储代理服务
1 2 systemctl enable openstack-swift-proxy.service memcached.service systemctl restart openstack-swift-proxy.service memcached.service
在所有 对象存储节点 启用服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 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
验证
在 控制节点 上执行操作
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 . demo-openrc swift stat openstack container create container1 echo 'Hello OpenStack!' > test.txtopenstack object create container1 test.txt openstack object list container1 openstack object save container1 test.txt