当前位置: 首页 > 工具软件 > swift-xattr > 使用案例 >

Ubuntu 12.04 OpenStack Swift单节点部署手册

锺离晗昱
2023-12-01

说明

·        此文档为基于官方修改的只针对Ubuntu 12.04,完整的参阅官方文档

·        本部署为开发环境,Swift配置为以root权限运行,生产环境推荐新建用户swift

·        Ubuntu Server安装时不选其它组件,最小化安装

·        以下安装命令全部以root身份运行

Ubuntu 更新:

sudo apt-get update

sudo apt-get upgrade

安装依赖

apt-get update

apt-get install curl gcc memcached rsync sqlite3 xfsprogsgit python-setuptools

apt-get install python-coverage python-dev python-nosepython-simplejson python-xattr python-eventlet python-greenletpython-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 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

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  root:root/var/cache/swift*

mkdir -p /var/run/swift

chown  root:root  /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_ENABLEtrue:

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 clonehttps://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-loggingproxy-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 NOTLOSE)

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 /home/pz/bin

创建脚本/home/pz/bin/resetswift

因未创建rsyslog作为独立日志,已移除find /var/log/swift…这一行 
如果使用的是单独分区存储需要将/srv/swift-disk替换为/dev/sdb1

#!/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

创建脚本/home/pz/bin/remakerings

#!/bin/bash

cd /etc/swift

rm -f *.builder *.ring.gz backups/*.builderbackups/*.ring.gz

swift-ring-builder object.builder create 10 3 1

swift-ring-builder object.builder addr1z1-127.0.0.1:6010/sdb1 1

swift-ring-builder object.builder addr1z2-127.0.0.1:6020/sdb2 1

swift-ring-builder object.builder addr1z3-127.0.0.1:6030/sdb3 1

swift-ring-builder object.builder addr1z4-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 addr1z1-127.0.0.1:6011/sdb1 1

swift-ring-builder container.builder addr1z2-127.0.0.1:6021/sdb2 1

swift-ring-builder container.builder addr1z3-127.0.0.1:6031/sdb3 1

swift-ring-builder container.builder add r1z4-127.0.0.1:6041/sdb41

swift-ring-builder container.builder rebalance

swift-ring-builder account.builder create 10 3 1

swift-ring-builder account.builder addr1z1-127.0.0.1:6012/sdb1 1

swift-ring-builder account.builder addr1z2-127.0.0.1:6022/sdb2 1

swift-ring-builder account.builder addr1z3-127.0.0.1:6032/sdb3 1

swift-ring-builder account.builder addr1z4-127.0.0.1:6042/sdb4 1

swift-ring-builder account.builder rebalance

创建/home/pz/bin/startmain

#!/bin/bash

swift-init main start

创建/home/pz/bin/startrest

#!/bin/bash

swift-init rest start

chmod +x ~/bin/*

编辑~/.bashrc,在最后添加如下两行

export SWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf

export PATH=${PATH}:~/bin

然后执行下列命令

. ~/.bashrc

remakerings

cp /home/pz/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


简单使用
  1.获取一个 X-Storage-Url 和 X-Auth-Token。
#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
2. 检查账户。注意,X-Auth-Token:与<token-from-x-auth-token-above>之间存在一个空格,一定不能丢。
# curl -v -H 'X-Auth-Token: <token-from-x-auth-token-above>' <url-from-x-storage-url-above>
1. 检查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
2. 创建container,创建一个名称为container_test的container(目录),注意使用当前的token。
# 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


3. 查看test用户的container列表,发现只有一个目录:container_test。
# swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list
container_test
4. 上传Object(文件),上传hello文件到container_test目录中。
# swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing upload container_test /root/hello
root/hello
5. 查看目录中的内容,查看container_test目录中的内容。
# swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing list container_test
root/hello
6. 下载Object(文件)下载container_test下的object。
# swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K testing download container_test
  将container_test目录内的所有内容下载到目前所在目录。注意:如果上传文件的时候,有嵌套目录,则上传到Swift上后,也是以嵌套目录的形式存在,下载后,会在当前目录创建一样的嵌套目录。
________________________________________
补充说明:
  现在已经完成SAIO的部署了,下面介绍一下系统环境的改变:
  1. ~/swift目录下存放Swift与python-swiftclient的源代码与执行脚本。
~/swift/bin目录下存放执行脚本。
~/swift/swift_1.7.6目录下存放Swift的源代码。
~/swift/python-swiftclient_1.2.0目录下存放Swift客户端的源代码。
  2. /usr/local/lib/python2.7/dist-packages、/usr/share/pyshared、/usr/bin、/usr/local/bin等目录下存放Swift与python-swiftclient安装后的程序文件。
  3. Swift的回环设备挂载在/mnt/sdb1目录上。
  4. 回环设备对应的文件为/srv/swift-disk。
  5. 四个存储节点对应的实际存储空间(即共享上述回环设备)——/mnt/sdb1/1、/mnt/sdb1/2、/mnt/sdb1/3、/mnt/sdb1/4。
  6. 四个存储节点指向实际存储空间的软链接——/srv/1、/srv/2、/srv/3、/srv/4。
  7. 四个存储节点的对应的虚拟挂载点——/srv/1/node/sdb1、/srv/2/node/sdb2、/srv/2/node/sdb2、/srv/2/node/sdb2。
  8. Swift运行时所需目录/var/run/swift,用于存放各个服务进程的pid文件等内容。
  9. Swift临时缓存的目录(姑且这么理解)——/var/cache/swift、/var/cache/swift2、/var/cache/swift3、/var/cache/swift4。
  10. /etc/swift目录中存放Swift自身的配置文件。
/etc/swift/object-server目录中存放四个存储节点的Object Server配置文件。
/etc/swift/container-server目录中存放四个存储节点的Container Server配置文件。
/etc/swift/account-server目录中存放四个存储节点的Account Server配置文件。
/etc/swift/proxy-server.conf为Proxy Server的配置文件。
/etc/swift/swift.conf为Swift哈希后缀的配置文件。
backups目录、*.builder文件和*.ring.rz文件都是Ring的相关文件,其中*.ring.rz文件记录了生成的Ring。
test.conf文件是Swift单元测试所需的文件。
  11. /var/log/swift目录下存放rsyslog独立日志工具输出的日志文件。
  12. 其他被创建的文件:
/etc/rsyncd.conf,作为rsync数据镜像备份工具的配置文件。
/etc/rsyslog.d/10-swift.conf,作为rsyslog独立日志工具的配置文件。
  13. 其他被修改的文件:
/etc/fstab,回环设备挂载相关配置文件。
/etc/rc.local,使得系统在启动时自动创建一些Swift所需的目录,这些目录可能在系统关闭后丢失。
/etc/default/rsync,使rsync能开机启动。
/etc/rsyslog.conf,改变rsyslog工具所在的Group。
~/.bashrc,使新增的环境变量生效。

参考: 
http://docs.openstack.org/developer/swift/development_saio.html

 类似资料: