本文對在單機部署swift 當中每一個細節作具體的介紹,並對配置作對應的解釋html
PC物理機 Ubuntu-12.04-desktop-64位node
Swift 版本號:1.13.1python
Swift-client 1.2.0linux
注意:本文所有操做都是在root權限下進行的。git
獲取swift源碼github
git clone https://github.com/openstack/swift.gitsql
獲取python版swift-client源碼json
git clone https://github.com/openstack/python-swiftclient.gitubuntu
利用pythoncharm 或者 裝有pydev插件的eclipse打開下載的swift源碼,在swift-master下 requirements.txt中列出了需要安裝的依賴包。並列出了其版本 swift
dnspython>=1.9.4
eventlet>=0.9.15
greenlet>=0.3.1
netifaces>=0.5
pastedeploy>=1.3.3
simplejson>=2.0.9
xattr>=0.4
安裝相關依賴包(swift 和swift-client),另 ubuntu12.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
mkdir ~/bin
cd ~/swift
python setup.py develop
此過程會檢查以前安裝的依賴包的正確性 並會將swift-master/bin 下的一些swift啓動文件的命令增長到/usr/local/bin下。咱們在使用swift命令時就說經過/usr/local/bin下的命令而後再映射到詳細的swift-master/bin 下的詳細文件裏的。
# cd ~/python-swiftclient
export SWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf
export PATH=${PATH}:~/bin
# . ~/.bashrc
該文件夾是Swift執行時所需的。用於存放各個服務進程的pid文件等內容。
# mkdir -p /var/run/swift
# chown root:root /var/run/swift
mkdir -p /var/run/swift
chown root:root /var/run/swif
# mkdir /srv
# dd if=/dev/zero of=/srv/swift-disk bs=1024 count=0 seek=20000000
# mkfs.xfs -f -i size=1024 /srv/swift-disk
如上命令 第一條 if=/dev/zero 表示空輸入。of=/srv/swift-disk 表示輸出到指定文件;bs=1024 表示輸入輸出的塊大小(Byte)。count=0表示拷貝0個塊,塊大小由bs指定;seek=20000000從輸出文件開頭跳過20000000個塊後再開始複製。
也就是建立一個20G的文件。爲建立迴環設備作準備。
第二條命令 xfs表示建立的是XFS格式的迴環設備。-i size=1024。當數據小於1024KB時。寫入inode中,當數據大於1024KB時,寫入block中,默認值爲256KB;還可以考慮設置-l size=128m,可顯著提高XFS文件系統刪除文件、複製文件等操做的速度。但需要大內存的支持,默認值的是10m。第二條命令的結果是在上述文件的基礎上建立了XFS迴環設備。
/srv/swift-disk /mnt/sdb1 xfs loop,noatime,nodiratime,nobarrier,logbufs=8 0 0
# mkdir /mnt/sdb1
# mount /mnt/sdb1
# mkdir /mnt/sdb1/1 /mnt/sdb1/2 /mnt/sdb1/3 /mnt/sdb1/4
# chown root:root /mnt/sdb1/*
# for x in {1..4}; do ln -s /mnt/sdb1/$x /srv/$x; done
# 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
# chown -R root:root /etc/swift /srv/[1-4]/ /var/run/swift
# mkdir -p /var/cache/swift /var/cache/swift2 /var/cache/swift3 /var/cache/swift4
# chown root:root /var/cache/swift*
# mkdir -p /var/run/swift
# chown root:root /var/run/swift
1 建立文件 /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
#$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/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.* ~
$PrivDropToGroup adm
# mkdir -p /var/log/swift/hourly
# chown -R syslog.adm /var/log/swift
# chmod -R g+w /var/log/swif
5. 從新啓動rsyslog服務。
# service rsyslog restart
這些配置信息的實例可在swift-master/doc/saio(swift all in one) 中詳細找到。
關於配置文件裏每一個選項的意義可以到官方部署指導上詳細查看
1 建立文件/etc/swift/proxy-server.conf ,此文件爲代理結點的配置歇息,內容例如如下
[DEFAULT]
bind_port = 8080
user = root
log_facility = LOG_LOCAL1
eventlet_debug = true
[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
[filter:healthcheck]
use = egg:swift#healthcheck
[filter:cache]
use = egg:swift#memcache
[filter:proxy-logging]
use = egg:swift#proxy_logging
[swift-hash]
# random unique string that can never change (DO NOT LOSE)
swift_hash_path_suffix = jtangfs
[DEFAULT]
devices = /srv/1/node
mount_check = false
disable_fallocate = true
bind_port = 6012
user = root
log_facility = LOG_LOCAL2
recon_cache_path = /var/cache/swift
eventlet_debug = true
[pipeline:main]
pipeline = recon account-server
[app:account-server]
use = egg:swift#account
[filter:recon]
use = egg:swift#recon
[account-replicator]
vm_test_mode = yes
[account-auditor]
[account-reaper]
[DEFAULT]
devices = /srv/3/node
mount_check = false
disable_fallocate = true
bind_port = 6032
user = root
log_facility = LOG_LOCAL4
recon_cache_path = /var/cache/swift3
eventlet_debug = true
[pipeline:main]
pipeline = recon account-server
[app:account-server]
use = egg:swift#account
[filter:recon]
use = egg:swift#recon
[account-replicator]
vm_test_mode = yes
[account-auditor]
[account-reaper]
6. 建立文件/etc/swift/account-server/4.conf。文件內容例如如下:
[DEFAULT]
devices = /srv/4/node
mount_check = false
disable_fallocate = true
bind_port = 6042
user = root
log_facility = LOG_LOCAL5
recon_cache_path = /var/cache/swift4
eventlet_debug = true
[pipeline:main]
pipeline = recon account-server
[app:account-server]
use = egg:swift#account
[filter:recon]
use = egg:swift#recon
[account-replicator]
vm_test_mode = yes
[account-auditor]
[account-reaper]
[DEFAULT]
devices = /srv/1/node
mount_check = false
disable_fallocate = true
bind_port = 6011
user = root
log_facility = LOG_LOCAL2
recon_cache_path = /var/cache/swift
eventlet_debug = true
[pipeline:main]
pipeline = recon container-server
[app:container-server]
use = egg:swift#container
[filter:recon]
use = egg:swift#recon
[container-replicator]
vm_test_mode = yes
[container-updater]
[container-auditor]
[container-sync]
[DEFAULT]
devices = /srv/2/node
mount_check = false
disable_fallocate = true
bind_port = 6021
user = root
log_facility = LOG_LOCAL3
recon_cache_path = /var/cache/swift2
eventlet_debug = true
[pipeline:main]
pipeline = recon container-server
[app:container-server]
use = egg:swift#container
[filter:recon]
use = egg:swift#recon
[container-replicator]
vm_test_mode = yes
[container-updater]
[container-auditor]
[container-sync]
[DEFAULT]
devices = /srv/3/node
mount_check = false
disable_fallocate = true
bind_port = 6031
user = root
log_facility = LOG_LOCAL4
recon_cache_path = /var/cache/swift3
eventlet_debug = true
[pipeline:main]
pipeline = recon container-server
[app:container-server]
use = egg:swift#container
[filter:recon]
use = egg:swift#recon
[container-replicator]
vm_test_mode = yes
[container-updater]
[container-auditor]
[container-sync]
[DEFAULT]
devices = /srv/4/node
mount_check = false
disable_fallocate = true
bind_port = 6041
user = root
log_facility = LOG_LOCAL5
recon_cache_path = /var/cache/swift4
eventlet_debug = true
[pipeline:main]
pipeline = recon container-server
[app:container-server]
use = egg:swift#container
[filter:recon]
use = egg:swift#recon
[container-replicator]
vm_test_mode = yes
[container-updater]
[container-auditor]
[container-sync]
[DEFAULT]
devices = /srv/1/node
mount_check = false
disable_fallocate = true
bind_port = 6010
user = root
log_facility = LOG_LOCAL2
recon_cache_path = /var/cache/swift
eventlet_debug = true
[pipeline:main]
pipeline = recon object-server
[app:object-server]
use = egg:swift#object
[filter:recon]
use = egg:swift#recon
[object-replicator]
vm_test_mode = yes
[object-updater]
[object-auditor]
[DEFAULT]
devices = /srv/2/node
mount_check = false
disable_fallocate = true
bind_port = 6020
user = root
log_facility = LOG_LOCAL3
recon_cache_path = /var/cache/swift2
eventlet_debug = true
[pipeline:main]
pipeline = recon object-server
[app:object-server]
use = egg:swift#object
[filter:recon]
use = egg:swift#recon
[object-replicator]
vm_test_mode = yes
[object-updater]
[object-auditor]
[DEFAULT]
devices = /srv/3/node
mount_check = false
disable_fallocate = true
bind_port = 6030
user = root
log_facility = LOG_LOCAL4
recon_cache_path = /var/cache/swift3
eventlet_debug = true
[pipeline:main]
pipeline = recon object-server
[app:object-server]
use = egg:swift#object
[filter:recon]
use = egg:swift#recon
[object-replicator]
vm_test_mode = yes
[object-updater]
[object-auditor]
[DEFAULT]
devices = /srv/4/node
mount_check = false
disable_fallocate = true
bind_port = 6040
user = root
log_facility = LOG_LOCAL5
recon_cache_path = /var/cache/swift4
eventlet_debug = true
[pipeline:main]
pipeline = recon object-server
[app:object-server]
use = egg:swift#object
[filter:recon]
use = egg:swift#recon
[object-replicator]
vm_test_mode = yes
[object-updater]
[object-auditor]
#!/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 mount /mnt/sdb1
sudo mkdir /mnt/sdb1/1 /mnt/sdb1/2 /mnt/sdb1/3 /mnt/sdb1/4
sudo chown root:root /mnt/sdb1/*
mkdir -p /srv/1/node/sdb1 /srv/2/node/sdb2 /srv/3/node/sdb3 /srv/4/node/sdb4
sudo rm -f /var/log/debug /var/log/messages /var/log/rsyncd.log /var/log/syslog
find /var/cache/swift* -type f -name *.recon -exec rm -f {} \;
sudo service rsyslog restart
sudo service memcached restart
#!/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 object.builder add z1-127.0.0.1:6010/sdb1 100 #z1 表示 zone1 127.0.0.1:6010 爲設備ip地址和port號,sdb1爲設備的存儲空間,100表明權重 這些都會調用swift-master/bin/swift-ring-builder 中的main方#法而後再代用swift-master/swift/cli/ringbuilder下的詳細方法。
ring代碼分析將在下一篇博客中詳細介紹
swift-ring-builder object.builder add z2-127.0.0.1:6020/sdb2 100
swift-ring-builder object.builder add z3-127.0.0.1:6030/sdb3 100
swift-ring-builder object.builder add z4-127.0.0.1:6040/sdb4 100
swift-ring-builder object.builder rebalance
swift-ring-builder container.builder create 18 3 1
swift-ring-builder container.builder add z1-127.0.0.1:6011/sdb1 100
swift-ring-builder container.builder add z2-127.0.0.1:6021/sdb2 100
swift-ring-builder container.builder add z3-127.0.0.1:6031/sdb3 100
swift-ring-builder container.builder add z4-127.0.0.1:6041/sdb4 100
swift-ring-builder container.builder rebalance
swift-ring-builder account.builder create 18 3 1
swift-ring-builder account.builder add z1-127.0.0.1:6012/sdb1 100
swift-ring-builder account.builder add z2-127.0.0.1:6022/sdb2 100
swift-ring-builder account.builder add z3-127.0.0.1:6032/sdb3 100
swift-ring-builder account.builder add z4-127.0.0.1:6042/sdb4 100
swift-ring-builder account.builder rebalance
#!/bin/bash
swift-init main start
#!/bin/bash
swift-init rest start
至此swift 單節點部署已經完畢,如下可以經過swift-client測試swift
root權限
輸入 swift --help 會羅列出詳細的命令介紹
# curl -v -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' http://127.0.0.1:8080/auth/v1.0
響應結果爲
home/kinglion/books/MySQL2ndEdition.pdf
其它 curl命令 你們可以本身試着應用,固然你們也可以基於swift-client 作一些http請要求的命令,對swift作使用作測試