使用Swauth認證多節點安裝Swift

來源:互聯網
上載者:User
轉載請寫明出處:http://blog.csdn.net/cywosp/article/details/7428769 1.  摘要說明

        本文所涉及到的所有操作都是在Ubuntu Server 11.10 64位系統上通過驗證。本文參考了Openstackswift的Instructions for a Multiple Server SwiftInstallation (Ubuntu)文檔,具體資訊如下:

Linux系統版本:Ubuntu Server 11.10 64-bit oneiricProxy Server IP:   192.168.112.129Storage Server One:192.168.112.130Storage Server Two:192.168.112.131Storage Server Three:192.168.112.132官方文檔:      www.openstack.org參考文檔:      http://swift.openstack.org/howto_installmultinode.htmlSwift版本:       1.4.8Swauth版本:      1.0.4

2.  為每一台機器安裝依賴包
sudo apt-get --option Dpkg::Options::=--force-confold --assume-yes updatesudo apt-get install pep8 pylint python-pip screen unzip wget psmisc git-core lsof openssh-server vim-nox locate python-virtualenv python-unittest2 iputils-ping wget curl tcpdump euca2ools python-setuptools python-dev python-lxml python-pastescript python-pastedeploy python-paste sqlite3 python-pysqlite2 python-sqlalchemy python-mysqldb python-webob python-greenlet python-routes libldap2-dev libsasl2-dev python-bcrypt curl gcc python-configobj python-coverage python-dev python-eventlet python-greenlet python-netifaces python-nose python-pastedeploy python-setuptools python-simplejson python-webob python-xattr sqlite3 xfsprogs 

3.  為每一台機器建立swift使用者

sudo useradd -mk /home/swift/ -s /bin/bash swift

sudo passwd swift    #為swift使用者添加密碼,在此我將其設為了swift

編輯/etc/sudoer檔案,在檔案末尾添加如下代碼

swift ALL=(ALL) NOPASSWD:ALL

4.  下載源碼(在swift使用者下操作)

1.  在Proxy機器中下載swauth和swift源碼

su swift#切換到swift使用者sudo mkdir /home/swift/openstack#建立一個目錄來存放cd /home/swift/openstackgit clone https://github.com/openstack/swift.git#下載swiftcd swiftgit checkout 1.4.8#使用1.4.8版本,在swift目錄下你可以#使用git tag命令查看有多少個版本git clone https://github.com/gholt/swauth.git#下載swauthcd swauthgit checkout 1.0.4

2.  在每一台Storage節點的機器中下載swift

su swift#切換到swift使用者sudo mkdir /home/swift/openstack#建立一個目錄來存放cd /home/swift/openstackgit clone https://github.com/openstack/swift.git#下載swiftcd swiftgit checkout 1.4.8#使用1.4.8版本,在swift目錄下你可以使用git tag命令查看有多少個版本

5.  安裝swauth和swift (在swift使用者下操作)

1.  在Proxy機器中安裝swauth和swift

cd  /home/swift/openstack/swauthsudo python setup.py install  --record  file.txtcd /home/swift/openstack/swift#在Proxy節點中安裝swift是為了使用swift的swift-proxy-serversudo python setup.py install  --record  file.txt註:file.txt檔案記錄了安裝資訊,要想刪除所安裝的軟體通過命令sudo cat file.txt | xargs  rm  -rf即可刪除,這一步可能會出現禁止刪除問題,因此你需要使用root使用者來操作。

2.  在每一台Storage節點的機器中安裝swift

