在一台机器上部署swift存储和swauth认证(swift单独部署)
问题导读
1.如何创建swift用户?
2.存储节点设置需要注意什么问题?
3.swift_hash_path_suffix作用是什么?
static/image/hrline/4.gif
1.摘要说明本文所涉及到的所有操作都是在Ubuntu Server 11.10 64位系统上通过验证。本文参考了Openstackswift的SAIO(Swift All In One)文档,具体信息如下:Linux系统版本:Ubuntu Server11.10 64-bit oneiric机器系统IP: 192.168.112.129官方文档: www.openstack.org参考文档: http://swift.openstack.org/development_saio.htmlSwift版本: 1.4.8Swauth版本:1.0.42.安装依赖包sudoapt-get --option Dpkg::Options::=--force-confold --assume-yes updatesudoapt-get install pep8 pylint python-pip screen unzip wget psmisc git-core lsofopenssh-server vim-nox locate python-virtualenv python-unittest2 iputils-pingwget curl tcpdump euca2ools python-setuptools python-dev python-lxmlpython-pastescript python-pastedeploy python-paste sqlite3 python-pysqlite2python-sqlalchemy python-mysqldb python-webob python-greenlet python-routeslibldap2-dev libsasl2-dev python-bcrypt curl gcc python-configobjpython-coverage python-dev python-eventlet python-greenlet python-netifacespython-nose python-pastedeploy python-setuptools python-simplejson python-webobpython-xattr sqlite3 xfsprogs 3.创建swift用户
sudo useradd -mk /home/swift/ -s /bin/bash swift
sudo passwd swift #为swift用户添加密码,在此我将其设为了swift
编辑/etc/sudoer文件,在文件末尾添加如下代码
swiftALL=(ALL) NOPASSWD:ALL4.下载swift和swauth源码 (在swift用户下操作)
su swift #切换到swift用户
sudo mkdir /home/swift/openstack #创建一个目录来存放
cd /home/swift/openstack
gitclone https://github.com/openstack/swift.git #下载swift
cdswift
git checkout 1.4.8 #使用1.4.8版本,在swift目录下你可以使用git tag命令查看有多少个版本
git clone https://github.com/gholt/swauth.git #下载swauth
cd swauth
git checkout 1.0.4
5.安装swift和swauth(在swift用户下操作)
cd /home/swift/openstack/swift
sudo python setup.py install --record file.txt
#参数--record file.txt的作用是将所有文件被安装到的路径记录到#file.txt中,为了以后想卸载该软件的时候用,要想卸载该软件时,到#file.txt所在目录输入如下命令即可:sudo cat file.txt | xargs rm –rf
cd /home/swift/openstack/swauth
sudo python setup.py install --record file.txt 6.安装相关软件
sudo apt-get install memcached7.存储点的设置(在swift用户下操作)在这里有两种方式来设置存储点1.你的系统里有一个单独分区,使用此分区来做存储点,在这里假设系统中有/dev/sdb1(注:这里根据你自己系统的情况而定)这个分区未被使用,我们用它来做存储点。
sudo mkfs.xfs -i size=1024 /dev/sdb1 #以xfs方式格式化分区
sudo chmod a+w /etc/fstab
sudo echo “/dev/sdb1 /mnt/sdb1 xfs noatime,nodiratime nobarrier,logbufs=8 0 0”>> /etc/fstab #系统启动时自动挂载
sudo mkdir /mnt/sdb1 #在/mnt下创建sdb1挂载目录
sudo mount /mnt/sdb1 #挂载
sudo mkdir /mnt/sdb1/1 /mnt/sdb1/2 /mnt/sdb1/3 /mnt/sdb1/4
sudo chown swift:swift /mnt/sdb1/*
sudo mkdir /srv
for x in {1..4}; do sudo ln -s /mnt/sdb1/$x /srv/$x; done #创建连接
sudo mkdir -p /etc/swift/object-server /etc/swift/container-server/etc/swift/account-server /srv/1/node/sdb1 /srv/2/node/sdb2 /srv/3/node/sdb3/srv/4/node/sdb4 /var/run/swift #创建相关目录
sudo chown -R swift:swift /etc/swift /srv// /var/run/swift
在/etc/rc.local的exit 0之前加入下列三行
mkdir /var/run/swift
chown swift:swift /var/run/swift
chmod a+w /var/run/swift2.如果系统中没有单独未使用的分区则可以创建一个回环设备来做存储点(在此我使用的就是此方法)
sudo mkdir /srv
sudo dd if=/dev/zero of=/srv/swift-disk bs=1024 count=0 seek=1000000 #这个命令是在/srv/下创建一个名为swift-disk的存
#储区,你可以改变seek的大小来改变swift-disk的大小
sudo mkfs.xfs -i size=1024 /srv/swift-disk
sudo chmod a+w /etc/fstab
sudo echo “/srv/swift-disk /mnt/sdb1 xfs loop,noatime,nodiratime,nobarrier,logbufs=80 0” >> /etc/fstab #系统启动
#时自动挂载
sudo mkdir /mnt/sdb1 #在/mnt下创建sdb1挂载目录
sudo mount /mnt/sdb1 #挂载
sudo mkdir /mnt/sdb1/1 /mnt/sdb1/2 /mnt/sdb1/3 /mnt/sdb1/4
sudo chown swift:swift /mnt/sdb1/*
for x in {1..4}; do sudo ln -s /mnt/sdb1/$x /srv/$x; done #创建连接
sudo mkdir -p /etc/swift/object-server /etc/swift/container-server/etc/swift/account-server /srv/1/node/sdb1 /srv/2/node/sdb2 /srv/3/node/sdb3/srv/4/node/sdb4 /var/run/swift #创建相关目录
sudo chown -R swift:swift /etc/swift /srv// /var/run/swift
在/etc/rc.local的exit 0之前加入下列三行
mkdir /var/run/swift
chown swift:swift /var/run/swift
chmod a+w /var/run/swift
8.设置rsync
sudo touch /etc/rsyncd.conf #在/etc/下创建rsyncd.conf
sudo chmod a+w /etc/rsyncd.conf
将以下配置信息写入/etc/rsyncd.conf中
uid =swift
gid =swift
logfile = /var/log/rsyncd.log
pidfile = /var/run/rsyncd.pid
address= 127.0.0.1
maxconnections = 25
path =/srv/1/node/
readonly = false
lockfile = /var/lock/account6012.lock
maxconnections = 25
path =/srv/2/node/
readonly = false
lockfile = /var/lock/account6022.lock
maxconnections = 25
path =/srv/3/node/
readonly = false
lockfile = /var/lock/account6032.lock
maxconnections = 25
path =/srv/4/node/
readonly = false
lockfile = /var/lock/account6042.lock
maxconnections = 25
path =/srv/1/node/
readonly = false
lockfile = /var/lock/container6011.lock
maxconnections = 25
path =/srv/2/node/
readonly = false
lockfile = /var/lock/container6021.lock
maxconnections = 25
path =/srv/3/node/
readonly = false
lockfile = /var/lock/container6031.lock
maxconnections = 25
path =/srv/4/node/
readonly = false
lockfile = /var/lock/container6041.lock
maxconnections = 25
path =/srv/1/node/
readonly = false
lockfile = /var/lock/object6010.lock
maxconnections = 25
path =/srv/2/node/
readonly = false
lockfile = /var/lock/object6020.lock
maxconnections = 25
path =/srv/3/node/
readonly = false
lockfile = /var/lock/object6030.lock
maxconnections = 25
path =/srv/4/node/
readonly = false
lockfile = /var/lock/object6040.lock
编辑/etc/default/rsync:
将RSYNC_ENABLE设置为true
重启服务:
sudo servicersync restart
9.设置日志文件(可选)
sudo touch /etc/rsyslog.d/10-swift.conf
sudo chmod a+w /etc/rsyslog.d/10-swift.conf
在该文件中添加如下配置信息
#Uncomment the following to have a log containing all logs together
#local1,local2,local3,local4,local5.* /var/log/swift/all.log
#Uncomment the following to have hourly proxy logs for stats processing
#$templateHourlyProxyLog,"/var/log/swift/hourly/%$YEAR%%$MONTH%%$DAY%%$HOUR%"
#local1.*;local1.!notice?HourlyProxyLog
local1.*;local1.!notice/var/log/swift/proxy.log
local1.notice /var/log/swift/proxy.error
local1.* ~
local2.*;local2.!notice/var/log/swift/storage1.log
local2.notice /var/log/swift/storage1.error
local2.* ~
local3.*;local3.!notice/var/log/swift/storage2.log
local3.notice /var/log/swift/storage2.error
local3.* ~
local4.*;local4.!notice/var/log/swift/storage3.log
local4.notice /var/log/swift/storage3.error
local4.* ~
local5.*;local5.!notice/var/log/swift/storage4.log
local5.notice /var/log/swift/storage4.error
local5.*
修改/etc/rsyslog.conf:
将$PrivDropToGroupsyslog改为$PrivDropToGroup adm
执行如下命令
sudo mkdir -p /var/log/swift/hourly
sudo chown -R syslog.adm /var/log/swift
sudo service rsyslog restart10. 配置各个节点(以下文件不存在的话需要自己创建)sudo chmod a+w -R /etc/swift/*
1./etc/swift/proxy-server.conf
bind_port= 8080
user =swift
log_facility= LOG_LOCAL1
pipeline= healthcheck cache swauth proxy-server
use =egg:swift#proxy
allow_account_management= true
account_autocreate= true
use =egg:swauth#swauth
#Highly recommended to change this.
super_admin_key= swauthkey
default_swift_cluster= local#http://127.0.0.1:8080/auth/v1.0
use =egg:swift#healthcheck
use =egg:swift#memcache
2./etc/swift/swift.conf
#random unique string that can never change (DO NOT LOSE)
swift_hash_path_suffix= cynric #cynric是可以随意更改的字符串
3./etc/swift/account-server/1.conf
devices= /srv/1/node
mount_check= false
bind_port= 6012
user =swift
log_facility= LOG_LOCAL2
pipeline= account-server
use =egg:swift#account
vm_test_mode= yes
4./etc/swift/account-server/2.conf
devices= /srv/2/node
mount_check= false
bind_port= 6022
user =swift
log_facility= LOG_LOCAL3
pipeline= account-server
use =egg:swift#account
vm_test_mode= yes
5./etc/swift/account-server/3.conf
devices= /srv/3/node
mount_check= false
bind_port= 6032
user =swift
log_facility= LOG_LOCAL4
pipeline= account-server
use =egg:swift#account
vm_test_mode= yes
6./etc/swift/account-server/4.conf
devices= /srv/4/node
mount_check= false
bind_port= 6042
user =swift
log_facility= LOG_LOCAL5
pipeline= account-server
use =egg:swift#account
vm_test_mode= yes
7./etc/swift/container-server/1.conf
devices= /srv/1/node
mount_check= false
bind_port= 6011
user =swift
log_facility= LOG_LOCAL2
pipeline= container-server
use =egg:swift#container
vm_test_mode= yes
8./etc/swift/container-server/2.conf
devices= /srv/2/node
mount_check= false
bind_port= 6021
user =swift
log_facility= LOG_LOCAL3
pipeline= container-server
use =egg:swift#container
vm_test_mode= yes
9./etc/swift/container-server/3.conf
devices= /srv/3/node
mount_check= false
bind_port= 6031
user =swift
log_facility= LOG_LOCAL4
pipeline= container-server
use =egg:swift#container
vm_test_mode= yes
10./etc/swift/container-server/4.conf
devices= /srv/4/node
mount_check= false
bind_port= 6041
user =swift
log_facility= LOG_LOCAL5
pipeline= container-server
use =egg:swift#container
vm_test_mode= yes
11./etc/swift/object-server/1.conf
devices= /srv/1/node
mount_check= false
bind_port= 6010
user =swift
log_facility= LOG_LOCAL2
pipeline= object-server
use =egg:swift#object
vm_test_mode= yes
12./etc/swift/object-server/2.conf
devices= /srv/2/node
mount_check= false
bind_port= 6020
user =swift
log_facility= LOG_LOCAL3
pipeline= object-server
use =egg:swift#object
vm_test_mode= yes
13./etc/swift/object-server/3.conf
devices= /srv/3/node
mount_check= false
bind_port= 6030
user =swift
log_facility= LOG_LOCAL4
pipeline= object-server
use =egg:swift#object
vm_test_mode= yes
14./etc/swift/object-server/4.conf
devices= /srv/4/node
mount_check= false
bind_port= 6040
user =swift
log_facility= LOG_LOCAL5
pipeline= object-server
use =egg:swift#object
vm_test_mode= yes
11. 创建swift运行脚本
sudo mkdir /home/swift/bin
sudo chown swift:swift -R /home/swift/
在/etc/profile文件末尾添加如下代码
export PATH=$PATH:/home/swift/bin1.创建/home/swift/bin/remakerings
#!/bin/bash
cd/etc/swift
rm -f*.builder *.ring.gz backups/*.builder backups/*.ring.gz
swift-ring-builder object.builder create 18 3 1
swift-ring-builder container.builder create 18 3 1
swift-ring-builder account.builder create 18 3 1
swift-ring-builder object.builder add z1-127.0.0.1:6010/sdb1 1
swift-ring-builder object.builder add z2-127.0.0.1:6020/sdb2 1
swift-ring-builder object.builder add z3-127.0.0.1:6030/sdb3 1
swift-ring-builder object.builder add z4-127.0.0.1:6040/sdb4 1
swift-ring-builder container.builder add z1-127.0.0.1:6011/sdb1 1
swift-ring-builder container.builder add z2-127.0.0.1:6021/sdb2 1
swift-ring-builder container.builder add z3-127.0.0.1:6031/sdb3 1
swift-ring-builder container.builder add z4-127.0.0.1:6041/sdb4 1
swift-ring-builder account.builder add z1-127.0.0.1:6012/sdb1 1
swift-ring-builder account.builder add z2-127.0.0.1:6022/sdb2 1
swift-ring-builder account.builder add z3-127.0.0.1:6032/sdb3 1
swift-ring-builder account.builder add z4-127.0.0.1:6042/sdb4 1
swift-ring-builder object.builder rebalance
swift-ring-builder container.builder rebalance
swift-ring-builder account.builder rebalance
2.创建/home/swift/bin/sfstart
#!/bin/bash
swift-init all start
sudo chown swift:swift -R /var/log/swift/
sudo chmod a+w /var/run/swift/*
3.创建/home/swift/bin/sfstop
#!/bin/bash
Swift-init all stop
4.创建/home/swift/bin/resetswift
#!/bin/bash
swift-init all stop
find /var/log/swift -type f -exec rm -f {} \;
sudo umount /mnt/sdb1
sudo mkfs.xfs -f -i size=1024 /srv/swift-disk
sudo chmod a+w /srv/swift-disk
sudo mount /mnt/sdb1
sudo rm -rf /srv/1 /srv/2 /srv/3 /srv/4
sudo mkdir /mnt/sdb1/1 /mnt/sdb1/2 /mnt/sdb1/3 /mnt/sdb1/4
sudo chown swift:swift /mnt/sdb1/*
for x in {1..4}; do sudo ln -s /mnt/sdb1/$x/srv/$x; done
sudo mkdir -p /srv/1/node/sdb1 /srv/2/node/sdb2 /srv/3/node/sdb3/srv/4/node/sdb4
sudo chown swift:swift -R /srv/*
sudo rm -f /var/log/debug /var/log/messages /var/log/rsyncd.log/var/log/syslog
sudo chown -R swift:swift /mnt/sdb1/*
sudo service rsyslog restart
sudo service memcached restart
在/home/swift/bin/resetswift中,如果你使用的是单独分区来做存储点的,你需要把sudo mkfs.xfs -f -i size=1024 /srv/swift-disk和sudo chmod a+w /srv/swift-disk中的/srv/swift-disk改为该分区的设备名,例如本文第七步第一小点所说的那样,在这里我这里应该改为/dev/sdb1,具体情况根据你的系统而定
5.使/home/swift/bin下的文件具有可执行权限
sudochmod a+x /home/swift/bin/*
12. 生成ring文件source/etc/profile#下次启动系统是这条命令就不用执行了remakerings #执行该命令在/etc/swift中生成相应的文件
13. 启动swift服务source/etc/profile#下次启动系统是这条命令就不用执行了sfstart #执行这个需要一段时间#当启动的时候可能会报WARNING: Unable to increase filedescriptor limit.Running as non-root?这是正常情况
14. 测试swift服务1.初始化swauthswauth-prep-K swauthkey #执行成功的话则不会有任何信息显示#在这一步经常会出现Auth subsystem prep failed: 500 ServerError这种错误,发生错误的原因可能是你的/srv下的目录和/mnt/sdb1下的目录的拥有者不是属于swift用户。2.添加用户swauth-add-user-Ahttp://127.0.0.1:8080/auth/ -K swauthkey -a test tester testing #在tenant test中添加tester用户并设置密码为testing
3.检测swift运行状态swift-A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat-v #运行成功则会返回类似如下的信息
StorageURL:http://127.0.0.1:8080/v1/AUTH_3f7fb037-57b6-4771-831a-8fd811bcc3c7AuthToken: AUTH_tkf5b6840d9ce64d7298a800505a2ed857Account:AUTH_3f7fb037-57b6-4771-831a-8fd811bcc3c7Containers:0Objects:0Bytes:0Accept-Ranges:bytesX-Trans-Id:txdb39ed113c1c49299ebb364a4246a3a9 注:红色字体部分是根据具体情况而定的,并不是每个人系统返回都是一样的,假如出现了错误你可以在/var/log/swift/目录下查询到相应的信息15. 上传和下载文件1.获取X-Storage-Token和X-Storage-Urlcurl-v -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing'http://127.0.0.1:8080/auth/v1.0 #执行完该条语句会返回相应的信息,例如(返回信息的一小部分):HTTP/1.1200 OKX-Storage-Url:http://127.0.0.1:8080/v1/AUTH_3f7fb037-57b6-4771-831a-8fd811bcc3c7X-Storage-Token:AUTH_tkf5b6840d9ce64d7298a800505a2ed857X-Auth-Token:AUTH_tkf5b6840d9ce64d7298a800505a2ed857swift-A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list #查看test用户的container列表3.上传和列出文件swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing upload cynric/etc/swift/proxy-server.conf #将/etc/swift/proxy-server.conf文件上传到cynric容器中
swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list cynric #列出cynric容器中的文件4.下载文件swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing download cynric #将cynric容器下的所有文件下载到本地注意:如果上传文件的时候,有嵌套目录,则上传到swift上后,也是以嵌套目录的形式存在,下载后,会在当前目录创建一样的嵌套目录。
页:
[1]