本文主要讨论 openstack swift 的独立安装,一个节点作为代理节点运行 proxy 服务,其他节点作为存储节点。
1. 安装各种依赖
proxy node 和 storage node 都需要安装。
ubuntu 环境
1 | apt-get update; apt-get upgrade |
centos 环境
1 | yum update; yum upgrade |
安装 liberasurecode
1 | git clone https://github.com/openstack/liberasurecode.git |
在 /etc/ld.so.conf
中添加一行:/usr/local/lib
运行 sudo ldconfig
安装 swift client(如果不在此节点运行 client 程序可以不安装)
1 | cd ~ |
安装 swift
1 | cd ~ |
需要在每次开机时都创建一些需要的目录,修改 /etc/rc.local
添加如下内容:
1 | sudo mkdir -p /var/run/swift |
创建 swift 目录
1 | mkdir /etc/swift |
2. 在 proxy node 上安装服务
下载 proxy 的配置文件
1 | curl -o /etc/swift/proxy-server.conf \ |
删除注释和空格
1 | cp proxy-server.conf proxy-server.conf.bak |
更改: proxy-server.conf
:
1 | [DEFAULT] |
在上述配置中使用的认证方法是tempauth,即在 pipeline 部分添加 pipeline = ... tempauth ...
Tempauth 在配置文件中的格式:
user_
key: 密码
group有两种,.admin和.reseller_admin
.reseller_admin 具有对任何account操作的权限。
.admin 具有对所在的account 操作的权限。
如果没有设置以上组,则用户只能访问那些被.admin或.reseller_admin所允许的container。
3. 在storage node上安装服务
下面的操作要在每个node上都安装一次
格式化设备
查看设备
1 | fdisk -l |
找到一个新设备,分区(也可以不分区)
1 | fdisk /dev/sdb |
格式化为xfs文件系统
1 | mkfs.xfs /dev/sdb1 |
创建目录挂载点
1 | mkdir -p /srv/node/sdb1 |
设置开机自动挂载,编辑 /etc/fstab
文件,添加如下内容:
1 | /dev/sdb1 /srv/node/sdb1 xfs noatime,nodiratime,nobarrier,logbufs=8 0 2 |
挂载
1 | mount /srv/node/sdb1 |
配置 rsyncd 服务
修改 /etc/rsyncd.conf
:
1 | uid = user # 根据实际情况填写 |
编辑 /etc/default/rsync
,找到其中的RSYNC_ENABLE,将值设为true
1 | RSYNC_ENABLE=true |
启动 rsyncd 和 memcached, 并设置开机启动
ubuntu 环境中
1 | apt-get install sysv-rc-conf |
centos 环境中
1 | systemctl enable rsyncd.service |
测试
1 | rsync rsync://pub@127.0.0.1 |
也可以在别的机器上测试
配置 account container 和 object 服务
下载样例配置文件
1 | curl -o /etc/swift/account-server.conf \ |
删除注释和空格
1 | cp container-server.conf container-server.conf.bak |
配置 account-server.conf
:
1 | [DEFAULT] |
配置 container -server.conf
:
1 | [DEFAULT] |
配置 object-server.conf
:
1 | [DEFAULT] |
4. 配置swift.conf
在 proxy node 上操作。
下载样例文件:
1 | curl -o /etc/swift/swift.conf \ |
在[swift-hash]段落中,修改掉suffix和prefix的内容。随便什么内容都好,但是一旦你设置好了,就不能再次修改了。
1 | [swift-hash] |
然后在[storage-policy:0]段落中,编辑一下默认的存储策略:
1 | [storage-policy:0] |
将配置的文件复制到其他的 storage node 上,如果还有其他的 proxy node,也要复制到其他的 proxy node 上。
5. 创建 ring
创建ring: account ring, container ring, object ring.
1 | swift-ring-builder account.builder create 18 3 1 |
18 表示 partition 数为2的18次方,3表示 replication 数为3,1 表示分区数据的最短迁移间隔时间为1小时。
向 ring 中加入设备
1 | swift-ring-builder account.builder add r1z1-192.168.2.129:6202/sdb1 100 |
r1表示 region1, z1 表示 zone1, zone 这个概念是虚拟的,可以将一个 device 划定到一个 zone,在分配 partition 的时候会考虑到这个因素,尽量划分到不同的 zone 中。
sdb1 为 swift 所使用的存储空间。
100 代表设备的权重,也是在分配 partition 的时候会考虑的因素。
验证查看 ring
1 | swift-ring-builder account.builder |
重新平衡 ring
1 | swift-ring-builder account.builder rebalance |
分发 ring
将 /etc/swift 目录下生成的 container.ring.gz,object.ring.gz 和 account.ring.gz 复制到每一个 storage node上的 /etc/swift 目录中。
如果还有其他的 node 运行着 swift proxy 服务,那么这些配置文件也需要复制过去。
6. 启动服务
在 proxy node 上启动 proxy 服务
1 | sudo swift-init proxy start |
在 storage node 启动服务
1 | sudo swift-init account-server start |
停止服务只要将 start 改为 stop, 可以将上述命令写进一个脚本里一次运行。
7. 测试
需要先安装 swift client
1 | import swiftclient |
写在后面
动态扩容,加上需要添加的机器信息,重新生成 ring 文件。将新生成的 ring 文件放到每一个服务器的 /etc/swift 目录下。swift 的各个组件程序会定期重新读取 rings 文件。
服务器时间必须一致,不一致的话会出现问题。测试中有一台服务器比其他的慢了2小时,结果向这台 proxy 上传文件,返回成功,但是其实并没有上传成功,可能是由于时间原因,在其他机器看来这个文件已经被删除掉了。