Ubuntu 12.04 OpenStack Swift單節點部署手冊

OpenStack Swift單節點部署手冊

部署環境

  • VMware Workstation 9 (推薦版本,低版本亦可,只要能安裝Ubuntu 12.04)
  • Ubuntu 12.04 Server 32 bit
  • OpenStack Swift v1.8 (Grizzly)

說明

  • 此文檔爲基於官方修改的只針對Ubuntu 12.04,完整的參閱官方文檔
  • 本部署爲開發環境,Swift配置爲以root權限運行,生產環境推薦新建用戶swift
  • 選擇Ubuntu 12.04因其默認內核爲3.5,減小部署時的麻煩
  • Ubuntu Server安裝時不選其它組件,最小化安裝
  • 如下安裝命令所有以root身份運行

Ubuntu 更改成國內源(非必需):

sudo vi /etc/apt/sources.list
%s/cn.archive.ubuntu.com/mirrors.ustc.edu.cn/g #修改前面一部分
%s/security.ubuntu.com/mirrors.ustc.edu.cn/g #修改security的源地址
sudo apt-get update
sudo apt-get upgrade

安裝依賴

apt-get update
apt-get install curl gcc memcached rsync sqlite3 xfsprogs git python-setuptools
apt-get install python-coverage python-dev python-nose python-simplejson python-xattr python-eventlet 
python-greenlet python-pastedeploy python-netifaces python-pip python-dnspython python-mock

使用迴環設備做爲存儲,若須要使用一個分區做爲存儲,參見官方文檔

mkdir /srv
truncate -s 1GB /srv/swift-disk
mkfs.xfs /srv/swift-disk
修改/etc/fstab 添加以下行

/srv/swift-disk /mnt/sdb1 xfs loop,noatime,nodiratime,nobarrier,logbufs=8 0 0html

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 
mkdir -p /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
編輯文件/etc/rc.local,在exit 0 以前添加以下4行:
mkdir -p /var/cache/swift /var/cache/swift2 /var/cache/swift3 /var/cache/swift4
chown <your-user-name>:<your-group-name> /var/cache/swift*
mkdir -p /var/run/swift
chown <your-user-name>:<your-group-name> /var/run/swift

設置Rsync

建立文件/etc/rsyncd.conf,:
uid = root
gid = root
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
address = 127.0.0.1

[account6012]
max connections = 25
path = /srv/1/node/
read only = false
lock file = /var/lock/account6012.lock

[account6022]
max connections = 25
path = /srv/2/node/
read only = false
lock file = /var/lock/account6022.lock

[account6032]
max connections = 25
path = /srv/3/node/
read only = false
lock file = /var/lock/account6032.lock

[account6042]
max connections = 25
path = /srv/4/node/
read only = false
lock file = /var/lock/account6042.lock

[container6011]
max connections = 25
path = /srv/1/node/
read only = false
lock file = /var/lock/container6011.lock

[container6021]
max connections = 25
path = /srv/2/node/
read only = false
lock file = /var/lock/container6021.lock

[container6031]
max connections = 25
path = /srv/3/node/
read only = false
lock file = /var/lock/container6031.lock

[container6041]
max connections = 25
path = /srv/4/node/
read only = false
lock file = /var/lock/container6041.lock

[object6010]
max connections = 25
path = /srv/1/node/
read only = false
lock file = /var/lock/object6010.lock

[object6020]
max connections = 25
path = /srv/2/node/
read only = false
lock file = /var/lock/object6020.lock

[object6030]
max connections = 25
path = /srv/3/node/
read only = false
lock file = /var/lock/object6030.lock

[object6040]
max connections = 25
path = /srv/4/node/
read only = false
lock file = /var/lock/object6040.lock
編輯文件/etc/default/rsync,設置參數RSYNC_ENABLE爲true:
RSYNC_ENABLE=true
啓動rsync服務
service rsync restart
確認rsync啓動成功
rsync rsync://pub@localhost/

設置獨立日誌(非必需,略,見官方文檔)

獲取代碼並設置測試環境

