以前介紹了《OpenStack Swift All In One安裝部署流程與簡單使用》,那麼接下來就說一說Swift集羣部署吧。php
1. 簡介html
本文檔詳細描述了使用兩臺PC部署一個小型Swift集羣的過程,並給出一些簡單的使用實例。本文檔假定以下前提條件:node
閱讀本文檔前,能夠先閱讀文檔《Swift All In One安裝部署流程》,學習Swift單機部署的相關知識。python
2. 安裝部署linux
2.1 準備環境nginx
|
PC 1git |
PC 2github |
機器類型:sql |
PC物理機數據庫 |
PC物理機 |
操做系統: |
Ubuntu-12.04-desktop-64位 |
Ubuntu-12.04-desktop-64位 |
用戶類型: |
root |
root |
數據庫: |
sqlite3 |
sqlite3 |
IP地址: |
192.168.3.52(局域網) |
192.168.3.53(局域網) |
Proxy Server: |
是 |
是 |
Storage Server: |
是 |
是 |
Auth: |
TempAuth |
TempAuth |
Token緩存: |
memcached |
memcached |
2.2 版本說明
本文檔基於:
請確保安裝的Swift版本與本文檔中的版本相同。若有問題,請參考官網的更新文檔。
2.3 安裝軟件環境
首先,在PC1和PC2上安裝Swift所需的軟件環境(確保你的機器能夠訪問互聯網),例如,sqlite3做爲本地數據庫,memcached做爲Token緩存。Ubuntu-12.04已自帶rsync工具,所以不用另行安裝。
# apt-get install python-software-properties # add-apt-repository ppa:swift-core/release # apt-get update # apt-get install curl gcc git-core memcached python-coverage python-dev python-nose python-setuptools python-simplejson python-xattr sqlite3 xfsprogs python-eventlet python-greenlet python-pastedeploy python-netifaces python-pip # pip install mock |
在PC1和PC2上執行如下操做,安裝Swift服務:
1. 在主目錄(root用戶)下建立swift目錄。而後在該下建立bin目錄,用於存放咱們手動建立的Swift相關腳本文件。
# mkdir ~/swift # mkdir –p ~/swift/bin |
2. 進入~/swift目錄,而後從git上獲取Swift和python-swiftclient源代碼,下載到本地。固然也可使用之前下載的1.7.6版本的Swift代碼和1.2.0版本的python-swiftclient代碼,將代碼目錄放至~/swift目錄下便可。
# cd ~/swift # git clone https://github.com/openstack/swift.git # git clone https://github.com/openstack/python-swiftclient.git |
3. 而後使用上述代碼以開發的方式安裝Swift和python-swiftclient(假設Swift的代碼目錄爲~/swift/swift_1.7.6,python-swiftclient的代碼目錄爲~/swift/python-swiftclient_1.2.0)。最終,二者都會被安裝到python的dist-packages中。
# cd ~/swift/swift_1.7.6 # python setup.py develop # cd ~/swift/python-swiftclient_1.2.0 # python setup.py develop |
4. 安裝過程當中,會自動檢查其所需的依賴項,並自動進行下載安裝。文件~/swift/swift_1.7.6/tools/pip-requires中(內容以下所示)記錄了Swift所需的依賴項,setup.py就是根據該文件來檢查依賴項的。
eventlet>=0.9.15 greenlet>=0.3.1 netifaces>=0.6 pastedeploy>=1.3.3 simplejson>=2.0.9 xattr>=0.4 python-swiftclient |
5. 相似的,文件~/swift/python-swiftclient_1.2.0/tools/pip-requires中(內容以下所示)記錄了python-swiftclient所需的依賴項。
simplejson |
6. 修改~/.bashrc文件,在文件尾部添加以下內容:(該文件包含當前用戶Bash Shell的環境變量信息,用以標明Swift測試配置文件路徑和啓動程序路徑)
export SWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf export PATH=${PATH}:~/swift/bin |
7. 而後執行以下命令,以使修改生效。一旦生效,終生有效哦親!。
# . ~/.bashrc |
8. 建立/var/run/swift目錄,並修改其權限。該目錄是Swift運行時所需的,用於存放各個服務進程的pid文件等內容。
# mkdir -p /var/run/swift # chown root:root /var/run/swift |
9. /var/run/swift目錄在操做系統關閉後會消失,所以須要在操做系統再次啓動時進行建立。咱們能夠編輯/etc/rc.local文件,在exit 0 以前添加以下內容來實現該目錄的自動建立。
mkdir -p /var/run/swift chown root:root /var/run/swift |
Swift可以運行在任何支持擴展屬性的現代文件系統之上,Swift官方推薦用戶使用XFS文件系統。通過官方的驗證,認爲XFS文件系統能爲Swift的用例提供最佳的性能,而且經過了完整的穩定性測試。
對於任何一臺PC,咱們能夠選擇使用一個分區做爲存儲(Using a partition for storage),也可使用一個迴環設備做爲存儲(Using a loopback device for storage)。因爲實驗環境所限,本文檔使用迴環設備做爲存儲。若但願使用獨立分區做爲存儲,請參考官方文檔。咱們須要在每一臺PC上建立迴環設備,做爲每個Swift節點的數據存儲空間。在PC1和PC2上執行如下操做:
1. 選擇一個位置建立存儲文件夾。
# mkdir /srv |
2. 在存儲文件夾中建立XFS格式的迴環設備,即/srv/swift-disk文件。
# dd if=/dev/zero of=/srv/swift-disk bs=1024 count=0 seek=50000000 # mkfs.xfs -f -i size=1024 /srv/swift-disk |
3. 編輯/etc/fstab文件,在文件末尾添加以下內容:
/srv/swift-disk /srv/node/sdb1 xfs loop,noatime,nodiratime,nobarrier,logbufs=8 0 0 |
4. 建立迴環設備掛載點文件夾,並執行掛載。
# mkdir -p /srv/node/sdb1 # mount /srv/node/sdb1 |
5. 改變掛載點文件夾的權限。
# chown -R root:root /srv/node |
在PC1和PC2上建立Swift的配置文件目錄。
# mkdir -p /etc/swift # chown -R root:root /etc/swift/ |
在PC1中建立配置文件/etc/swift/swift.conf,編輯其內容(以下所示),而後複製到PC2中的/etc/swift目錄下。該文件記錄了Swift使用的哈希後綴,用於一致性哈希計算。集羣中的每一個節點都必須保存該文件,而且徹底相同。
[swift-hash] # random unique string that can never change (DO NOT LOSE) swift_hash_path_suffix = jtangfs |
rsync是類Unix系統下的數據鏡像備份工具。Swift對象副本的複製更新是基於推送模式的。對象的複製更新使用rsync將文件同步到對等節點,Account和Container的複製更新則經過HTTP或rsync來推送數據庫文件上丟失的記錄。在PC1和PC2上建立rsync的配置文件/etc/rsyncd.conf,添加以下內容:(下面以PC1爲例,其中的address是PC1上rsync服務端監聽的IP地址,等待客戶端推送複製更新,這裏一樣推薦設置爲內網地址)
uid = root gid = root log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid address = 192.168.3.52
[account] max connections = 2 path = /srv/node/ read only = false lock file = /var/lock/account.lock
[container] max connections = 2 path = /srv/node/ read only = false lock file = /var/lock/container.lock
[object] max connections = 2 path = /srv/node/ read only = false lock file = /var/lock/object.lock |
爲了使rsync可以開機啓動,須要在PC1和PC2上編輯配置文件/etc/default/rsync,將參數RSYNC_ENABLE設置爲true,而後啓動rsync服務。
# perl -pi -e 's/RSYNC_ENABLE=false/RSYNC_ENABLE=true/' /etc/default/rsync # service rsync restart |
在PC1和PC2上執行如下操做,以完成每一個節點上的account、container和object存儲服務的配置。下面以PC1上的操做爲例。
1. 配置account存儲服務,建立配置文件/etc/swift/account-server.conf,並添加如下內容:(其中,devices參數表示Parent directory of where devices are mounted,默認值爲/srv/node;log_facility表示日誌標籤,與獨立日誌的配置有關)
[DEFAULT] devices = /srv/node mount_check = false bind_ip = 192.168.3.52 bind_port = 6002 workers = 4 user = root log_facility = LOG_LOCAL4
[pipeline:main] pipeline = account-server
[app:account-server] use = egg:swift#account
[account-replicator]
[account-auditor]
[account-reaper] |
2. 配置container存儲服務,建立配置文件/etc/swift/container-server.conf,並添加如下內容:
[DEFAULT] devices = /srv/node mount_check = false bind_ip = 192.168.3.52 bind_port = 6001 workers = 4 user = root log_facility = LOG_LOCAL3
[pipeline:main] pipeline = container-server
[app:container-server] use = egg:swift#container
[container-replicator]
[container-updater]
[container-auditor]
[container-sync] |
3. 配置object存儲服務,建立配置文件/etc/swift/object-server.conf,並添加如下內容:
[DEFAULT] devices = /srv/node mount_check = false bind_ip = 192.168.3.52 bind_port = 6000 workers = 4 user = root log_facility = LOG_LOCAL2
[pipeline:main] pipeline = object-server
[app:object-server] use = egg:swift#object
[object-replicator]
[object-updater]
[object-auditor] |
Swift默認將日誌信息輸出到文件/var/log/syslog中。若是要按照我的需求設置rsyslog,生成特有的Swift日誌文件,則須要在PC1和PC2上執行如下操做,完成獨立日誌的配置。
1. 建立日誌配置文件/etc/rsyslog.d/10-swift.conf,編輯內容以下:(增長account、container、object的日誌配置信息)
# 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 $template HourlyProxyLog,"/var/log/swift/hourly/%$YEAR%%$MONTH%%$DAY%%$HOUR%" #local1.*;local1.!notice ?HourlyProxyLog
local2.*;local2.!notice /var/log/swift/object.log local2.notice /var/log/swift/ object.error local2.* ~
local3.*;local3.!notice /var/log/swift/container.log local3.notice /var/log/swift/ container.error local3.* ~
local4.*;local4.!notice /var/log/swift/account.log local4.notice /var/log/swift/ account.error local4.* ~ |
2. 編輯文件/etc/rsyslog.conf,更改參數$PrivDropToGroup爲adm。
$PrivDropToGroup adm |
3. 建立/var/log/swift目錄,用於存放獨立日誌。此外,上面的10-swift.conf 文件中設置了輸出Swift Proxy Server每小時的stats日誌信息,因而也要建立/var/log/swift/hourly目錄。
# mkdir -p /var/log/swift/hourly |
4. 更改Swift獨立日誌目錄的權限。
# chown -R syslog.adm /var/log/swift # chmod -R g+w /var/log/swift |
5. 重啓rsyslog服務
# service rsyslog restart |
Proxy Server使用memcached來緩存用戶的Token。咱們可根據具體需求修改memcached配置文件/etc/memcached.conf。例如,考慮到安全因素,只容許memcached在局域網內被訪問,則應將其監聽的IP地址修改成局域網IP地址(默認爲127.0.0.1,內外網通吃)。推薦配置爲內部的、非公網的IP地址。將PC1上的修改成192.168.3.52,PC2上的修改成192.168.3.53,並在完成後重啓memcached服務。下面以PC1上執行的命令爲例:
# perl -pi -e "s/-l 127.0.0.1/-l 192.168.3.52/" /etc/memcached.conf # service memcached restart |
因爲每一臺PC都運行Swift的全部服務,既做爲Proxy Server,又做爲Storage Server,上面在配置Storage Server時已經完成了Swift的配置,此處可省略。可是,若是Proxy Server和Storage Server是分離的,那麼就須要將上面的swift.conf文件複製到Proxy Server中的/etc/swift目錄下。
2.6.3 配置proxy-server
在PC1和PC2上建立proxy-server配置文件/etc/swift/proxy-server.conf,添加如下內容:
[DEFAULT] bind_port = 8080 user = root workers = 8 log_facility = LOG_LOCAL1
[pipeline:main] pipeline = healthcheck cache tempauth proxy-logging proxy-server
[app:proxy-server] use = egg:swift#proxy allow_account_management = true account_autocreate = true
[filter:tempauth] use = egg:swift#tempauth user_admin_admin = admin .admin .reseller_admin user_test_tester = testing .admin user_test2_tester2 = testing2 .admin user_test_tester3 = testing3 reseller_prefix = AUTH # account和token的命名前綴,注意此處不能夠加「_」。 # 例如X-Storage-Url爲http://192.168.3.52:8080/v1/AUTH_test # 例如X-Auth-Token爲AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1 token_life = 86400 # token的有效期,單位:秒。
[filter:healthcheck] use = egg:swift#healthcheck
[filter:cache] use = egg:swift#memcache memcache_servers = 192.168.3.52:11211,192.168.3.53:11211
[filter:proxy-logging] use = egg:swift#proxy_logging |
配置參數中:memcache_servers指定memcached地址,可配置爲集羣,以「,」分隔;workers爲工做線程數,推薦配置爲CPU核心數的2-4倍;「user_admin_admin = admin .admin .reseller_admin」中,user_爲前綴,第一個「admin」爲帳戶名,第二個「admin」爲用戶名,第三個「admin爲」密碼,「.admin」爲角色信息,「.reseller_admin」表示超級管理員角色(可操做任何帳戶)。
「user_admin_admin = admin .admin .reseller_admin」後面還能夠增長一項<storage-url>,顯示地指定Swift爲該用戶提供的存儲服務入口(PC1爲admin用戶提供的默認值是http://192.168.3.52:8080/v1/AUTH_admin)。admin用戶經過認證後,Swift會把Token和該<storage-url>返回給用戶,此後admin用戶可使用該<storage-url>訪問Swift來請求存儲服務。特別值得說明的是,若是在Proxy Server前面增長了負載均衡器(如nginx),那麼該<storage-url>應該指向負載均衡器,使得用戶在經過認證後,向負載均衡器發起存儲請求,再由負載均衡器將請求均衡地分發給Proxy Server集羣。此時的<storage-url>形如http://<LOAD_BALANCER_HOSTNAME>:<PORT>/v1/AUTH_admin。
Swift同時支持http和https協議,本文檔中咱們使用http協議,若想使用https協議,則須要進行ssl的配置,具體操做請查看參考連接中的內容。
2.6.4 配置獨立日誌(可選)
上文中已經作了說明,此處可用於設置Proxy Server的獨立日誌,須要在PC1和PC2上執行如下操做,完成其配置。
1. 編輯日誌配置文件/etc/rsyslog.d/10-swift.conf,增長proxy的日誌配置信息:
# 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 $template HourlyProxyLog,"/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/object.log local2.notice /var/log/swift/ object.error local2.* ~
local3.*;local3.!notice /var/log/swift/container.log local3.notice /var/log/swift/ container.error local3.* ~
local4.*;local4.!notice /var/log/swift/account.log local4.notice /var/log/swift/ account.error local4.* ~ |
2. 重啓rsyslog服務
# service rsyslog restart |
Ring共有三種,分別爲Account Ring、Container Ring、Object Ring。Ring須要在整個集羣中保持徹底相同,所以須要在某一臺PC上建立Ring文件,而後複製到其餘PC上。咱們將在PC1上進行Ring的建立,而後複製到PC2上。
首先,使用以下命令建立三個Ring。其中,18表示Ring的分區數爲218;2表示對象副本數爲2;1表示分區數據的遷移時間爲1小時(這個解釋有待證明)。
# cd /etc/swift # swift-ring-builder account.builder create 18 2 1 # swift-ring-builder container.builder create 18 2 1 # swift-ring-builder object.builder create 18 2 1 |
而後向三個Ring中添加存儲設備。其中z1和z2表示zone1和zone2;sdb1爲Swift使用的存儲空間,即上文掛在的迴環設備;100表明設備的權重。
# cd /etc/swift # swift-ring-builder account.builder add z1-192.168.3.52:6002/sdb1 100 # swift-ring-builder container.builder add z1-192.168.3.52:6001/sdb1 100 # swift-ring-builder object.builder add z1-192.168.3.52:6000/sdb1 100
# swift-ring-builder account.builder add z2-192.168.3.53:6002/sdb1 100 # swift-ring-builder container.builder add z2-192.168.3.53:6001/sdb1 100 # swift-ring-builder object.builder add z2-192.168.3.53:6000/sdb1 100 |
Ring文件建立完畢後,能夠經過如下命令來查看剛纔添加的信息,以驗證是否輸入正確。若發現錯誤,以Account Ring爲例,可使用swift-ring-builder account.builder的刪除方法刪除已添加的設備,而後從新添加。
# cd /etc/swift # swift-ring-builder account.builder # swift-ring-builder container.builder # swift-ring-builder object.builder |
完成設備的添加後,咱們還須要建立Ring的最後一步,即平衡環。這個過程須要消耗一些時間。成功以後,會在當前目錄生成account.ring.gz、container.ring.gz和object.ring.gz三個文件,這三個文件就是全部節點(包括Proxy Server和Storage Server)要用到的Ring文件。咱們須要將這三個文件拷貝到PC2中的/etc/swift目錄下。
# cd /etc/swift # swift-ring-builder account.builder rebalance # swift-ring-builder container.builder rebalance # swift-ring-builder object.builder rebalance |
因爲咱們統一採用root用戶部署,因此要確保全部節點上的/etc/swift目錄都屬於root用戶。
# chown -R root:root /etc/swift |
爲便於操做,咱們能夠在PC1和PC2上建立如下Swift腳本。
1. 建立~/swift/bin/remakerings腳本文件,添加如下內容,便可一鍵完成Ring的從新建立,固然具體內容須要根據實際環境進行修改。
#!/bin/bash
cd /etc/swift
rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
swift-ring-builder account.builder create 18 2 1 swift-ring-builder container.builder create 18 2 1 swift-ring-builder object.builder create 18 2 1
swift-ring-builder account.builder add z1-192.168.3.52:6002/sdb1 100 swift-ring-builder container.builder add z1-192.168.3.52:6001/sdb1 100 swift-ring-builder object.builder add z1-192.168.3.52:6000/sdb1 100
swift-ring-builder account.builder add z2-192.168.3.53:6002/sdb1 100 swift-ring-builder container.builder add z2-192.168.3.53:6001/sdb1 100 swift-ring-builder object.builder add z2-192.168.3.53:6000/sdb1 100
swift-ring-builder account.builder rebalance swift-ring-builder container.builder rebalance swift-ring-builder object.builder rebalance |
2. 建立~/swift/bin/resetswift腳本文件,添加如下內容,便可一鍵清空Swift的對象數據和日誌,完成重置。注意:若是使用的是獨立分區存儲,則須要另行處理,例如將/srv/swift-disk替換爲/dev/sdb1等;若是沒有使用rsyslog做爲獨立日誌,則須要去掉「find /var/log/swift... 」和「sudo service rsyslog restart」這兩行。
#!/bin/bash
swift-init all stop find /var/log/swift -type f -exec rm -f {} \; sudo umount /srv/node/sdb1 sudo mkfs.xfs -f -i size=1024 /srv/swift-disk sudo mount /srv/node/sdb1 sudo chown root:root /srv/node/sdb1 sudo rm -f /var/log/debug /var/log/messages /var/log/rsyncd.log /var/log/syslog sudo service rsyslog restart sudo service rsync restart sudo service memcached restart |
3. 建立~/swift/bin/startmain腳本文件,添加如下內容,便可一鍵啓動Swift的基本服務,包括proxy-server、account-server、container-server和object-server。
#!/bin/bash
swift-init main start |
4. 建立~/swift/bin/stopmain腳本文件,添加如下內容,便可一鍵關閉Swift的基本服務,包括proxy-server、account-server、container-server和object-server。
#!/bin/bash
swift-init main stop |
5. 建立~/swift/bin/startall腳本文件,添加如下內容,便可一鍵啓動Swift的全部服務,包括proxy-server、account-server、account-replicator 、account-auditor、container-server、container-replicator、container-updater、container-auditor、object-server、object-replicator、object-updater、object-auditor。
#!/bin/bash
swift-init proxy start swift-init account-server start swift-init account-replicator start swift-init account-auditor start swift-init container-server start swift-init container-replicator start swift-init container-updater start swift-init container-auditor start swift-init object-server start swift-init object-replicator start swift-init object-updater start swift-init object-auditor start |
6. 建立~/swift/bin/stopall腳本文件,添加如下內容,便可一鍵關閉Swift的全部服務,包括proxy-server、account-server、account-replicator 、account-auditor、container-server、container-replicator、container-updater、container-auditor、object-server、object-replicator、object-updater、object-auditor。
#!/bin/bash
swift-init proxy stop swift-init account-server stop swift-init account-replicator stop swift-init account-auditor stop swift-init container-server stop swift-init container-replicator stop swift-init container-updater stop swift-init container-auditor stop swift-init object-server stop swift-init object-replicator stop swift-init object-updater stop swift-init object-auditor stop |
7. 完成腳本建立後,須要更改腳本權限,使之可以執行。
# chmod +x ~/swift/bin/* |
因爲咱們是以開發的方式安裝Swift的,因此可以執行功能單元測試。若提示「Unable to read test config /etc/swift/test.conf – file not found」,可沒必要理會,或手動將配置文件~/swift/swift_1.7.6/test/sample.conf複製過去。
# cd ~/swift/swift_1.7.6 # ./.unittests |
咱們須要在PC1和PC2上啓動Proxy Server和Storage Server的服務。爲了便於操做,咱們直接使用上文中建立的腳本文件(在~/swift/bin目錄下)運行Swift。可使用~/swift/bin/startmain腳本文件啓動Swift的基本服務;或使用~/swift/bin/startall腳本文件鍵啓動Swift的全部服務。若提示「Unable to increase file descriptor limit. Running as non-root?」警告爲正常現象,沒必要理會。
# startmain 或 # startall |
一樣的,咱們可使用~/swift/bin/stopmain腳本文件關閉Swift的基本服務;使用~/swift/bin/stopall腳本文件鍵關閉Swift的全部服務。
# stopmain 或 # stopall |
完成安裝部署後,可使用swift --help命令查看Swift幫助信息。
# swift --help Usage: swift <command> [options] [args]
Commands: stat [container] [object] Displays information for the account, container, or object depending on the args given (if any). list [options] [container] Lists the containers for the account or the objects for a container. -p or --prefix is an option that will only list items beginning with that prefix. -d or --delimiter is option (for container listings only) that will roll up items with the given delimiter (see Cloud Files general documentation for what this means). upload [options] container file_or_directory [file_or_directory] [...] Uploads to the given container the files and directories specified by the remaining args. -c or --changed is an option that will only upload files that have changed since the last upload. -S <size> or --segment-size <size> and --leave-segments are options as well (see --help for more). post [options] [container] [object] Updates meta information for the account, container, or object depending on the args given. If the container is not found, it will be created automatically; but this is not true for accounts and objects. Containers also allow the -r (or --read-acl) and -w (or --write-acl) options. The -m or --meta option is allowed on all and used to define the user meta data items to set in the form Name:Value. This option can be repeated. Example: post -m Color:Blue -m Size:Large download --all OR download container [options] [object] [object] ... Downloads everything in the account (with --all), or everything in a container, or a list of objects depending on the args given. For a single object download, you may use the -o [--output] <filename> option to redirect the output to a specific file or if "-" then just redirect to stdout. delete [options] --all OR delete container [options] [object] [object] ... Deletes everything in the account (with --all), or everything in a container, or a list of objects depending on the args given. Segments of manifest objects will be deleted as well, unless you specify the --leave-segments option.
Example: swift -A https://auth.api.rackspacecloud.com/v1.0 -U user -K key stat
Options: --version show program's version number and exit -h, --help show this help message and exit -s, --snet Use SERVICENET internal network -v, --verbose Print more info -q, --quiet Suppress status output -A AUTH, --auth=AUTH URL for obtaining an auth token -V AUTH_VERSION, --auth-version=AUTH_VERSION Specify a version for authentication. Defaults to 1.0. -U USER, --user=USER User name for obtaining an auth token. -K KEY, --key=KEY Key for obtaining an auth token. --os-username=<auth-user-name> Openstack username. Defaults to env[OS_USERNAME]. --os-password=<auth-password> Openstack password. Defaults to env[OS_PASSWORD]. --os-tenant-id=<auth-tenant-id> OpenStack tenant ID. Defaults to env[OS_TENANT_ID] --os-tenant-name=<auth-tenant-name> Openstack tenant name. Defaults to env[OS_TENANT_NAME]. --os-auth-url=<auth-url> Openstack auth URL. Defaults to env[OS_AUTH_URL]. --os-auth-token=<auth-token> Openstack token. Defaults to env[OS_AUTH_TOKEN] --os-storage-url=<storage-url> Openstack storage URL. Defaults to env[OS_STORAGE_URL] --os-region-name=<region-name> Openstack region name. Defaults to env[OS_REGION_NAME] --os-service-type=<service-type> Openstack Service type. Defaults to env[OS_SERVICE_TYPE] --os-endpoint-type=<endpoint-type> Openstack Endpoint type. Defaults to env[OS_ENDPOINT_TYPE] --insecure Allow swiftclient to access insecure keystone server. The keystone's certificate will not be verified. |
啓動PC1和PC2上的Swift服務後,咱們交替地在PC1和PC2上執行操做,並隨機使用二者提供的storage-url,若是用戶驗證和存儲服務所有正確,則代表Swift集羣部署成功。
咱們先使用curl測試幾個簡單的命令。
1. 在PC1上訪問192.168.3.52,進行tester用戶驗證,獲取Token和storage-url。
# curl -k -v -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' http://192.168.3.52:8080/auth/v1.0 |
* About to connect() to 192.168.3.52 port 8080 (#0) * Trying 192.168.3.52... connected > GET /auth/v1.0 HTTP/1.1 > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 > Host: 192.168.3.52:8080 > Accept: */* > X-Storage-User: test:tester > X-Storage-Pass: testing > < HTTP/1.1 200 OK < X-Storage-Url: http://192.168.3.52:8080/v1/AUTH_test < X-Auth-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1 < Content-Type: text/html; charset=UTF-8 < X-Storage-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1 < Content-Length: 0 < Date: Wed, 20 Mar 2013 06:13:15 GMT < * Connection #0 to host 192.168.3.52 left intact * Closing connection #0 |
2. 在PC1上訪問192.168.3.52,查看test帳戶的狀態信息。
# curl -k -v -H 'X-Auth-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1' http://192.168.3.52:8080/v1/AUTH_test |
* About to connect() to 192.168.3.52 port 8080 (#0) * Trying 192.168.3.52... connected > GET /v1/AUTH_test HTTP/1.1 > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 > Host: 192.168.3.52:8080 > Accept: */* > X-Auth-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1 > < HTTP/1.1 204 No Content < Content-Length: 0 < Accept-Ranges: bytes < X-Timestamp: 1363760036.52552 < X-Account-Bytes-Used: 0 < X-Account-Container-Count: 0 < Content-Type: text/html; charset=UTF-8 < X-Account-Object-Count: 0 < Date: Wed, 20 Mar 2013 06:13:56 GMT < * Connection #0 to host 192.168.3.52 left intact * Closing connection #0 |
3. 在PC1上訪問192.168.3.53,查看test帳戶的狀態信息。
# curl -k -v -H 'X-Auth-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1' http://192.168.3.53:8080/v1/AUTH_test |
* About to connect() to 192.168.3.53 port 8080 (#0) * Trying 192.168.3.53... connected > GET /v1/AUTH_test HTTP/1.1 > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 > Host: 192.168.3.53:8080 > Accept: */* > X-Auth-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1 > < HTTP/1.1 204 No Content < Content-Length: 0 < Accept-Ranges: bytes < X-Timestamp: 1363760036.52552 < X-Account-Bytes-Used: 0 < X-Account-Container-Count: 0 < Content-Type: text/html; charset=UTF-8 < X-Account-Object-Count: 0 < Date: Wed, 20 Mar 2013 06:15:19 GMT < * Connection #0 to host 192.168.3.53 left intact * Closing connection #0 |
4. 在PC2上訪問192.168.3.52,查看test帳戶的狀態信息。
# curl -k -v -H 'X-Auth-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1' http://192.168.3.52:8080/v1/AUTH_test |
* About to connect() to 192.168.3.52 port 8080 (#0) * Trying 192.168.3.52... connected > GET /v1/AUTH_test HTTP/1.1 > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 > Host: 192.168.3.52:8080 > Accept: */* > X-Auth-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1 > < HTTP/1.1 204 No Content < Content-Length: 0 < Accept-Ranges: bytes < X-Timestamp: 1363760036.52552 < X-Account-Bytes-Used: 0 < X-Account-Container-Count: 0 < Content-Type: text/html; charset=UTF-8 < X-Account-Object-Count: 0 < Date: Wed, 20 Mar 2013 06:17:01 GMT < * Connection #0 to host 192.168.3.52 left intact * Closing connection #0 |
上述測試一切正常,代表curl測試經過。
3.2 用Swift客戶端測試
接着,咱們使用Swift客戶端進行測試。
1. 在PC1上訪問192.168.3.53,查看test帳戶的狀態信息。
# swift -A http://192.168.3.53:8080/auth/v1.0 -U test:tester -K testing stat |
Account: AUTH_test Containers: 0 Objects: 0 Bytes: 0 Accept-Ranges: bytes X-Timestamp: 1363760036.52552 Content-Type: text/plain; charset=utf-8 |
2. 在PC1上訪問192.168.3.52,在test帳戶下建立名爲myfiles的container。
# swift -A http://192.168.3.52:8080/auth/v1.0 -U test:tester -K testing post myfiles |
|
3. 在PC1上訪問192.168.3.53,顯示test帳戶下的container列表。
# swift -A http://192.168.3.53:8080/auth/v1.0 -U test:tester -K testing list |
myfiles |
4. 在PC2上訪問192.168.3.52,顯示test帳戶下的container列表。
# swift -A http://192.168.3.52:8080/auth/v1.0 -U test:tester -K testing list |
myfiles |
5. 在PC2上訪問192.168.3.53,在剛纔建立的container下上傳文件。上傳完成後,Swift服務端會以完整路徑做爲文件名。
# swift -A http://192.168.3.53:8080/auth/v1.0 -U test:tester -K testing upload myfiles ~/file |
root/file |
6. 在PC1上訪問192.168.3.52,顯示剛纔建立的container下的文件列表。
# swift -A http://192.168.3.52:8080/auth/v1.0 -U test:tester -K testing list myfiles |
root/file |
7. 在PC1上訪問192.168.3.52,下載剛纔上傳的文件。給定的文件名必須是其完整路徑,例如上傳的文件爲~/file,服務端記錄的文件名爲root/file,因而下載時也要給文件名root/file,而不能是file。最終,文件會被下載到~/root目錄下,成爲~/root/file。可使用額外的命令參數來決定下載位置,詳情參考swift --help。
# swift -A http://192.168.3.52:8080/auth/v1.0 -U test:tester -K testing download myfiles root/file |
root/file [headers 0.041s, total 0.065s, 0.000s MB/s] |
上述測試一切正常,代表Swift客戶端測試經過。
4. 參考連接
http://docs.openstack.org/developer/swift/howto_installmultinode.html
http://docs.openstack.org/developer/swift/development_saio.html
http://docs.openstack.org/developer/swift/deployment_guide.html
http://liangbo.me/index.php/2012/03/29/openstack-hands-on-lab-2-swift-installation-with-keystone/
http://blog.csdn.net/zzcase/article/details/6578520
http://www.kissthink.com/archive/4175.html
http://www.cnblogs.com/Bob-FD/archive/2012/07/25/2608413.html
http://blog.csdn.net/zoushidexing/article/details/7860226