标签:openstack 对象存储ring memcached swift python
在顺利的安装部署了KeyStone之后,原以为swift的安装调试也会如KeyStone一般,但过程却充满了坎坷,在结合源代码中的一些函数之后,终于成功的完成了swift的安装,并实验了上传下载文件等功能,下面整理了swift的安装过程,并对遇到的问题进行了总结,希望对遇到同样问题的人有些启示或帮助。安装过程依然参考的是OpenStack的官方安装手册,但补充了一些细节。在安装之前,先简单的介绍一下Swift是什么、主要功能是什么。OpenStack的对象存储(Swift)是一个多租户的、高可扩展的对象存储系统,通过RESTful HTTP API管理着大量的非结构化数据,在部署对象存储之前必须至少安装了身份服务(KeyStone)。Swift包含的组件包括:代理服务依赖于认证和授权机制,如果使用身份服务完成认证和授权的话,则在配置管理swift之前,首先要在keystone中创建swift的认证信息和endpoint。对象存储在控制节点上不适用SQL数据库。由于之前已经成功部署了KeyStone,所以这里就不在赘述KeyStone的安装过程,直接进入Swift的安装。本次安装是在单节点的虚拟机进行的,也就是控制节点和存储节点部署在相同的主机中,操作系统为CentOS7.1。首先在KeyStone中创建Swift的用户、服务及endpoint,具体命令及结果如下:
[openstack@localhost ~]$ keystone user-create --name swift --pass 123456 +----------+----------------------------------+ | Property | Value | +----------+----------------------------------+ | email | | | enabled | True | | id | ed4f45ac3e8a4ac683d54b642e61ac04 | | name | swift | | username | swift | +----------+----------------------------------+ keystone user-role-add --user swift --role admin --tenant service [openstack@localhost ~]$ keystone service-create --name swift --type object-store +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | | | enabled | True | | id | 094cc0da43e348f8b792f77ef99f8e7e | | name | swift | | type | object-store | +-------------+----------------------------------+ [openstack@localhost ~]$ keystone endpoint-create --region regionOne --service swift --publicurl ‘http://localhost:8080/v1/AUTH_%(tenant_id)s‘ --internalurl ‘http://localhost:8080/v1/AUTH_%(tenant_id)s‘ --adminurl ‘http://localhost:8080/v1/AUTH_%(tenant_id)s‘ +-------------+-----------------------------------------------------------------+ | Property | Value | +-------------+-----------------------------------------------------------------+ | adminurl | http://locoalhost:8080/v1/ | | id | c0da7d196e204e038766740e405dbbce | | internalurl | http://locoalhost:8080/v1/AUTH_2835009c452b4d408f95ff5a920fc877 | | publicurl | http://locoalhost:8080/v1/AUTH_2835009c452b4d408f95ff5a920fc877 | | region | regionOne | | service_id | 094cc0da43e348f8b792f77ef99f8e7e | +-------------+-----------------------------------------------------------------+然后安装proxy-server,swift客户端、memcached等:yum install openstack-swift-proxy python-swiftclient python-keystone-auth-token python-keystonemiddleware memcached。上面命令中的python-keystone-auth-token是无法安装的,当使用yum安装时将会报如下的异常信息:没有可用软件包 python-keystone-auth-token。经过在OpenStack的官网确认,该问题属于文档中的错误,直接忽略该问题或者执行yum install openstack-swift-proxy python-swiftclient python-keystonemiddleware memcached。安装执行完毕后,执行下面的命令下载proxy-server.conf文件:
curl -o /etc/swift/proxy-server.conf https://raw.githubusercontent.com/openstack/swift/stable/juno/etc/proxyserver.conf-sample下载完成后需要对文件中的配置参数进行修改,修改的具体内容如下:
[DEFAULT] ... bind_port = 8080 user = swift swift_dir = /etc/swift
[pipeline:main] pipeline = authtoken cache healthcheck keystoneauth proxy-logging proxy-server
[app:proxy-server] ... allow_account_management = true account_autocreate = true
[filter:keystoneauth] use = egg:swift#keystoneauth ... operator_roles = admin,_member_
[filter:authtoken] paste.filter_factory = keystonemiddleware.auth_token:filter_factory ... auth_uri = http://localhost:5000/v2.0 identity_uri = http://localhost:35357 admin_tenant_name = service admin_user = swift admin_password = SWIFT_PASS #指定为使用keystone创建swift用户时设置的密码,比如123456 delay_auth_decision = true
[filter:cache] ... memcache_servers = 127.0.0.1:11211这样就完成了proxy-server的安装和部署,可以使用systemctl启动该服务了,但目前先不启动该服务,直到部署配置存储服务后。在安装存储服务之前,先为存储服务指定存储目录,这需要将磁盘分区挂载到存储目录。根据官方的安装手册,挂载的磁盘必须具备分区表,也就是该磁盘已经分区完毕。经过测试,该磁盘具备几个分区不重要,但必须执行了分区,可以使用fdisk命令进行磁盘分区操作。虽然Swift支持各种文件系统,但根据测试XFS文件系统具有最好的性能和稳定性,所以对磁盘分区后,比如/dev/sdb1,需要使用命令mkfs.xfs对/dev/sdb1进行格式化:mkfs.xfs /dev/sdb1。格式化完成后,创建挂载目录:mkdir -p /srv/node/,然后编辑/etc/fstab,添加下面语句:
/dev/sdb1 /srv/node/ xfs noatime,nodiratime,nobarrier,logbufs=8 0 2最后挂载设备的存储目录:mount /srv/node,并修改该目录的所有者为运行swift的用户:chown -R swift:swift /srv/。挂载目录是swift一个潜在的容易出问题的地方,有可能是权限问题,也有可能和后面介绍的配置文件有关,具体的问题后面再详细介绍。挂载设备后,还需要修改/etc/rsyncd.conf文件,具体内容如下:
uid = swift gid = swift log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid address = MANAGEMENT_INTERFACE_IP_ADDRESS [account] max connections = 2 path = /srv/ read only = false lock file = /var/lock/account.lock [container] max connections = 2 path = /srv/ read only = false lock file = /var/lock/container.lock [object] max connections = 2 path = /srv/ read only = false lock file = /var/lock/object.lock做完准备工作后,执行下面的命令进行存储服务的安装,包括account-server、container-server和object-server:yum install openstack-swift-account openstack-swift-container openstack-swift-object。安装完成后,执行下面的命令下载account-server.conf、container-server.conf和object-server.conf文件:
curl -o /etc/swift/account-server.conf https://raw.githubusercontent.com/openstack/swift/stable/juno/etc/account-server.conf-sample curl -o /etc/swift/container-server.conf https://raw.githubusercontent.com/openstack/swift/stable/juno/etc/container-server.conf-sample curl -o /etc/swift/object-server.conf https://raw.githubusercontent.com/openstack/swift/stable/juno/etc/object-server.conf-sample三个配置文件所要修改的内容很相似,因此仅对account-server.conf进行说明,其它两个文件不同的地方将进行标记。
[DEFAULT] ... bind_ip = 127.0.0.1 bind_port = 6002 #不同的服务使用不同的端口 user = swift swift_dir = /etc/swift devices = /srv/ #设备挂载目录的上级目录
[pipeline:main] pipeline = healthcheck recon account-server#account-server在其它配置文件中应该改为container-server、object-server
[filter:recon] ... recon_cache_path = /var/cache/swiftcontainer-server.conf和object-server.conf只需要修改上面注释的地方即可,其它地方完全一致。修改完所有配置文件后,将/var/cache/swift的拥有者改为运行swift的用户,比如swift用户:chown -R swift:swift /var/cache/swift。在执行完所有上述步骤后,接下来就是要生成ring文件,命令的具体含义不会做深入解释,可以在命令直接输入swift-ring-builder查看详细说明。首先进入到/etc/swift目录,该目录在上述几个配置文件中进行设置,然后分别为account、container和object生成ring文件,由于所有的存储服务都部署在单节点上,所以副本的数量设置为1,具体命令为:
swift-ring-builder account.builder create 8 1 1 swift-ring-builder container.builder create 8 1 1 swift-ring-builder object.builder create 8 1 1其中第一个参数指定了要生成的partition的数量,比如2^8=256,第二个参数执行了副本的数量,此处为1,第三个参数的含义为至少移动分区一次间隔的小时数。创建了ring文件后,需要将存储节点或者目录增加到ring中:
swift-ring-builder account.builder add r1z1-127.0.0.1:6002/node 100 swift-ring-builder container.builder add r1z1-127.0.0.1:6001/node 100 swift-ring-builder object.builder add r1z1-127.0.0.1:6000/node 100其中的端口号一定要匹配相应配置文件中设置的端口号,而斜线/后面的内容要匹配挂载点的最后一级目录,比如将/dev/sdb1挂载到/srv/node上,则/后面的内容为node,而配置文件中的devices的值则为/srv/,如果设置错位或者不匹配挂载目录的话,会出现下面的错误:
object-replicator: node is not mounted proxy-server: ERROR Insufficient Storage 127.0.0.1:6002/node还可以在python命令行下输入下面的语句验证设置是否挂载正常、配置是否正确,如果一切正确,返回True,否则返回False:
from swift.common.constraints import check_mount check_mount(‘/srv‘,‘node‘) #第一个参数为配置文件中devices的值,第二个参数为向ring增加设备时/后面的值然后运行下面的命令对ring进行rebalance:
swift-ring-builder account.builder rebalance swift-ring-builder container.builder rebalance swift-ring-builder object.builder rebalance注意上述生成ring文件,增加存储节点到ring的步骤都是在控制节店中执行的。下载swift.conf文件并对其进行修改:
curl -o /etc/swift/swift.conf https://raw.githubusercontent.com/openstack/swift/stable/juno/etc/swift.conf-sample
[swift-hash] ... swift_hash_path_suffix = HASH_PATH_PREFIX swift_hash_path_prefix = HASH_PATH_SUFFIX
[storage-policy:0] ... name = Policy-0 default = yes如果是多节点部署swift的话,还需要将上述步骤生成的ring文件、swift.conf文件复制到所有节点中,并修改/etc/swift的拥有者为swift用户:chown -R swift:swift /etc/swift。
[openstack@localhost ~]$ cat swift-stop.sh #! /bin/bash systemctl stop openstack-swift-account.service openstack-swift-account-auditor.service openstack-swift-account-reaper.service openstack-swift-account-replicator.service systemctl stop openstack-swift-container.service openstack-swift-container-auditor.service openstack-swift-container-replicator.service openstack-swift-container-updater.service systemctl stop openstack-swift-object.service openstack-swift-object-auditor.service openstack-swift-object-replicator.service openstack-swift-object-updater.service所有服务启动完毕后,就可以检验一下向swift上传下载文件的功能了:
[openstack@localhost ~]$ source demo-openrc.sh [openstack@localhost ~]$ swift stat Account: AUTH_1928446a6c364ace8a40043b5318bd9f Containers: 0 Objects: 0 Bytes: 0 X-Put-Timestamp: 1434681204.28622 Connection: keep-alive X-Timestamp: 1434681204.28622 X-Trans-Id: tx60e7648bf53f4365a2c84-0055837f72 Content-Type: text/plain; charset=utf-8
[openstack@localhost ~]$ swift upload demo swift-stop.sh --object-name stop stop [openstack@localhost ~]$ swift list demo [openstack@localhost ~]$ swift list demo stop至此就完成了swift的单节点部署工作,并且从测试结果来看,一切动作正常。成功部署swift并不意味者对swift的所有功能、流程都已经熟悉了,相反还有很多需要学习的,比如swift客户端命令的详细使用方法,上传下载文件的具体流程,ring文件的具体含义,如何调整partition的数量等,还需要进一步的学习。
标签:openstack 对象存储ring memcached swift python
原文地址:http://blog.csdn.net/skywalker_only/article/details/46544649