從git上獲取swift代碼,下載到本地
git clone https://github.com/openstack/swift.git
安裝Swift的開發版本
cd ~/swift
git checkout -t origin/stable/grizzly # checkout穩定分支1.8
python setup.py develop
cd ..
從git上獲取python-swiftclient代碼,下載到本地
git clone https://github.com/openstack/python-swiftclient.git
安裝python-swiftclient的開發版本
cd ~/python-swiftclient
python setup.py develop
cd ..

配置各結點

建立文件/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
建立文件/etc/swift/swift.conf,
[swift-hash]
# random unique strings that can never change (DO NOT LOSE)
swift_hash_path_prefix = rui
swift_hash_path_suffix = jie
Create /etc/swift/account-server/1.conf:
[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]
Create /etc/swift/account-server/2.conf:
[DEFAULT]
devices = /srv/2/node
mount_check = false
disable_fallocate = true
bind_port = 6022
user = root
log_facility = LOG_LOCAL3
recon_cache_path = /var/cache/swift2
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]
Create /etc/swift/account-server/3.conf:
[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]
Create /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]
Create /etc/swift/container-server/1.conf:
[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]
Create /etc/swift/container-server/2.conf:
[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]
Create /etc/swift/container-server/3.conf:
[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]
Create /etc/swift/container-server/4.conf:
[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]
Create /etc/swift/object-server/1.conf:
[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]
Create /etc/swift/object-server/2.conf:
[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]
Create /etc/swift/object-server/3.conf:
[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]
Create /etc/swift/object-server/4.conf:
[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]

建立Swift運行腳本

mkdir ~/binnode

建立腳本~/bin/resetswift

因未建立rsyslog做爲獨立日誌,已移除find /var/log/swift...這一行
若是使用的是單獨分區存儲須要將/srv/swift-disk替換爲/dev/sdb1python

#!/bin/bash
swift-init all stop
sudo umount /mnt/sdb1
sudo mkfs.xfs -f /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/remakerings
#!/bin/bash
cd /etc/swift
rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
swift-ring-builder object.builder create 10 3 1
swift-ring-builder object.builder add r1z1-127.0.0.1:6010/sdb1 1
swift-ring-builder object.builder add r1z2-127.0.0.1:6020/sdb2 1
swift-ring-builder object.builder add r1z3-127.0.0.1:6030/sdb3 1
swift-ring-builder object.builder add r1z4-127.0.0.1:6040/sdb4 1
swift-ring-builder object.builder rebalance
swift-ring-builder container.builder create 10 3 1
swift-ring-builder container.builder add r1z1-127.0.0.1:6011/sdb1 1
swift-ring-builder container.builder add r1z2-127.0.0.1:6021/sdb2 1
swift-ring-builder container.builder add r1z3-127.0.0.1:6031/sdb3 1
swift-ring-builder container.builder add r1z4-127.0.0.1:6041/sdb4 1
swift-ring-builder container.builder rebalance
swift-ring-builder account.builder create 10 3 1
swift-ring-builder account.builder add r1z1-127.0.0.1:6012/sdb1 1
swift-ring-builder account.builder add r1z2-127.0.0.1:6022/sdb2 1
swift-ring-builder account.builder add r1z3-127.0.0.1:6032/sdb3 1
swift-ring-builder account.builder add r1z4-127.0.0.1:6042/sdb4 1
swift-ring-builder account.builder rebalance
建立~/bin/startmain
#!/bin/bash
swift-init main start
建立~/bin/startrest
#!/bin/bash
swift-init rest start

chmod +x ~/bin/*git

編輯~/.bashrc,在最後添加以下兩行
export SWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf
export PATH=${PATH}:~/bin

<!-- lang: shell -->
. ~/.bashrc
remakerings
cp ~/swift/test/sample.conf /etc/swift/test.conf
開啓Swift
startmain
檢查Swift工做
swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing stat
正確狀況下,應該輸出如下信息
Account: AUTH_test
Containers: 0
Objects: 0
Bytes: 0
Accept-Ranges: bytes
重啓main服務
swift-init main restart
swift-init
swift-init命令有許多參數,具體查看幫助

ps

Markdown寫博客挺友好github

參考:
http://www.cnblogs.com/fczjuever/archive/2013/05/11/3073151.html http://docs.openstack.org/developer/swift/development_saio.htmlsql

相關文章
相關標籤/搜索