SwiftAll-In-One 安装指南
author:钱立宽
email:pczebra1446@gmail.com
date:2018-3-20
Swift All-In-One(SAIO)单机部署机器配置:
戴尔PowerEdge-T110-II服务器一台;
Intel Xeon四核处理器3.1G Hz 一个
网卡 一块
内存 500G
操作系统:Ubuntu 14.04 LTS desktop
本机IP地址:10.200.25.223(固定IP)
PLEASE Keep These Cautions InMind :
一定要仔细阅读每一个在接下来会出现的配置文件,一定要注意IP地址和端口号配置的对不对
本文档基于openstack swift官方文档 https://docs.openstack.org/swift/latest/
CSND博客 SAIO中文版安装教程 http://blog.csdn.net/hubinqiang/article/details/57359565
博客园 OpenStack Swift集群部署流程与简单使用 https://www.cnblogs.com/fczjuever/p/3224022.html
安装测试成功。
1) 安装依赖
1. sudoapt-get update
2. sudoapt-get install curl gcc memcached rsync sqlite3 xfsprogs \
git-core libffi-devpython-setuptools \
liberasurecode-devlibssl-dev
3. sudoapt-get install python-coverage python-dev python-nose \
python-xattr python-eventlet \
python-greenletpython-pastedeploy \
python-netifaces python-pip python-dnspython\ python-mock
2) 使用回环设备存储
1》 使用回环设备作为存储
1. sudomkdir /srv
2. sudotruncate -s 1GB /srv/swift-disk
3. sudomkfs.xfs /srv/swift-disk
修改truncate命令中指定的大小以根据需要创建更大或更小的分区
2》 编辑修改分区表/etc/fstab并添加(sudo gedit /etc/fstab):
/srv/swift-disk /mnt/sda1 xfs loop,noatime,nodiratime,nobarrier,logbufs=80 0
3》 创建挂载点和链接
1. sudomkdir /mnt/sda1
2. sudomount /mnt/sda1
3. sudomkdir /mnt/sda1/1 /mnt/sda1/2 /mnt/sda1/3 /mnt/sda1/4
4. sudochown ${USER}:${USER} /mnt/sda1/*
5. forx in {1..4}; do sudo ln -s /mnt/sda1/$x /srv/$x; done
6. sudomkdir -p /srv/1/node/sda1 /srv/1/node/sda5 \
/srv/2/node/sda2 /srv/2/node/sda6\
/srv/3/node/sda3 /srv/3/node/sda7 \
/srv/4/node/sda4 /srv/4/node/sda8 \
/var/run/swift
7. sudochown -R ${USER}:${USER} /var/run/swift
8. forx in {1..4}; do sudo chown -R ${USER}:${USER} /srv/$x/; done
4》 CommonPost-Device Setup
添加下面几行到/etc/rc.local中(在exit 0 之前):
1. mkdir-p /var/cache/swift /var/cache/swift2 /var/cache/swift3 /var/cache/swift4
2. chown<your-user-name>:<your-group-name> /var/cache/swift*
3. mkdir-p /var/run/swift
4. chown<your-user-name>:<your-group-name> /var/run/swift
3) 获取代码
1》下载python-swiftclient代码
1. cd$HOME; git clone https://github.com/openstack/python-swiftclient.git
2》编译并安装python-swiftclient
1. cd$HOME/python-swiftclient; sudo python setup.py develop; cd –
3》下载swift的代码
1. gitclone https://github.com/openstack/swift.git
4》编译并安装swift
注意:在Ubuntu14.04中按照官方文档的安装方式有些包是安装不上的,因为包之间的版本冲突
感谢印度小哥Manikandan Venkatesan manikandanv@compunetconnections.com的帮助
1. cd $Home/swift
2. sudo apt-get purgepython-setuptools
3. sudo apt-get install python-pbr
4. sudo pip install -rrequirements.txt
5. sudo pip install -rtest-requirements.txt
6. sudo python setup.py develop;cd –
4) 安装rsync
1》 创建/etc/rsyncd.conf:
1. sudocp $HOME/swift/doc/saio/rsyncd.conf /etc/
2. sudosed -i "s/<your-user-name>/${USER}/" /etc/rsyncd.conf
默认rsyncd.conf文件内容如下,用来修复上面的修改
uid = <your-user-name>
gid = <your-user-name>
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
再次提醒读者注意这里和接下来所出现的所有IP地址
2》 在Ubuntu,修改/etc/default/rsync中的下面一行
1. RSYNC_ENABLE=true
3》 启动rsync
1. sudoservice rsync restart
4》 验证rsync是不是接受了所有的连接
1. rsyncrsync://pub@localhost/
执行上述命令,应该会看到
account6012
account6022
account6032
account6042
container6011
container6021
container6031
container6041
object6010
object6020
object6030
object6040
5) 启动memcached
sudo serviceMemcached start
tempauth中间件在memcached中存储令牌。如果memcached是没有运行,令牌不能被验证,就无法使用swift
(可选) 启动rsyslog,为swift建立独立的日志
1》 安装swift rsyslog的配置
1. sudo cp$HOME/swift/doc/saio/rsyslog.d/10-swift.conf /etc/rsyslog.d/
查看该conf文件以确定是否要将日志独立出来,以及是否需要每小时处理统计信息的日志。为方便起见,我们提供以下默认内容:
# Uncomment thefollowing to have a log containing all logs together
#local1,local2,local3,local4,local5.* /var/log/swift/all.log
# Uncomment thefollowing to have hourly proxy logs for stats processing
#$templateHourlyProxyLog,"/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.* ~
local6.*;local6.!notice /var/log/swift/expirer.log
local6.notice /var/log/swift/expirer.error
local6.* ~
2》 编辑/etc/rsyslog.conf 并进行以下修改(在“GLOBAL DIRECTIVES”中)
$PrivDropToGroup adm
3》 如果使用的是hourly logs则执行下面的
sudo mkdir -p /var/log/swift/hourly
否则执行
sudomkdir -p /var/log/swift
4》 创建日志目录,启动syslog
1. sudo chown -Rsyslog.adm /var/log/swift
2. sudo chmod -R g+w /var/log/swift
3. sudo service rsyslog restart
6) 配置每一个节点
执行以下步骤时,请务必查看配置文件是否与示例一致,注意ip和端口号
1》(可选)删除已经存在的swift目录
1. sudo rm -rf/etc/swift
2》往/etc/swift中添加配置文件
1. cd$HOME/swift/doc; sudo cp -r saio/swift /etc/swift; cd –
2. sudo chown -R${USER}:${USER} /etc/swift
3》在swift配置文件中更新<your-user-name>引用
1. find /etc/swift/-name \*.conf | xargs sudo sed -i "s/<your-user-name>/${USER}/"
通过执行上述命令提供的配置文件的内容如下:
1./etc/swift/swift.conf
[swift-hash]
# random uniquestrings that can never change (DO NOT LOSE)
# Use only printablechars (python -c "import string; print(string.printable)")
swift_hash_path_prefix = changeme
swift_hash_path_suffix = changeme
[storage-policy:0]
name = gold
policy_type = replication
default = yes
[storage-policy:1]
name = silver
policy_type = replication
[storage-policy:2]
name = ec42
policy_type = erasure_coding
ec_type = liberasurecode_rs_vand
ec_num_data_fragments =4
ec_num_parity_fragments= 2
2./etc/swift/proxy-server.conf
[DEFAULT]
bind_ip = 127.0.0.1
bind_port = 8080
workers = 1
user =<your-user-name>
log_facility =LOG_LOCAL1
eventlet_debug = true
[pipeline:main]
# Yes, proxy-loggingappears twice. This is so that
#middleware-originated requests get logged too.
pipeline = catch_errorsgatekeeper healthcheck proxy-logging cache bulk tempurl ratelimit crossdomaincontainer_sync tempauth staticweb copy container-quotas account-quotas slo dloversioned_writes proxy-logging proxy-server
[filter:catch_errors]
use = egg:swift#catch_errors
[filter:healthcheck]
use = egg:swift#healthcheck
[filter:proxy-logging]
use = egg:swift#proxy_logging
[filter:bulk]
use = egg:swift#bulk
[filter:ratelimit]
use = egg:swift#ratelimit
[filter:crossdomain]
use = egg:swift#crossdomain
[filter:dlo]
use = egg:swift#dlo
[filter:slo]
use = egg:swift#slo
[filter:container_sync]
use = egg:swift#container_sync
current =//saio/saio_endpoint
[filter:tempurl]
use = egg:swift#tempurl
[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:staticweb]
use = egg:swift#staticweb
[filter:account-quotas]
use = egg:swift#account_quotas
[filter:container-quotas]
use = egg:swift#container_quotas
[filter:cache]
use = egg:swift#memcache
[filter:gatekeeper]
use = egg:swift#gatekeeper
[filter:versioned_writes]
use = egg:swift#versioned_writes
allow_versioned_writes= true
[filter:copy]
use = egg:swift#copy
[app:proxy-server]
use = egg:swift#proxy
allow_account_management= true
account_autocreate = true
3./etc/swift/object-expirer.conf
[DEFAULT]
# swift_dir =/etc/swift
user =<your-user-name>
# You can specifydefault log routing here if you want:
log_name =object-expirer
log_facility =LOG_LOCAL6
log_level = INFO
#log_address =/dev/log
#
# comma separatedlist of functions to call to setup custom log handlers.
# functions getpassed: conf, name, log_to_console, log_route, fmt, logger,
# adapted_logger
# log_custom_handlers=
#
# If set,log_udp_host will override log_address
# log_udp_host =
# log_udp_port = 514
#
# You can enableStatsD logging here:
# log_statsd_host =
# log_statsd_port =8125
#log_statsd_default_sample_rate = 1.0
#log_statsd_sample_rate_factor = 1.0
#log_statsd_metric_prefix =
[object-expirer]
interval = 300
# auto_create_account_prefix= .
# report_interval =300
# concurrency is thelevel of concurrency o use to do the work, this value
# must be set to atleast 1
# concurrency = 1
# processes is howmany parts to divide the work into, one part per process
# that will be doing the work
# processes set 0means that a single process will be doing all the work
# processes can alsobe specified on the command line and will override the
# config value
# processes = 0
# process is which ofthe parts a particular process will work on
# process can also bespecified on the command line and will override the config
# value
# process is"zero based", if you want to use 3 processes, you should run
# processes with process set to 0, 1, and 2
# process = 0
[pipeline:main]
pipeline = catch_errorscache proxy-server
[app:proxy-server]
use = egg:swift#proxy
# Seeproxy-server.conf-sample for options
[filter:cache]
use = egg:swift#memcache
# Seeproxy-server.conf-sample for options
[filter:catch_errors]
use = egg:swift#catch_errors
# Seeproxy-server.conf-sample for options
4./etc/swift/container-reconciler.conf
[DEFAULT]
# swift_dir =/etc/swift
user =<your-user-name>
# You can specifydefault log routing here if you want:
# log_name = swift
# log_facility =LOG_LOCAL0
# log_level = INFO
# log_address =/dev/log
#
# comma separatedlist of functions to call to setup custom log handlers.
# functions getpassed: conf, name, log_to_console, log_route, fmt, logger,
# adapted_logger
# log_custom_handlers=
#
# If set,log_udp_host will override log_address
# log_udp_host =
# log_udp_port = 514
#
# You can enableStatsD logging here:
# log_statsd_host =
# log_statsd_port =8125
#log_statsd_default_sample_rate = 1.0
#log_statsd_sample_rate_factor = 1.0
#log_statsd_metric_prefix =
[container-reconciler]
# reclaim_age =604800
# interval = 300
# request_tries = 3
[pipeline:main]
pipeline = catch_errorsproxy-logging cache proxy-server
[app:proxy-server]
use = egg:swift#proxy
# Seeproxy-server.conf-sample for options
[filter:cache]
use = egg:swift#memcache
# Seeproxy-server.conf-sample for options
[filter:proxy-logging]
use = egg:swift#proxy_logging
[filter:catch_errors]
use = egg:swift#catch_errors
# Seeproxy-server.conf-sample for options
5./etc/swift/container-sync-realms.conf
[saio]
key = changeme
key2 = changeme
cluster_saio_endpoint =http://127.0.0.1:8080/v1/
6./etc/swift/account-server/1.conf
[DEFAULT]
devices = /srv/1/node
mount_check = false
disable_fallocate = true
bind_ip = 127.0.0.1
bind_port = 6012
workers = 1
user =<your-user-name>
log_facility =LOG_LOCAL2
recon_cache_path =/var/cache/swift
eventlet_debug = true
[pipeline:main]
pipeline = reconaccount-server
[app:account-server]
use = egg:swift#account
[filter:recon]
use = egg:swift#recon
[account-replicator]
rsync_module ={replication_ip}::account{replication_port}
[account-auditor]
[account-reaper]
7./etc/swift/container-server/1.conf
[DEFAULT]
devices = /srv/1/node
mount_check = false
disable_fallocate = true
bind_ip = 127.0.0.1
bind_port = 6011
workers = 1
user =<your-user-name>
log_facility =LOG_LOCAL2
recon_cache_path =/var/cache/swift
eventlet_debug = true
[pipeline:main]
pipeline = reconcontainer-server
[app:container-server]
use = egg:swift#container
[filter:recon]
use = egg:swift#recon
[container-replicator]
rsync_module ={replication_ip}::container{replication_port}
[container-updater]
[container-auditor]
[container-sync]
8./etc/swift/object-server/1.conf
[DEFAULT]
devices = /srv/1/node
mount_check = false
disable_fallocate = true
bind_ip = 127.0.0.1
bind_port = 6010
workers = 1
user =<your-user-name>
log_facility =LOG_LOCAL2
recon_cache_path =/var/cache/swift
eventlet_debug = true
[pipeline:main]
pipeline = reconobject-server
[app:object-server]
use = egg:swift#object
[filter:recon]
use = egg:swift#recon
[object-replicator]
rsync_module ={replication_ip}::object{replication_port}
[object-reconstructor]
[object-updater]
[object-auditor]
9./etc/swift/account-server/2.conf
[DEFAULT]
devices = /srv/2/node
mount_check = false
disable_fallocate = true
bind_ip = 127.0.0.1
bind_port = 6022
workers = 1
user =<your-user-name>
log_facility =LOG_LOCAL3
recon_cache_path =/var/cache/swift2
eventlet_debug = true
[pipeline:main]
pipeline = reconaccount-server
[app:account-server]
use = egg:swift#account
[filter:recon]
use = egg:swift#recon
[account-replicator]
rsync_module ={replication_ip}::account{replication_port}
[account-auditor]
[account-reaper]
10./etc/swift/container-server/2.conf
[DEFAULT]
devices = /srv/2/node
mount_check = false
disable_fallocate = true
bind_ip = 127.0.0.1
bind_port = 6021
workers = 1
user =<your-user-name>
log_facility =LOG_LOCAL3
recon_cache_path =/var/cache/swift2
eventlet_debug = true
[pipeline:main]
pipeline = reconcontainer-server
[app:container-server]
use = egg:swift#container
[filter:recon]
use = egg:swift#recon
[container-replicator]
rsync_module ={replication_ip}::container{replication_port}
[container-updater]
[container-auditor]
[container-sync]
11./etc/swift/object-server/2.conf
[DEFAULT]
devices = /srv/2/node
mount_check = false
disable_fallocate = true
bind_ip = 127.0.0.1
bind_port = 6020
workers = 1
user =<your-user-name>
log_facility =LOG_LOCAL3
recon_cache_path =/var/cache/swift2
eventlet_debug = true
[pipeline:main]
pipeline = reconobject-server
[app:object-server]
use = egg:swift#object
[filter:recon]
use = egg:swift#recon
[object-replicator]
rsync_module ={replication_ip}::object{replication_port}
[object-reconstructor]
[object-updater]
[object-auditor]
12./etc/swift/account-server/3.conf
[DEFAULT]
devices = /srv/3/node
mount_check = false
disable_fallocate = true
bind_ip = 127.0.0.1
bind_port = 6032
workers = 1
user =<your-user-name>
log_facility =LOG_LOCAL4
recon_cache_path =/var/cache/swift3
eventlet_debug = true
[pipeline:main]
pipeline = reconaccount-server
[app:account-server]
use = egg:swift#account
[filter:recon]
use = egg:swift#recon
[account-replicator]
rsync_module ={replication_ip}::account{replication_port}
[account-auditor]
[account-reaper]
13./etc/swift/container-server/3.conf
[DEFAULT]
devices = /srv/3/node
mount_check = false
disable_fallocate = true
bind_ip = 127.0.0.1
bind_port = 6031
workers = 1
user =<your-user-name>
log_facility =LOG_LOCAL4
recon_cache_path =/var/cache/swift3
eventlet_debug = true
[pipeline:main]
pipeline = reconcontainer-server
[app:container-server]
use = egg:swift#container
[filter:recon]
use = egg:swift#recon
[container-replicator]
rsync_module ={replication_ip}::container{replication_port}
[container-updater]
[container-auditor]
[container-sync]
14./etc/swift/object-server/3.conf
[DEFAULT]
devices = /srv/3/node
mount_check = false
disable_fallocate = true
bind_ip = 127.0.0.1
bind_port = 6030
workers = 1
user =<your-user-name>
log_facility =LOG_LOCAL4
recon_cache_path =/var/cache/swift3
eventlet_debug = true
[pipeline:main]
pipeline = reconobject-server
[app:object-server]
use = egg:swift#object
[filter:recon]
use = egg:swift#recon
[object-replicator]
rsync_module ={replication_ip}::object{replication_port}
[object-reconstructor]
[object-updater]
[object-auditor]
15./etc/swift/account-server/4.conf
[DEFAULT]
devices = /srv/4/node
mount_check = false
disable_fallocate = true
bind_ip = 127.0.0.1
bind_port = 6042
workers = 1
user =<your-user-name>
log_facility =LOG_LOCAL5
recon_cache_path =/var/cache/swift4
eventlet_debug = true
[pipeline:main]
pipeline = reconaccount-server
[app:account-server]
use = egg:swift#account
[filter:recon]
use = egg:swift#recon
[account-replicator]
rsync_module ={replication_ip}::account{replication_port}
[account-auditor]
[account-reaper]
16./etc/swift/container-server/4.conf
[DEFAULT]
devices = /srv/4/node
mount_check = false
disable_fallocate = true
bind_ip = 127.0.0.1
bind_port = 6041
workers = 1
user = <your-user-name>
log_facility =LOG_LOCAL5
recon_cache_path =/var/cache/swift4
eventlet_debug = true
[pipeline:main]
pipeline = reconcontainer-server
[app:container-server]
use = egg:swift#container
[filter:recon]
use = egg:swift#recon
[container-replicator]
rsync_module ={replication_ip}::container{replication_port}
[container-updater]
[container-auditor]
[container-sync]
17./etc/swift/object-server/4.conf
[DEFAULT]
devices = /srv/4/node
mount_check = false
disable_fallocate = true
bind_ip = 127.0.0.1
bind_port = 6040
workers = 1
user =<your-user-name>
log_facility =LOG_LOCAL5
recon_cache_path =/var/cache/swift4
eventlet_debug = true
[pipeline:main]
pipeline = reconobject-server
[app:object-server]
use = egg:swift#object
[filter:recon]
use = egg:swift#recon
[object-replicator]
rsync_module ={replication_ip}::object{replication_port}
[object-reconstructor]
[object-updater]
[object-auditor]
注意:在我配置节点过程中,执行cd$HOME/swift/doc; sudo cp -r saio/swift /etc/swift; cd -之后所得到的文件中,如/etc/swift/account-server/2.conf,
会发现默认 bind_ip=127.0.0.2,其他文件会有bind_ip=127.0.0.3或者4,这样是行不通的,因为服务器只有一块网卡,所以要将bind_ip改回127.0.0.1
7) 创建运行swift的脚本
1》复制SAIO脚本,重新设置环境
1. mkdir -p $HOME/bin
2. cd$HOME/swift/doc; cp saio/bin/* $HOME/bin; cd –
3. chmod +x$HOME/bin/*
2》编辑$HOME/bin/resetswift脚本
模板resetswift脚本如下:
#!/bin/bash
set-e
swift-init all kill
# Remove thefollowing line if you did not set up rsyslog for individual logging:
sudo find /var/log/swift -type f -exec rm -f {} \;
if cut -d' '-f2 /proc/mounts | grep-q /mnt/sda1 ; then
sudo umount /mnt/sda1
fi
# If you areusing a loopback device set SAIO_BLOCK_DEVICE to "/srv/swift-disk"
sudo mkfs.xfs -f${SAIO_BLOCK_DEVICE:-/srv/swift-disk}
sudo mount /mnt/sda1
sudo mkdir /mnt/sda1/1 /mnt/sda1/2 /mnt/sda1/3 /mnt/sda1/4
sudo chown ${USER}:${USER} /mnt/sda1/*
mkdir -p /srv/1/node/sda1 /srv/1/node/sda5 \
/srv/2/node/sda2 /srv/2/node/sda6 \
/srv/3/node/sda3 /srv/3/node/sda7 \
/srv/4/node/sda4 /srv/4/node/sda8
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 {} \;
if [ "`type -t systemctl`" == "file" ]; then
sudo systemctl restart rsyslog
sudo systemctl restart memcached
else
sudo service rsyslog restart
sudo service memcached restart
fi
如果使用回环设备,请使用/srv/swift-disk添加环境变量var替换/dev/sdb1:
1. echo "exportSAIO_BLOCK_DEVICE=/srv/swift-disk" >> $HOME/.bashrc
如果没有为单个日志记录设置rsyslog,请删除find /var/log/swift ...行:
1. sed -i "/find\/var\/log\/swift/d" $HOME/bin/resetswift
3》安装运行测试的样本配置
1. cp$HOME/swift/test/sample.conf /etc/swift/test.conf
模板test.conf如下所示:
[func_test]
# Sample configfor Swift with tempauth
auth_host = 127.0.0.1
auth_port = 8080
auth_ssl = no
auth_prefix = /auth/
# Sample configfor Swift with Keystone v2 API.
# For keystonev2 change auth_version to 2 and auth_prefix to /v2.0/.
# And"allow_account_management" should not be set "true".
#auth_version =3
#auth_host =localhost
#auth_port =5000
#auth_ssl = no
#auth_prefix =/v3/
# Primaryfunctional test account (needs admin access to the account)
account = test
username = tester
password = testing
# User on asecond account (needs admin access to the account)
account2 = test2
username2 = tester2
password2 = testing2
# User on sameaccount as first, but without admin access
username3 = tester3
password3 = testing3
# Fourth user isrequired for keystone v3 specific tests.
# Account mustbe in a non-default domain.
#account4 =test4
#username4 =tester4
#password4 =testing4
#domain4 =test-domain
# Fifth user isrequired for service token-specific tests.
# The accountmust be different from the primary test account.
# The user mustnot have a group (tempauth) or role (keystoneauth) on
# the primarytest account. The user must have a group/role that is unique
# and not givento the primary tester and is specified in the options
#<prefix>_require_group (tempauth) or <prefix>_service_roles(keystoneauth).
#account5 =test5
#username5 =tester5
#password5 =testing5
# Theservice_prefix option is used for service token-specific tests.
# If service_prefixor username5 above is not supplied, the tests are skipped.
# To set thevalue and enable the service token tests, look at the
#reseller_prefix option in /etc/swift/proxy-server.conf. There must be at
# least twoprefixes. If not, add a prefix as follows (where we add SERVICE):
# reseller_prefix = AUTH, SERVICE
# Theservice_prefix must match the <prefix> used in<prefix>_require_group
# (tempauth) or<prefix>_service_roles (keystoneauth); for example:
# SERVICE_require_group = service
# SERVICE_service_roles = service
# Note: Do notenable service token tests if the first prefix in
#reseller_prefix is the empty prefix AND the primary functional test
# accountcontains an underscore.
#service_prefix= SERVICE
# Sixth user isrequired for access control tests.
# Account musthave a role for reseller_admin_role(keystoneauth).
#account6 = test
#username6 =tester6
#password6 =testing6
collate = C
# Only necessaryif a pre-existing server uses self-signed certificate
insecure = no
[unit_test]
fake_syslog = False
[probe_test]
#check_server_timeout = 30
# validate_rsync= false
[swift-constraints]
# The functionaltest runner will try to use the constraint values provided in
# theswift-constraints section of test.conf.
#
# If a constraintvalue does not exist in that section, or because the
#swift-constraints section does not exist, the constraints values found in
# the /info APIcall (if successful) will be used.
#
# If aconstraint value cannot be found in the /info results, either because
# the /info APIcall failed, or a value is not present, the constraint value
# used will fallback to those loaded by the constraints module at time of
# import (whichwill attempt to load /etc/swift/swift.conf, see the
#swift.common.constraints module for more information).
#
# Note that thecluster must have "sane" values for the test suite to pass
# (for somedefinition of sane).
#
#max_file_size =5368709122
#max_meta_name_length= 128
#max_meta_value_length= 256
#max_meta_count= 90
#max_meta_overall_size= 4096
#max_header_size= 8192
#extra_header_count= 0
#max_object_name_length= 1024
#container_listing_limit= 10000
#account_listing_limit= 10000
#max_account_name_length= 256
#max_container_name_length= 256
# Newer swiftversions default to strict cors mode, but older ones were the
# opposite.
#strict_cors_mode= true
4》 添加运行测试用的环境变量
1. echo "exportSWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf" >> $HOME/.bashrc
5》 确保把bin目录设置到环境变量中去
1. echo "exportPATH=${PATH}:$HOME/bin" >> $HOME/.bashrc
6》 source环境变量,使其生效
1. . $HOME/.bashrc
7》 使用提供的脚本初始化rings
1. remakerings
remakerings脚本如下所示:
#!/bin/bash
set-e
cd /etc/swift
rm -f *.builder *.ring.gzbackups/*.builder backups/*.ring.gz
swift-ring-builder object.builder create 1031
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 object-1.builder create 1021
swift-ring-builder object-1.builder add r1z1-127.0.0.1:6010/sdb1 1
swift-ring-builder object-1.builder add r1z2-127.0.0.1:6020/sdb2 1
swift-ring-builder object-1.builder add r1z3-127.0.0.1:6030/sdb3 1
swift-ring-builder object-1.builder add r1z4-127.0.0.1:6040/sdb4 1
swift-ring-builder object-1.builder rebalance
swift-ring-builder object-2.builder create 1061
swift-ring-builder object-2.builder add r1z1-127.0.0.1:6010/sdb1 1
swift-ring-builder object-2.builder add r1z1-127.0.0.1:6010/sdb5 1
swift-ring-builder object-2.builder add r1z2-127.0.0.1:6020/sdb2 1
swift-ring-builder object-2.builder add r1z2-127.0.0.1:6020/sdb6 1
swift-ring-builder object-2.builder add r1z3-127.0.0.1:6030/sdb3 1
swift-ring-builder object-2.builder add r1z3-127.0.0.1:6030/sdb7 1
swift-ring-builder object-2.builder add r1z4-127.0.0.1:6040/sdb4 1
swift-ring-builder object-2.builder add r1z4-127.0.0.1:6040/sdb8 1
swift-ring-builder object-2.builder rebalance
swift-ring-builder container.builder create 1031
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 1031
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
注意:cp过来的remakerings文件ip分为127.0.0.1;127.0.0.2;127.0.0.3;127.0.0.4.这样是不可以使用的,需要全部改为127.0.0.1
此命令的输出产生以下内容。请注意,创建3个对象环以便在SAIO环境中测试存储策略和EC。EC环是唯一具有所有8个设备的环。还有两个复制环,一个用于3x复制,另一个用于2x复制,但是这些环仅使用4个设备:
remakerings运行结果:
Device d0r1z1-127.0.0.1:6010R127.0.0.1:6010/sdb1_"" with 1.0 weight got id 0
Device d1r1z2-127.0.0.1:6020R127.0.0.1:6020/sdb2_"" with 1.0 weight got id 1
Device d2r1z3-127.0.0.1:6030R127.0.0.1:6030/sdb3_"" with 1.0 weight got id 2
Device d3r1z4-127.0.0.1:6040R127.0.0.1:6040/sdb4_"" with 1.0 weight got id 3
Reassigned 1024 (100.00%) partitions. Balanceis now 0.00. Dispersion is now 0.00
Device d0r1z1-127.0.0.1:6010R127.0.0.1:6010/sdb1_"" with 1.0 weight got id 0
Device d1r1z2-127.0.0.1:6020R127.0.0.1:6020/sdb2_"" with 1.0 weight got id 1
Device d2r1z3-127.0.0.1:6030R127.0.0.1:6030/sdb3_"" with 1.0 weight got id 2
Device d3r1z4-127.0.0.1:6040R127.0.0.1:6040/sdb4_"" with 1.0 weight got id 3
Reassigned 1024 (100.00%) partitions. Balanceis now 0.00. Dispersion is now 0.00
Device d0r1z1-127.0.0.1:6010R127.0.0.1:6010/sdb1_"" with 1.0 weight got id 0
Device d1r1z1-127.0.0.1:6010R127.0.0.1:6010/sdb5_"" with 1.0 weight got id 1
Device d2r1z2-127.0.0.1:6020R127.0.0.1:6020/sdb2_"" with 1.0 weight got id 2
Device d3r1z2-127.0.0.1:6020R127.0.0.1:6020/sdb6_"" with 1.0 weight got id 3
Device d4r1z3-127.0.0.1:6030R127.0.0.1:6030/sdb3_"" with 1.0 weight got id 4
Device d5r1z3-127.0.0.1:6030R127.0.0.1:6030/sdb7_"" with 1.0 weight got id 5
Device d6r1z4-127.0.0.1:6040R127.0.0.1:6040/sdb4_"" with 1.0 weight got id 6
Device d7r1z4-127.0.0.1:6040R127.0.0.1:6040/sdb8_"" with 1.0 weight got id 7
Reassigned 1024 (100.00%) partitions. Balanceis now 0.00. Dispersion is now 0.00
Device d0r1z1-127.0.0.1:6011R127.0.0.1:6011/sdb1_"" with 1.0 weight got id 0
Device d1r1z2-127.0.0.1:6021R127.0.0.1:6021/sdb2_"" with 1.0 weight got id 1
Device d2r1z3-127.0.0.1:6031R127.0.0.1:6031/sdb3_"" with 1.0 weight got id 2
Device d3r1z4-127.0.0.1:6041R127.0.0.1:6041/sdb4_"" with 1.0 weight got id 3
Reassigned 1024 (100.00%) partitions. Balance isnow 0.00. Dispersion is now 0.00
Device d0r1z1-127.0.0.1:6012R127.0.0.1:6012/sdb1_"" with 1.0 weight got id 0
Device d1r1z2-127.0.0.1:6022R127.0.0.1:6022/sdb2_"" with 1.0 weight got id 1
Device d2r1z3-127.0.0.1:6032R127.0.0.1:6032/sdb3_"" with 1.0 weight got id 2
Device d3r1z4-127.0.0.1:6042R127.0.0.1:6042/sdb4_"" with 1.0 weight got id 3
Reassigned 1024 (100.00%) partitions. Balanceis now 0.00. Dispersion is now 0.00
8》运行单元测试
1. $HOME/swift/.unittests
9》启动swift的主线程,分别包括(proxy,account,container和object)几个进程
1. startmain
(遇到“Unable to increase file descriptor limit.Running as non-root?” 警告提示不用理。)
startmain
脚本如下所示:
#!/bin/bash
set-e
swift-init main start
10》 获取X-Storage-Url和X-Auth-Token
1. curl -v -H'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' http://127.0.0.1:8080/auth/v1.0
可以得到以下返回信息:
* About to connect() to 127.0.0.1 port 8080 (#0) * Trying 127.0.0.1... connected * Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0) > GET /auth/v1.0 HTTP/1.1 > User-Agent: curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15 > Host: 127.0.0.1:8080 > Accept: */* > X-Storage-User: test:tester > X-Storage-Pass: testing
< HTTP/1.1 200 OK < X-Storage-Url: http://127.0.0.1:8080/v1/AUTH_test < X-Storage-Token: AUTH_tk6474e5ee0cb04832b9d2a168e1a164d8 < X-Auth-Token: AUTH_tk6474e5ee0cb04832b9d2a168e1a164d8 < Content-Length: 0 < Date: Mon, 04 Jul 2011 01:36:57 GMT * Connection #0 to host 127.0.0.1 left intact *Closing connection #0 |
11》 检查能否获得account
1. curl -v -H'X-Auth-Token: <token-from-x-auth-token-above>'<url-from-x-storage-url-above>
12》 检查python-swiftclient提供的swift命令是否可用
1. swift -Ahttp://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 |
13》 验证unctional tests的运行
1. $HOME/swift/.functests
(注意:功能测试将首先删除已配置帐户中的所有内容。)
14》 验证probe tests的运行
1. $HOME/swift/.probetests
(注意:probe tests将在每个测试调用resetswift时重置您的环境。)
8) swift的简单应用
1》创建container, 创建一个名称为container_test的container(目录),注意使用当前的token
1. curl -X PUT -D- -H "X-Auth_Token:AUTH_tk6474e5ee0cb04832b9d2a168e1a164d8"http://127.0.0.1:8080/v1/AUTH_test/container_test
正确情况下,应该得到以下信息:
HTTP/1.1 201 Created Content-Length: 0 Content-Type: text/html; charset=UTF-8 Date: Mon, 04 Jul 2011 01:39:38 GMT |
2》查看test用户的container列表,发现只有一个目录:container_test
1. swift -Ahttp://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list
显示结果:
container_test
3》上传文件,上传1.txt文件到container_test目录中
1. swift -Ahttp://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing upload container_test$HOME/1.txt
显示结果:
home/server403/1.txt
4》下载文件(object)
1. swift -Ahttp://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing download container_test
将container_test目录内的所有内容下载到目前所在目录。注意:如果上传文件的时候,有嵌套目录,则上传到Swift上后,也是以嵌套目录的形式存在,下载后,会在当前目录创建一样的嵌套目录。
至此,Swift All-In-One安装配置结束!