cd  /home/swift/openstack/swiftsudo python setup.py  install  --record  file.txt
6.  Proxy節點的設定
1.sudo apt-get install memcached#安裝快取服務器修改/etc/ memcached.conf檔案,將-l 127.0.0.1改為-l 192.168.112.129(這裡我是根據我自己的情況設定的,具體原因見第一點中的圖)sudo service memcached restartsudo mkdir  /etc/swiftcd  /etc/swiftsudo chown -R swift:swift /etc/swiftcp  /home/swift/openstack/swift/etc/proxy-server.conf /etc/swift/cp  /home/swift/openstack/swift/etc/swift.conf /etc/swift/
2.修改/etc/swift/proxy-server.conf檔案,具體內容如下,原檔案中沒有的項需要自行增加[DEFAULT]bind_port = 8080user = swiftlog_facility = LOG_LOCAL0[pipeline:main]pipeline = catch_errors healthcheck cache ratelimit swauth proxy-server[app:proxy-server]use = egg:swift#proxyallow_account_management = trueaccount_autocreate = true[filter:swauth]use = egg:swauth#swauth# Highly recommended to change this.super_admin_key = swauthkeydefault_swift_cluster = local#http://192.168.112.129:8080/auth/v1.0 [filter:healthcheck]use = egg:swift#healthcheck[filter:cache]use = egg:swift#memcache
3.修改/etc/swift/swift.conf,紅色部分是隨意更改的,你可以根據自己的需要更改[swift-hash]swift_hash_path_suffix = cynric
4.產生相關ring以及builder檔案,使用如下命令產生,紅色部分是根據具體情況而更改的,具體原因見摘要說明裡的圖。每一台機器使用一個域(z1, z2, z3…依次遞增)sudo chown -R swift:swift /etc/swift/*cd  /etc/swiftswift-ring-builder object.builder create 18 3 1swift-ring-builder container.builder create 18 3 1swift-ring-builder account.builder create 18 3 1export HOST_IP=192.168.112.130swift-ring-builder object.builder add z1-${HOST_IP}:6010/sdb1 100swift-ring-builder container.builder add z1-${HOST_IP}:6011/sdb1 100swift-ring-builder account.builder add z1-${HOST_IP}:6012/sdb1 100export HOST_IP=192.168.112.131swift-ring-builder object.builder add z2-${HOST_IP}:6010/sdb1 100swift-ring-builder container.builder add z2-${HOST_IP}:6011/sdb1 100swift-ring-builder account.builder add z2-${HOST_IP}:6012/sdb1 100export HOST_IP=192.168.112.132swift-ring-builder object.builder add z3-${HOST_IP}:6010/sdb1 100swift-ring-builder container.builder add z3-${HOST_IP}:6011/sdb1 100swift-ring-builder account.builder add z3-${HOST_IP}:6012/sdb1 100swift-ring-builder object.builder rebalanceswift-ring-builder container.builder rebalanceswift-ring-builder account.builder rebalance
5.啟動proxy服務swift-init  proxy  start
7.  配置Storage節點

因為每個Storage節點的設定基本上是相似的,所以在這裡只拿其中一個節點做樣本(192.168.112.130),其他節點只需要重複一下幾步操作就可以了

1.建立/etc/swift目錄sudo mkdir /etc/swiftsudo chown -R swift:swift /etc/swift/*
2.將Proxy節點上/etc/swift/中的account.ring.gz  container.ring.gz  object.ring.gz  swift.conf拷貝到當前儲存節點(192.168.112.130)/etc/swift目錄中,可使用如下命令scp  swift@192.168.112.129:/etc/swift/*.ring.gz  /etc/swift/scp  swift@192.168.112.129:/etc/swift/swift.conf  /etc/swift/sudo chown -R swift:swift /etc/swift/*
3.更改/etc/rsyncd.conf檔案,如果該檔案不存在則需要自行建立,內容如下uid = swiftgid = swiftlog file = /var/log/rsyncd.logpid file = /var/run/rsyncd.pidaddress = 192.168.112.130#這裡也可以改為127.0.0.1[account]max connections = 2path = /srv/node/read only = falselock file = /var/lock/account.lock[conainer]max connections = 2path = /srv/node/read only = falselock file = /var/lock/container.lock[object]max connections = 2path = /srv/node/read only = falselock file = /var/lock/object.lock編輯/etc/default/rsync:將RSYNC_ENABLE設定為true更改好之後,重啟該服務sudo service rsync restart
4.儲存點的設定這裡有分兩種情況來設定儲存點1.假設你的系統裡有一個單獨分區,使用此分區來做儲存點,在這裡假設系統中有/dev/sdb1(註:這雷根據你自己系統的情況而定)這個分區未被使用,我們用它來做儲存點。sudo mkdir -p /srv/node/sdb1sudo mkfs.xfs -i size=1024 /dev/sdb1 #以xfs方式格式化分區sudo chmod a+w /etc/fstabsudo echo "/dev/sdb1 /srv/node/sdb1 xfs noatime,nodiratime,nobarrier,logbufs=8 0 0" >> /etc/fstab  #系統啟動時自動掛載,這裡的sdb1是一定不能改的,因為在做Proxy節點產生相應的ring檔案時使用了sdb1 (swift-ring-builder object.builder add z1-${HOST_IP}:6010/sdb1 100)的時候,加入需要更改則兩個地方都需要改sudo mount /srv/node/sdb1sudo chown -R swift:swift /srv/node/sdb1sudo chmod a+w -R /srv/node/sdb12.如果系統裡沒有單獨的分區來做儲存點,則需要建立一個臨時分區來做儲存點sudo mkdir -p /srv/node/sdb1sudo 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-disksudo chmod a+w /etc/fstabsudo echo “/srv/swift-disk /srv/node/sdb1 xfs loop,noatime,nodiratime,nobarrier,logbufs=8 0 0” >> /etc/fstab#系統啟動時自動掛載sudo mount /srv/node/sdb1sudo chown -R swift:swift /srv/node/sdb1sudo chmod a+w -R /srv/node/sdb1sudo chmod a+w /srv/swift-disk建立相關的目錄sudo mkdir /var/run/swiftsudo chown swift:swift /var/run/swiftsudo chmod a+w /var/run/swift在/etc/rc.local的exit 0之前加入下列三行mkdir /var/run/swiftchown swift:swift /var/run/swiftchmod a+w /var/run/swift
5.Swift檔案配置建立/etc/swift/account-server.conf檔案,並加入如下配置[DEFAULT]devices = /srv/nodemount_check = falsebind_port = 6012user = swiftbind_ip = 0.0.0.0workers = 2[pipeline:main]pipeline = account-server[app:account-server]use = egg:swift#account[account-replicator][account-auditor][account-reaper]建立/etc/swift/object-server.conf檔案[DEFAULT]devices = /srv/nodemount_check = falsebind_port = 6010user = swiftbind_ip = 0.0.0.0workers = 2[pipeline:main]pipeline = object-server[app:object-server]use = egg:swift#object[object-replicator][object-updater][object-auditor]建立/etc/swift/ container-server.conf檔案[DEFAULT]devices = /srv/nodemount_check = falsebind_port = 6011user = swiftbind_ip = 0.0.0.0workers = 2[pipeline:main]pipeline = container-server[app:container-server]use = egg:swift#container[container-replicator][container-updater][container-auditor][container-sync]
6.啟動swift服務sudo chown -R swift:swift /etc/swift/*swift-init all start#當啟動的時候可能會報WARNING: Unable to increase file descriptor limit.  Running as non-root?  這是正常情況
8.  測試swift(在Proxy主機上測試)

1.  初始化swauth

swauth-prep  -K swauthkey     #執行成功的話則不會有任何資訊顯示

#在這一步經常會出現Auth subsystem prep failed: 500 ServerError這種錯誤,發生錯誤的原因可能是你的/srv下的目錄的擁有者不是屬於swift使用者。

2.  添加使用者

swauth-add-user  -A http://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_84841e28-93a8-4e9c-a295-f9734f25da01

AuthToken: AUTH_tkfacf171def344d03bf01519e93327f3c

Account:AUTH_ 84841e28-93a8-4e9c-a295-f9734f25da01

Containers:0

Objects:0

Bytes:0

Accept-Ranges:bytes

X-Trans-Id:txa0c57ad0fd6d435b8287ca111ca0269a

注:紅色字型部分是根據具體情況而定的,並不是每個人系統返回都是一樣的,假如出現了錯誤你可以在/var/log/swift/目錄下查詢到相應的資訊

9.  上傳和下載檔案(在Proxy主機上測試)

1.  擷取X-Storage-Token和X-Storage-Url

curl  -v -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' http://127.0.0.1:8080/auth/v1.0       #執行完該條語句會返回相應的資訊,例如(返回資訊的一小部分):

HTTP/1.1200 OK

X-Storage-Url:http://127.0.0.1:8080/v1/AUTH_84841e28-93a8-4e9c-a295-f9734f25da01

X-Storage-Token:AUTH_tkfacf171def344d03bf01519e93327f3c

X-Auth-Token:AUTH_tkfacf171def344d03bf01519e93327f3c

2.  建立container和列出容器

curl -X PUT -D -  -H "X-Auth_Token:AUTH_tkfacf171def344d03bf01519e93327f3c"http://127.0.0.1:8080/v1/AUTH_84841e28-93a8-4e9c-a295-f9734f25da01/cynric     #建立cyrnic容器,紅色部分是上一步返回的資訊

swift  -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上後,也是以嵌套目錄的形式存在,下載後,會在目前的目錄建立一樣的嵌套目錄。

 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.