本文对在单机部署swift 其中每一个细节做详细的介绍,并对配置做相应的解释
PC物理机 Ubuntu-12.04-desktop-64位
Swift 版本:1.13.1
Swift-client 1.2.0
注意:本文所有操作都是在root权限下进行的。
获取swift源代码
git clone https://github.com/openstack/swift.git
获取python版swift-client源代码
git clone https://github.com/openstack/python-swiftclient.git
利用pythoncharm 或者 装有pydev插件的eclipse打开下载的swift源代码,在swift-master下 requirements.txt中列出了需要安装的依赖包,并列出了其版本号
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
# 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地址和端口号,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做使用做测试
openstack swift 源码分析之swift单机部署,布布扣,bubuko.com
openstack swift 源码分析之swift单机部署
原文地址:http://blog.csdn.net/xianghonglee/article/details/24962723