以前介紹了《OpenStack Swift All In One安裝部署流程與簡單使用》,那麼接下來就說一說Swift集羣部署吧。php
1. 簡介html
本文檔詳細描述了使用兩臺PC部署一個小型Swift集羣的過程,並給出一些簡單的使用實例。本文檔假定以下前提條件:node
閱讀本文檔前,能夠先閱讀文檔《Swift All In One安裝部署流程》,學習Swift單機部署的相關知識。python
2. 安裝部署linux
2.1 準備環境nginx
|
PC 1git |
PC 2github |
機器類型:sql |
PC物理機數據庫 |
PC物理機 |
操做系統: |
Ubuntu-12.04-desktop-64位 |
Ubuntu-12.04-desktop-64位 |
用戶類型: |
root |
root |
數據庫: |
sqlite3 |
sqlite3 |
IP地址: |
192.168.3.52(局域網) |
192.168.3.53(局域網) |
Proxy Server: |
是 |
是 |
Storage Server: |
是 |
是 |
Auth: |
TempAuth |
TempAuth |
Token緩存: |
memcached |
memcached |
2.2 版本說明
本文檔基於:
請確保安裝的Swift版本與本文檔中的版本相同。若有問題,請參考官網的更新文檔。
2.3 安裝軟件環境
首先,在PC1和PC2上安裝Swift所需的軟件環境(確保你的機器能夠訪問互聯網),例如,sqlite3做爲本地數據庫,memcached做爲Token緩存。Ubuntu-12.04已自帶rsync工具,所以不用另行安裝。
# cd ~/swift # git clone https://github.com/openstack/swift.git # git clone https://github.com/openstack/python-swiftclient.git |
eventlet>=0.9.15 greenlet>=0.3.1 netifaces>=0.6 pastedeploy>=1.3.3 simplejson>=2.0.9 xattr>=0.4 python-swiftclient |
mkdir -p /var/run/swift chown root:root /var/run/swift |
/srv/swift-disk /srv/node/sdb1 xfs loop,noatime,nodiratime,nobarrier,logbufs=8 0 0 |
# chown -R root:root /srv/node |
# mkdir -p /etc/swift # chown -R root:root /etc/swift/ |
[swift-hash] # random unique string that can never change (DO NOT LOSE) swift_hash_path_suffix = jtangfs |
uid = root gid = root log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid address = 192.168.3.52
[account] max connections = 2 path = /srv/node/ read only = false lock file = /var/lock/account.lock
[container] max connections = 2 path = /srv/node/ read only = false lock file = /var/lock/container.lock
[object] max connections = 2 path = /srv/node/ read only = false lock file = /var/lock/object.lock |
# perl -pi -e 's/RSYNC_ENABLE=false/RSYNC_ENABLE=true/' /etc/default/rsync # service rsync restart |
[DEFAULT] devices = /srv/node mount_check = false bind_ip = 192.168.3.52 bind_port = 6002 workers = 4 user = root log_facility = LOG_LOCAL4
[pipeline:main] pipeline = account-server
[app:account-server] use = egg:swift#account
[account-replicator]
[account-auditor]
[account-reaper] |
[DEFAULT] devices = /srv/node mount_check = false bind_ip = 192.168.3.52 bind_port = 6001 workers = 4 user = root log_facility = LOG_LOCAL3
[pipeline:main] pipeline = container-server
[app:container-server] use = egg:swift#container
[container-replicator]
[container-updater]
[container-auditor]
[container-sync] |
[DEFAULT] devices = /srv/node mount_check = false bind_ip = 192.168.3.52 bind_port = 6000 workers = 4 user = root log_facility = LOG_LOCAL2
[pipeline:main] pipeline = object-server
[app:object-server] use = egg:swift#object
[object-replicator]
[object-updater]
[object-auditor] |
# 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
local2.*;local2.!notice /var/log/swift/object.log local2.notice /var/log/swift/ object.error local2.* ~
local3.*;local3.!notice /var/log/swift/container.log local3.notice /var/log/swift/ container.error local3.* ~
local4.*;local4.!notice /var/log/swift/account.log local4.notice /var/log/swift/ account.error local4.* ~ |
[DEFAULT] bind_port = 8080 user = root workers = 8 log_facility = LOG_LOCAL1
[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 reseller_prefix = AUTH # account和token的命名前綴,注意此處不能夠加「_」。 # 例如X-Storage-Url爲http://192.168.3.52:8080/v1/AUTH_test # 例如X-Auth-Token爲AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1 token_life = 86400 # token的有效期,單位:秒。
[filter:healthcheck] use = egg:swift#healthcheck
[filter:cache] use = egg:swift#memcache memcache_servers = 192.168.3.52:11211,192.168.3.53:11211
[filter:proxy-logging] use = egg:swift#proxy_logging |
# 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/object.log local2.notice /var/log/swift/ object.error local2.* ~
local3.*;local3.!notice /var/log/swift/container.log local3.notice /var/log/swift/ container.error local3.* ~
local4.*;local4.!notice /var/log/swift/account.log local4.notice /var/log/swift/ account.error local4.* ~ |
# cd /etc/swift # swift-ring-builder account.builder create 18 2 1 # swift-ring-builder container.builder create 18 2 1 # swift-ring-builder object.builder create 18 2 1 |
# cd /etc/swift # swift-ring-builder account.builder add z1-192.168.3.52:6002/sdb1 100 # swift-ring-builder container.builder add z1-192.168.3.52:6001/sdb1 100 # swift-ring-builder object.builder add z1-192.168.3.52:6000/sdb1 100
# swift-ring-builder account.builder add z2-192.168.3.53:6002/sdb1 100 # swift-ring-builder container.builder add z2-192.168.3.53:6001/sdb1 100 # swift-ring-builder object.builder add z2-192.168.3.53:6000/sdb1 100 |
#!/bin/bash
cd /etc/swift
rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
swift-ring-builder account.builder create 18 2 1 swift-ring-builder container.builder create 18 2 1 swift-ring-builder object.builder create 18 2 1
swift-ring-builder account.builder add z1-192.168.3.52:6002/sdb1 100 swift-ring-builder container.builder add z1-192.168.3.52:6001/sdb1 100 swift-ring-builder object.builder add z1-192.168.3.52:6000/sdb1 100
swift-ring-builder account.builder add z2-192.168.3.53:6002/sdb1 100 swift-ring-builder container.builder add z2-192.168.3.53:6001/sdb1 100 swift-ring-builder object.builder add z2-192.168.3.53:6000/sdb1 100
swift-ring-builder account.builder rebalance swift-ring-builder container.builder rebalance swift-ring-builder object.builder rebalance |
#!/bin/bash
swift-init all stop find /var/log/swift -type f -exec rm -f {} \; sudo umount /srv/node/sdb1 sudo mkfs.xfs -f -i size=1024 /srv/swift-disk sudo mount /srv/node/sdb1 sudo chown root:root /srv/node/sdb1 sudo rm -f /var/log/debug /var/log/messages /var/log/rsyncd.log /var/log/syslog sudo service rsyslog restart sudo service rsync restart sudo service memcached restart |
#!/bin/bash
swift-init main start |
#!/bin/bash
swift-init main stop |
#!/bin/bash
swift-init proxy start swift-init account-server start swift-init account-replicator start swift-init account-auditor start swift-init container-server start swift-init container-replicator start swift-init container-updater start swift-init container-auditor start swift-init object-server start swift-init object-replicator start swift-init object-updater start swift-init object-auditor start |
#!/bin/bash
swift-init proxy stop swift-init account-server stop swift-init account-replicator stop swift-init account-auditor stop swift-init container-server stop swift-init container-replicator stop swift-init container-updater stop swift-init container-auditor stop swift-init object-server stop swift-init object-replicator stop swift-init object-updater stop swift-init object-auditor stop |
# chmod +x ~/swift/bin/* |
# cd ~/swift/swift_1.7.6 # ./.unittests |
# startmain 或 # startall |
# stopmain 或 # stopall |
# swift --help Usage: swift <command> [options] [args]
Commands: stat [container] [object] Displays information for the account, container, or object depending on the args given (if any). list [options] [container] Lists the containers for the account or the objects for a container. -p or --prefix is an option that will only list items beginning with that prefix. -d or --delimiter is option (for container listings only) that will roll up items with the given delimiter (see Cloud Files general documentation for what this means). upload [options] container file_or_directory [file_or_directory] [...] Uploads to the given container the files and directories specified by the remaining args. -c or --changed is an option that will only upload files that have changed since the last upload. -S <size> or --segment-size <size> and --leave-segments are options as well (see --help for more). post [options] [container] [object] Updates meta information for the account, container, or object depending on the args given. If the container is not found, it will be created automatically; but this is not true for accounts and objects. Containers also allow the -r (or --read-acl) and -w (or --write-acl) options. The -m or --meta option is allowed on all and used to define the user meta data items to set in the form Name:Value. This option can be repeated. Example: post -m Color:Blue -m Size:Large download --all OR download container [options] [object] [object] ... Downloads everything in the account (with --all), or everything in a container, or a list of objects depending on the args given. For a single object download, you may use the -o [--output] <filename> option to redirect the output to a specific file or if "-" then just redirect to stdout. delete [options] --all OR delete container [options] [object] [object] ... Deletes everything in the account (with --all), or everything in a container, or a list of objects depending on the args given. Segments of manifest objects will be deleted as well, unless you specify the --leave-segments option.
Example: swift -A https://auth.api.rackspacecloud.com/v1.0 -U user -K key stat
Options: --version show program's version number and exit -h, --help show this help message and exit -s, --snet Use SERVICENET internal network -v, --verbose Print more info -q, --quiet Suppress status output -A AUTH, --auth=AUTH URL for obtaining an auth token -V AUTH_VERSION, --auth-version=AUTH_VERSION Specify a version for authentication. Defaults to 1.0. -U USER, --user=USER User name for obtaining an auth token. -K KEY, --key=KEY Key for obtaining an auth token. --os-username=<auth-user-name> Openstack username. Defaults to env[OS_USERNAME]. --os-password=<auth-password> Openstack password. Defaults to env[OS_PASSWORD]. --os-tenant-id=<auth-tenant-id> OpenStack tenant ID. Defaults to env[OS_TENANT_ID] --os-tenant-name=<auth-tenant-name> Openstack tenant name. Defaults to env[OS_TENANT_NAME]. --os-auth-url=<auth-url> Openstack auth URL. Defaults to env[OS_AUTH_URL]. --os-auth-token=<auth-token> Openstack token. Defaults to env[OS_AUTH_TOKEN] --os-storage-url=<storage-url> Openstack storage URL. Defaults to env[OS_STORAGE_URL] --os-region-name=<region-name> Openstack region name. Defaults to env[OS_REGION_NAME] --os-service-type=<service-type> Openstack Service type. Defaults to env[OS_SERVICE_TYPE] --os-endpoint-type=<endpoint-type> Openstack Endpoint type. Defaults to env[OS_ENDPOINT_TYPE] --insecure Allow swiftclient to access insecure keystone server. The keystone's certificate will not be verified. |
# curl -k -v -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' http://192.168.3.52:8080/auth/v1.0 |
* About to connect() to 192.168.3.52 port 8080 (#0) * Trying 192.168.3.52... connected > GET /auth/v1.0 HTTP/1.1 > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 > Host: 192.168.3.52:8080 > Accept: */* > X-Storage-User: test:tester > X-Storage-Pass: testing > < HTTP/1.1 200 OK < X-Storage-Url: http://192.168.3.52:8080/v1/AUTH_test < X-Auth-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1 < Content-Type: text/html; charset=UTF-8 < X-Storage-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1 < Content-Length: 0 < Date: Wed, 20 Mar 2013 06:13:15 GMT < * Connection #0 to host 192.168.3.52 left intact * Closing connection #0 |
# curl -k -v -H 'X-Auth-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1' http://192.168.3.52:8080/v1/AUTH_test |
* About to connect() to 192.168.3.52 port 8080 (#0) * Trying 192.168.3.52... connected > GET /v1/AUTH_test HTTP/1.1 > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 > Host: 192.168.3.52:8080 > Accept: */* > X-Auth-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1 > < HTTP/1.1 204 No Content < Content-Length: 0 < Accept-Ranges: bytes < X-Timestamp: 1363760036.52552 < X-Account-Bytes-Used: 0 < X-Account-Container-Count: 0 < Content-Type: text/html; charset=UTF-8 < X-Account-Object-Count: 0 < Date: Wed, 20 Mar 2013 06:13:56 GMT < * Connection #0 to host 192.168.3.52 left intact * Closing connection #0 |
# curl -k -v -H 'X-Auth-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1' http://192.168.3.53:8080/v1/AUTH_test |
* About to connect() to 192.168.3.53 port 8080 (#0) * Trying 192.168.3.53... connected > GET /v1/AUTH_test HTTP/1.1 > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 > Host: 192.168.3.53:8080 > Accept: */* > X-Auth-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1 > < HTTP/1.1 204 No Content < Content-Length: 0 < Accept-Ranges: bytes < X-Timestamp: 1363760036.52552 < X-Account-Bytes-Used: 0 < X-Account-Container-Count: 0 < Content-Type: text/html; charset=UTF-8 < X-Account-Object-Count: 0 < Date: Wed, 20 Mar 2013 06:15:19 GMT < * Connection #0 to host 192.168.3.53 left intact * Closing connection #0 |
# curl -k -v -H 'X-Auth-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1' http://192.168.3.52:8080/v1/AUTH_test |
* About to connect() to 192.168.3.52 port 8080 (#0) * Trying 192.168.3.52... connected > GET /v1/AUTH_test HTTP/1.1 > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 > Host: 192.168.3.52:8080 > Accept: */* > X-Auth-Token: AUTH_tk440e9bd9a9cb46d6be07a5b6a585f7d1 > < HTTP/1.1 204 No Content < Content-Length: 0 < Accept-Ranges: bytes < X-Timestamp: 1363760036.52552 < X-Account-Bytes-Used: 0 < X-Account-Container-Count: 0 < Content-Type: text/html; charset=UTF-8 < X-Account-Object-Count: 0 < Date: Wed, 20 Mar 2013 06:17:01 GMT < * Connection #0 to host 192.168.3.52 left intact * Closing connection #0 |
# swift -A http://192.168.3.53:8080/auth/v1.0 -U test:tester -K testing stat |
Account: AUTH_test Containers: 0 Objects: 0 Bytes: 0 Accept-Ranges: bytes X-Timestamp: 1363760036.52552 Content-Type: text/plain; charset=utf-8 |
# swift -A http://192.168.3.52:8080/auth/v1.0 -U test:tester -K testing post myfiles |
|
# swift -A http://192.168.3.53:8080/auth/v1.0 -U test:tester -K testing list |
myfiles |
# swift -A http://192.168.3.52:8080/auth/v1.0 -U test:tester -K testing list |
myfiles |
# swift -A http://192.168.3.53:8080/auth/v1.0 -U test:tester -K testing upload myfiles ~/file |
root/file |
# swift -A http://192.168.3.52:8080/auth/v1.0 -U test:tester -K testing list myfiles |
root/file |