本文主要是针对初次使用swift的同学,想了解下swift,以及swift如何安装,至于如果不适用keystone进行鉴权认证的话,也可以不安装keystone。
本文基于openstack 的juno版本 2.2,下载路径(https://launchpad.net/swift/+series)
(由于没法上传附件,本文所有用到的rpm包的路径为: )
1 Switf使用源码包安装
1.1 安装前准备,以及源码获取
当前使用swift的juno的2.2版本搭建对象存储服务器
1.1.1 Swift的源码包
swift-2.2.0.tar.gz
1.1.2 Swift的依赖包
依赖库:
python-configobj-4.6.0-3.el6.noarch.rpm
python-eventlet-0.14.0-1.el6.noarch.rpm
python-greenlet-0.4.2-1.el6.x86_64.rpm
python-netifaces-0.5-1.el6.x86_64.rpm
python-paste-deploy1.5-1.5.0-5.el6.noarch.rpm
python-setuptools-0.6.10-3.el6.noarch.rpm
python-simplejson-2.0.9-3.1.el6.x86_64.rpm
pyxattr-0.5.0-1.el6.x86_64.rpm
rsync-3.0.6-12.el6.x86_64.rpm
xfs的安装包:
xfsdump-3.0.4-3.el6.x86_64.rpm
xfsprogs-3.1.1-14.el6.x86_64.rpm
将所有的依赖包安装(先判断当前rpm是否已经安装,没有再安装)
1.2 安装swift
1)解压源码
tar –xf swift-2.2.0.tar.gz
cd swift-2.2.0
2)修改swift-2.2.0/requirements.txt的依赖包
将
dnspython>=1.9.4
eventlet>=0.9.15
greenlet>=0.3.1
netifaces>=0.5,!=0.10.0,!=0.10.1
pastedeploy>=1.3.3
simplejson>=2.0.9
xattr>=0.4
修改成
eventlet>=0.9.15
greenlet>=0.3.1
netifaces>=0.5,!=0.10.0,!=0.10.1
pastedeploy>=1.3.3
simplejson>=2.0.9
pyxattr>=0.4
当前用不到dnspython,xattr也叫做pyxattr
3)安装
python setup.py build
python setup.py install
1.3 修改配置文件
1.3.1 /etc/swift/swift.conf
vi /etc/swift/swift.conf
获取:hash_path = `od -t x8 -N 8 -A n </dev/random`
[swift-hash]
swift_hash_path_suffix = $hash_path
1.3.2 /etc/swift/proxy-server.conf
vi /etc/swift/proxy-server.conf
[DEFAULT]
bind_port = 8080
workers = 8
user = swift
log_facility = LOG_LOCAL0
[pipeline:main]
pipeline = healthcheck cache authtoken keystone proxy-logging proxy-server
# pipeline = healthcheck cache proxy-logging proxy-server
[app:proxy-server]
use = egg:swift#proxy
allow_account_management = true
account_autocreate = true
log_facility = LOG_LOCAL0
log_level = DEBUG
[filter:cache]
use = egg:swift#memcache
memcache_servers = 127.0.0.1:11211
[filter:catch_errors]
use = egg:swift#catch_errors
[filter:healthcheck]
use = egg:swift#healthcheck
[filter:proxy-logging]
use = egg:swift#proxy_logging
[filter:keystone]
use = egg:swift#keystoneauth
operator_roles = admin, SwiftOperator
is_admin = true
cache = swift.cache
[filter:authtoken]
paste.filter_factory = keystonemiddleware.auth_token:filter_factory
admin_tenant_name = %SERVICE_TENANT_NAME%
admin_user = %SERVICE_USER%
admin_password = %SERVICE_PASSWORD%
auth_host = 127.0.0.1
auth_port = 35357
auth_protocol = http
signing_dir = /tmp/keystone-signing-swift
1.3.2.1 注意点:
1)
pipeline = healthcheck cache authtoken keystone proxy-logging proxy-server
以上这个配置是带token访问swift的
# pipeline = healthcheck cache proxy-logging proxy-server
以上这个配置是不带token访问swift的
1.3.3 /etc/rsyslog.conf
vi /etc/rsyslog.conf
local0.* /var/log/swift/account.log
local1.* /var/log/swift/account-rest.log
1.3.3.1 注意点
配置日志的时候,不要跟日志的其他模块冲突
修改后需要重启 syslog
service rsyslog restart
1.3.4 /etc/rsyncd.conf
1)vi /etc/rsyncd.conf
secrets file = /etc/rsyncd.secrets
uid = swift
gid = swift
use chroot = no
max connections = 5
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
[domain]
comment = welcome
path = /var/www/domain/
auth users = root
hosts allow = 127.0.0.1
hosts deny = *
list = true
read only = no
[account]
max connections = 2
path = /home/swift/
read only = false
lock file = /var/lock/account.lock
[container]
max connections = 2
path = /home/swift/
read only = false
lock file = /var/lock/container.lock
[object]
max connections = 2
path = /home/swift/
read only = false
lock file = /var/lock/object.lock
2)rsync
rsync –daemon
1.3.5 /etc/swift/account-server.conf
1) vi /etc/swift/account-server.conf
[DEFAULT]
bind_ip = 192.168.2.202
bind_port = 6002
workers = 2
mount_check = false
log_facility = LOG_LOCAL0
devices = /srv/1/node
[pipeline:main]
pipeline = account-server
[app:account-server]
use = egg:swift#account
[account-replicator]
log_name = account-replicator
log_facility = LOG_LOCAL1
[account-auditor]
log_name = account-auditor
log_facility = LOG_LOCAL1
[account-reaper]
log_facility = LOG_LOCAL1
1.3.6 /etc/swift/container-server.conf
1) vi /etc/swift/container-server.conf
[DEFAULT]
bind_ip = 192.168.2.202
workers = 2
mount_check = false
bind_port = 6001
log_facility = LOG_LOCAL0
devices = /srv/1/node
[pipeline:main]
pipeline =-server
[app:container-server]
use = egg:swift#container
[container-replicator]
[container-updater]
[container-auditor]
[container-sync]
1.3.7 /etc/swift/object-server.conf
1) vi /etc/swift/object-server.conf
[DEFAULT]
bind_ip = 192.168.2.202
workers = 2
mount_check = false
bind_port = 6000
log_facility = LOG_LOCAL0
devices = /srv/1/node
[pipeline:main]
pipeline = object-server
[app:object-server]
use = egg:swift#object
[object-replicator]
[object-updater]
[object-auditor]
1.4 创建ring
1)
cd /etc/swift
swift-ring-builder account.builder create 18 2 1
swift-ring-builder account.builder add z1-192.168.2.202:6002/sdb1 1
swift-ring-builder account.builder add z2-192.168.2.203:6002/sdb1 1
swift-ring-builder account.builder
swift-ring-builder account.builder rebalance
swift-ring-builder object.builder create 18 2 1
swift-ring-builder object.builder add z1-192.168.2.202:6000/sdb1 1
swift-ring-builder object.builder add z2-192.168.2.203:6000/sdb1 1
swift-ring-builder object.builder
swift-ring-builder object.builder rebalance
swift-ring-builder.builder create 18 2 1
swift-ring-builder.builder add z1-192.168.2.202:6001/sdb1 1
swift-ring-builder.builder add z2-192.168.2.203:6001/sdb1 1
swift-ring-builder.builder
swift-ring-builder.builder rebalance
2)
拷贝所有的 account.builder,account.ring.gz,container.builder,container.ring.gz,object.builder, object.ring.gz 到每一个节点下面的 /etc/swift 目录下
注意:
每条命令都要判断是否执行成功
swift-ring-builder account.builder create 18 2 1
18表示 hash环的partion 2**18个
(这里的2^18个为swift中一致性hash中涉及到的虚拟机节点的个数,而非环节点个数,环节点数固定为2^32。(MD5的hash算法的值范围));
2表示副本个数,每个object保存几份,当前由于控制节点2个,所以当前设置成2个,如果控制节点1个,就设置成一个,
如果控制节点3个,就设置3个,最多只要设置3个副本即可;1表示多久(单位小时)检测一个object的存储状态。
必须进入 /etc/swift 这个目录,创建的ring才是有效的。
1.5 创建swift用户
groupadd swift
useradd -g swift swift
chown -R swift:swift /etc/swift/
keystone user-create --name swift --pass swift
keystone user-role-add --user swift --tenant services --role admin
keystone service-create --name swift --type object-store --description "OpenStack Object Storage"
keystone endpoint-create \
--service-id $(keystone service-list | awk '/ object-store / {print $2}') \
--publicurl 'http://havip:8080/v1/AUTH_%(tenant_id)s' \
--internalurl 'http://havip:8080/v1/AUTH_%(tenant_id)s' \
--adminurl http://havip:8080 \
--region regionOne
1.6 创建挂载路径
mkdir /srv
dd if=/dev/zero of=/srv/swift-disk bs=1024 count=0 seek=1000000
mkfs.xfs -i size=1024 /srv/swift-disk
vi /etc/fstab
/srv/swift-disk /mnt/sdb1 xfs loop,noatime,nodiratime,nobarrier,logbufs=8 0 0
mkdir /mnt/sdb1
mount /mnt/sdb1
mkdir /mnt/sdb1/1
chown swift:swift /mnt/sdb1/*
ln -s /mnt/sdb1/1 /srv/1
mkdir -p /etc/swift/object-server /etc/swift/container-server /etc/swift/account-server /srv/1/node/sdb1 /var/run/swift /var/cache/swift
chown -R swift:swift /etc/swift /srv/1/ /var/run/swift /var/cache/swift
chown -R swift:swift /srv/1
1.6 启动swift
service memcached start
swift-init all start
1.9 测试命令
publicURL=http://192.168.2.205:8080/v1/AUTH_8add6951a8144391acb47d883f5ba1ab
(这些不带token)
1、查询
curl -i $publicURL
2、创建account
curl –I $publicURL -X POST
3、创建container
curl -i $publicURL/ jack -X PUT -H "Content-Length: 0"
4、上传文件
curl -k -i -X PUT -T "install.log" $publicURL/jack/install.log
5、获取账户占用空间
curl -i $publicURL -I
6、查询container占用空间
curl -i $publicURL/jack -I
由于环境各异,也可能自己写的有所遗漏,可能安装后出现问题,欢迎大家相互交流,一起学习。