阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Ubuntu下Swift单节点安装测试小结

101次阅读
没有评论

共计 21561 个字符,预计需要花费 54 分钟才能阅读完成。

1      环境准备
1.1        版本
Linux 系统版本:Ubuntu Server 12.04.1 LTS;

Swift 版本:1.0(稍后安装);

Python 版本:2.7.3(稍后安装);

Python-swiftclient 版本:1.3.0(稍后安装)。

Ubuntu 下 Swift 多节点安装测试小结  http://www.linuxidc.com/Linux/2014-02/97347.htm

1.2        节点 IP
IP:192.168.1.107。

1.3        替换镜像(可选步骤)
网速较慢或者安装软件失败的情况下,可以考虑替换成国内的镜像:

vsroot@ubuntu:~$ sudo sed -i’s#us.archive.ubuntu.com#mirrors.163.com#g’ /etc/apt/sources.list

vsroot@ubuntu:~$ sudo apt-get update

1.4        系统时间
vsroot@ubuntu:~$ date #查看系统时间是否正确,正确的话则忽略下面两步

vsroot@ubuntu:~$ sudo date -s”2013-11-04 15:05:57″ #设置系统时间

vsroot@ubuntu:~$ sudo hwclock –w #写入硬件时间

1.5        关闭防火墙
请确保已关闭 SELinux。

vsroot@ubuntu:~$ sudo ufw disable #关闭防火墙

2      通用的 OS 配置
2.1        创建 Swift 用户
vsroot@ubuntu:~$ sudo useradd -mk/home/swift -s /bin/bash swift

vsroot@ubuntu:~$ sudo passwd swift # 不妨把用户 swift 的密码设置成 swift

编辑 /etc/sudoers,在文件末尾添加以下内容:

vsroot@ubuntu:~$ sudo vim /etc/sudoers

# User alias specification

swift  ALL=(ALL) NOPASSWD:ALL

之后就可以切换到 swift 用户进行后续操作了:

vsroot@ubuntu:~$ su swift

2.2        安装 Swift 依赖库
swift@ubuntu:~$ sudo apt-get install curlgcc memcached rsync sqlite3 xfsprogs git-core libffi-dev python-setuptools

swift@ubuntu:~$ sudo apt-get installpython-coverage python-dev python-nose python-simplejson python-xattrpython-eventlet python-greenlet python-pastedeploy python-netifaces python-pippython-dnspython python-mock

2.3        安装 Swift 相关软件
swift@ubuntu:~$ sudo add-apt-repositorycloud-archive:grizzly

swift@ubuntu:~$ sudo apt-get update

swift@ubuntu:~$ sudo apt-get install swiftpython-swiftclient openssh-server

2.4        创建 Swift 工作目录
swift@ubuntu:~$ sudo mkdir -p /etc/swift

swift@ubuntu:~$ sudo chown -R swift:swift/etc/swift/

2.5        创建 Swift 配置文件
swift@ubuntu:~$ cat>/etc/swift/swift.conf <<EOF

[swift-hash]

# random unique strings that can neverchange (DO NOT LOSE)

swift_hash_path_prefix = `od -t x8 -N 8 -An </dev/random`

swift_hash_path_suffix = `od -t x8 -N 8 -An </dev/random`

EOF

2.6        设置 IP 的环境变量
根据自身真实 IP 设置如下:

swift@ubuntu:~$ export LOCAL_NET_IP=192.168.1.107

考虑到 export 命令只对当前用户的当前会话生效,也可以考虑将环境变量写到 /etc/profile 中:

swift@ubuntu:~$ sudo vim /etc/profile

swift@ubuntu:~$ source /etc/profile #当前会话立即生效

2.7        创建 Swift 服务目录并修改开机配置文件
swift@ubuntu:~$ sudo mkdir -p/var/cache/swift /var/cache/swift2 /var/cache/swift3 /var/cache/swift4

swift@ubuntu:~$ sudo chown swift:swift/var/cache/swift*

swift@ubuntu:~$ sudo mkdir -p/var/run/swift

swift@ubuntu:~$ sudo chown swift:swift/var/run/swift

swift@ubuntu:~$ sudo vim /etc/rc.local

sudo mkdir -p /var/cache/swift/var/cache/swift2 /var/cache/swift3 /var/cache/swift4

sudo chown swift:swift /var/cache/swift*

sudo mkdir -p /var/run/swift

sudo chown swift:swift /var/run/swift

exit 0

3      配置 Proxy 服务
3.1        安装 swift-proxy 库
swift@ubuntu:~$ sudo apt-get installswift-proxy memcached

3.2        配置 memcached 并监听默认的端口
swift@ubuntu:~$ sudo perl -pi -e “s/-l127.0.0.1 /-l $LOCAL_NET_IP/” /etc/memcached.conf # 替换成自己的 IP

3.3        重启 memcached 服务器
swift@ubuntu: ~$ sudo service memcachedrestart

最好检查一下 memcached 服务是否已经正常启动。

3.4        创建 Proxy 服务器配置文件
swift@ubuntu:~$ cat>/etc/swift/proxy-server.conf <<EOF

[DEFAULT]

bind_port = 8080

workers = 1

user = swift

log_facility = LOG_LOCAL1

eventlet_debug = true

 

[pipeline:main]

# Yes, proxy-logging appears twice. This isnot a mistake.

pipeline = healthcheck proxy-logging cachetempauth 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

memcache_servers = $LOCAL_NET_IP:11211

 

[filter:proxy-logging]

use = egg:swift#proxy_logging

EOF

3.5        确保所有配置文件都属于 swift 用户
swift@ubuntu:~$ sudo chown -R swift:swift/etc/swift

Ubuntu Server 11.10 下使用 Swauth 认证多节点安装 Swift http://www.linuxidc.com/Linux/2012-04/58100.htm

4      配置 Storage 服务
4.1        安装包
swift@Ubuntu:~$ sudo apt-get installswift-account swift-container swift-object xfsprogs

4.2        为 StorageNode 的每个存储设备安装 XFS 逻辑卷
swift@ubuntu:~$ sudo fdisk /dev/sdb # 建立单独分区

swift@ubuntu:~$ sudo mkfs.xfs /dev/sdb1

如果文件系统小于 100MiB 或有大量小型档案,建议使用 512 字节区块;其余情况建议使用 4KiB 区块。

swift@ubuntu:~$ sudo vim /etc/fstab

/dev/sdb1 /mnt/sdb1 xfsnoatime,nodiratime,nobarrier,logbufs=8 0 0

swift@ubuntu:~$ sudo mkdir -p /mnt/sdb1

swift@ubuntu:~$ sudo mount /mount/sdb1

如果磁盘大于 1T,上面的 mount 命令可以加上 -o inode64 以达到更好的性能。

swift@ubuntu:~$ sudo mkdir -p /mnt/sdb1/1/mnt/sdb1/2 /mnt/sdb1/3 /mnt/sdb1/4

swift@ubuntu:~$ sudo chown swift:swift /mnt/sdb1/*

swift@ubuntu:~$ sudo mkdir -p /srv

swift@ubuntu:~$ for x in {1..4}; do ln -s/mnt/sdb1/$x /srv/$x; done

swift@ubuntu:~$ sudo 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

swift@ubuntu:~$ sudo chown -R swift:swift /etc/swift /srv/[1-4]//var/run/swift

4.3        创建 rsync 配置文件
swift@ubuntu:~$ sudo su #切换用户后,需重新定义 LOCAL_NET_IP

root@ubuntu:~$ cat >/etc/rsyncd.conf<<EOF

uid = swift

gid = swift

log file = /var/log/rsyncd.log

pid file = /var/run/rsyncd.pid

address = $LOCAL_NET_IP

 

[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

EOF

root@ubuntu:~$ su swift #切换用户后,需重新定义 LOCAL_NET_IP

4.4        修改 rsync 标签
swift@ubuntu:~$ sudo perl -pi -e’s/RSYNC_ENABLE=false/RSYNC_ENABLE=true/’ /etc/default/rsync

4.5        启动 rsync 服务
swift@ubuntu:~$ sudo service rsync restart

如果服务不能正常启动,请检查 rsync 配置文件。

确认 rsync 是否已连接所有服务:

swift@ubuntu:~$ rsync rsync://pub@$LOCAL_NET_IP/

4.6        创建 account、container 和 object rings 配置文件
swift@ubuntu:~$ cat >/etc/swift/account-server/1.conf <<EOF

[DEFAULT]

devices = /srv/1/node

mount_check = false

disable_fallocate = true

bind_port = 6012

workers = 1

user = swift

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]

EOF

swift@ubuntu:~$ cat > /etc/swift/account-server/2.conf<<EOF

[DEFAULT]

devices = /srv/2/node

mount_check = false

disable_fallocate = true

bind_port = 6022

workers = 1

user = swift

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]

EOF

swift@ubuntu:~$ cat > /etc/swift/account-server/3.conf<<EOF

[DEFAULT]

devices = /srv/3/node

mount_check = false

disable_fallocate = true

bind_port = 6032

workers = 1

user = swift

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]

EOF

swift@ubuntu:~$ cat > /etc/swift/account-server/4.conf<<EOF

[DEFAULT]

devices = /srv/4/node

mount_check = false

disable_fallocate = true

bind_port = 6042

workers = 1

user = swift

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]

EOF

swift@ubuntu:~$ cat >/etc/swift/container-server/1.conf <<EOF

[DEFAULT]

devices = /srv/1/node

mount_check = false

disable_fallocate = true

bind_port = 6011

workers = 1

user = swift

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]

EOF

swift@ubuntu:~$ cat > /etc/swift/container-server/2.conf<<EOF

[DEFAULT]

devices = /srv/2/node

mount_check = false

disable_fallocate = true

bind_port = 6021

workers = 1

user = swift

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]

EOF

swift@ubuntu:~$ cat > /etc/swift/container-server/3.conf<<EOF

[DEFAULT]

devices = /srv/3/node

mount_check = false

disable_fallocate = true

bind_port = 6031

workers = 1

user = swift

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]

EOF

swift@ubuntu:~$ cat > /etc/swift/container-server/4.conf<<EOF

[DEFAULT]

devices = /srv/4/node

mount_check = false

disable_fallocate = true

bind_port = 6041

workers = 1

user = swift

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]

EOF

swift@ubuntu:~$ cat >/etc/swift/object-server/1.conf <<EOF

[DEFAULT]

devices = /srv/1/node

mount_check = false

disable_fallocate = true

bind_port = 6010

workers = 1

user = swift

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]

EOF

swift@ubuntu:~$ cat > /etc/swift/object-server/2.conf<<EOF

[DEFAULT]

devices = /srv/2/node

mount_check = false

disable_fallocate = true

bind_port = 6020

workers = 1

user = swift

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]

EOF

swift@ubuntu:~$ cat >/etc/swift/object-server/3.conf <<EOF

[DEFAULT]

devices = /srv/3/node

mount_check = false

disable_fallocate = true

bind_port = 6030

workers = 1

user = swift

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]

EOF

swift@ubuntu:~$ cat >/etc/swift/object-server/4.conf <<EOF

[DEFAULT]

devices = /srv/4/node

mount_check = false

disable_fallocate = true

bind_port = 6040

workers = 1

user = swift

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]

EOF

5      配置打印信息(可选步骤)
5.1        创建配置文件
swift@ubuntu:~$ cat >/etc/rsyslog.d/10-swift.conf <<EOF

# Uncomment the following to have a logcontaining all logs together

#local1,local2,local3,local4,local5.*  /var/log/swift/all.log

 

# Uncomment the following to have hourlyproxy 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.*                ~

EOF

5.2        修改配置文件
swift@ubuntu:~$ sudo perl -pi -e ‘s/$PrivDropToGroupsyslog/$PrivDropToGroup adm/’ /etc/rsyslog.conf

swift@ubuntu:~$ mkdir -p/var/log/swift/hourly

swift@ubuntu:~$ sudo chown -R syslog.adm/var/log/swift

swift@ubuntu:~$ sudo chmod -R g+w/var/log/swift

5.3        启动日志服务
swift@ubuntu:~$ sudo service rsyslogrestart

6      启动 Swift 服务
6.1        创建 resetswift
swift@ubuntu:~$ sudo su

root@ubuntu:~$ mkdir -p ~/bin

root@ubuntu:~$ cat > ~/bin/resetswift <<EOF

#!/bin/bash

swift-init all stop

find /var/log/swift -type f -exec rm -f {}\;

sudo umount /mnt/sdb1

sudo mkfs.xfs -f /dev/sdb1

sudo mount /mnt/sdb1

sudo mkdir /mnt/sdb1/1 /mnt/sdb1/2/mnt/sdb1/3 /mnt/sdb1/4

sudo chown swift:swift /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

EOF

6.2        创建 remakerings
root@ubuntu:~$ cat> ~/bin/remakerings <<EOF

#!/bin/bash

 

cd /etc/swift

 

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

 

swift-ring-builder object.builder create 103 1

swift-ring-builder object.builder add r1z1-$LOCAL_NET_IP:6010/sdb11

swift-ring-builder object.builder add r1z2-$LOCAL_NET_IP:6020/sdb21

swift-ring-builder object.builder add r1z3-$LOCAL_NET_IP:6030/sdb31

swift-ring-builder object.builder add r1z4-$LOCAL_NET_IP:6040/sdb41

swift-ring-builder object.builder rebalance

swift-ring-builder container.builder create10 3 1

swift-ring-builder container.builder add r1z1-$LOCAL_NET_IP:6011/sdb11

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

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

swift-ring-builder container.builder addr1z4-$LOCAL_NET_IP:6041/sdb4 1

swift-ring-builder container.builderrebalance

swift-ring-builder account.builder create10 3 1

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

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

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

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

swift-ring-builder account.builderrebalance

EOF

其中,10 代表 partition 的数目为 2 的 10 次幂,这个数字取决于你希望一个 ring 中会有多少个 partition。3 代表每个 object 的副本数。最后一个参数 1,代表一个 partition 至少在 1 小时之后才能被移动。

注意,这里需要根据存储设备实际情况来设定:

① DEVICE 需要根据 Storage Node 上的 /etc/rsyncd.conf 中的 path 来设置,例如 path 为 /srv/1/node/,查看 /srv/1/node/ 下存在目录 sdb1 上的话,则 DEVICE 值为 sdb1;

② ZONE 从 1 开始计数,逐次加 1;当一个 Storage Node 存在多个 DEVICE 时,可以设为同一个 ZONE(推荐),也可以设为多个 ZONE;

③ 如果每个挂载分区的大小都一样,WEIGHT(权重)不妨均设置成 100。

6.3        创建 startmain 和 startrest
root@ubuntu:~$ cat > ~/bin/startmain<<EOF

#!/bin/bash

 

swift-init main start

EOF

swift@ubuntu:~$ cat > ~/bin/startrest<<EOF

#!/bin/bash

 

swift-init rest start

EOF

root@ubuntu:~$ chmod +x ~/bin/*

root@ubuntu:~$ vim ~/.bashrc # 添加在最后

exportSWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf

export PATH=${PATH}:~/bin

root@ubuntu:~$ . ~/.bashrc

6.4        启动 Swift 服务
root@ubuntu:~$ remakerings

root@ubuntu:~$ startmain

7      HTTP 测试
7.1        获得 X -Storage-Url 和 X -Auth-Token
root@ubuntu:~$ curl -v -H ‘X-Storage-User: test:tester’ -H ‘X-Storage-Pass: testing’ http://$LOCAL_NET_IP:8080/auth/v1.0

7.2        检测是否可以使用 HEAD 命令查询 account 状态
命令格式如下:

curl -k -v -H ‘X-Auth-Token:<token-from-x-auth-token-above>’ <url-from-x-storage-url-above>

具体示例如下:

curl -k -v -H ‘X-Auth-Token: AUTH_tk9e8c4b51a25a4e0d96d88b5478633151’ http://$LOCAL_NET_IP:8080/v1/AUTH_test

7.3        检测 swift 命令是否工作正常
swift@ubuntu:~$ swift -A http://$LOCAL_NET_IP:8080/auth/v1.0 -U test:tester -K testing stat

预期输出应为 zerocontainers、zero objects 和 zero bytes。

7.4        Swift 常用命令
swift@ubuntu:~$ swift -A http://$LOCAL_NET_IP:8080/auth/v1.0 -U test:tester -K testing list #列出根目录的细节

swift@ubuntu:~$ swift -A http://$LOCAL_NET_IP:8080/auth/v1.0 -U test:tester -K testing list subfolder1 #列出一级子目录 subfolder1 的细节

swift@ubuntu:~$ swift -A http://$LOCAL_NET_IP:8080/auth/v1.0 -U test:tester -K testing upload subfolder1 /etc/swift/*.builder #把本地指定文件上传到一级子目录 subfolder1 中

swift@ubuntu:~$ swift -A http://$LOCAL_NET_IP:8080/auth/v1.0 -U test:tester -K testing delete subfolder1 etc/swift/account.builder #删除一级子目录 subfolder1 下的某个指定文件

swift@ubuntu:~$ sudo swift -A http://$LOCAL_NET_IP:8080/auth/v1.0 -U test:tester -K testing download subfolder1 #把一级子目录 subfolder1 中的资源都下载到本地当前目录

8      FTP 测试
8.1        下载并安装 ftp-cloudfs
方法一:

swift@ubuntu:~$ git clone https://github.com/cloudfs/ftp-cloudfs.git

swift@ubuntu:~$ cd ftp-cloudfs/

swift@ubuntu:~$ Python setup.py install

swift@ubuntu:~$ sudo apt-get installpython-pip

swift@ubuntu:~$ pip install ftp-cloudfs

方法二:

swift@ubuntu:~$ sudo apt-get installpython-virtualenv

swift@ubuntu:~$ virtualenv ENV

swift@ubuntu:~$ source ENV/bin/activate

swift@ubuntu:~$ sudo apt-get installpython-pip

swift@ubuntu:~$ pip install –upgrade pip

swift@ubuntu:~$ pip install ftp-cloudfs

8.2        启动 ftp-cloudfs 服务
单用户情况下,可以使用如下命令启动 ftp-cloudfs 服务:

swift@ubuntu:~$ ftpcloudfs -b $LOCAL_NET_IP -a http://$LOCAL_NET_IP:8080/auth/v1.0 -f

多用户情况下,推荐使用如下命令启动 ftp-cloudfs 服务,性能会相对好些:

swift@ubuntu:~$ ftpcloudfs -b $LOCAL_NET_IP -a http://$LOCAL_NET_IP:8080/auth/v1.0 –memcache=$LOCAL_NET_IP:11211 –log-file /tmp/ftpcloufs.log

这里使用了 memcache 作为共享缓存。此外,我们把 FTP 相关的 log 输出到 /tmp/ftpcloufs.log 中便于查看。如果作为产品发布,建议还是使用 –syslog。

如果要停止 ftp-cloudfs 服务,可以使用这条命令:

swift@ubuntu:~$ kill `cat/tmp/ftpcloudfs.pid`

8.3        Windows 客户端 FTP 访问
可以在 Windows 客户端安装 FTP 工具(例如 FileZilla),或者直接通过 IE 浏览器简单访问 ftp://192.168.1.107:2021。

主机:192.168.1.107

用户名:test:tester

密码:testing

端口:2021

预期可以访问成功,并能够正常地上传、下载、新建、删除、重命名文件和目录等。

8.4        Linux 客户端 FTP 访问
swift@ubuntu:~$ftp 192.168.1.107 2021

然后输入用户名密码,就可以访问成功并正常使用了。

常用的几个 FTP 命令如下:

cd remote-dir:进入远程主机目录。
ls [remote-dir] [local-file]:显示远程目录 remote-dir,并存入本地文件 local-file(和 dir 命令相同)。
mkdir dir-name:在远程主机中建一目录。
rmdir dir-name:删除远程主机目录。
rename [from] [to]:更改远程主机文件名。
delete remote-file:删除远程主机文件。
mdelete [remote-file]:删除远程主机文件。
get remote-file [local-file]:将远程主机文件 remote-file 传至本地文件 local-file。
mget remote-files:传输多个远程文件。
put local-file [remote-file]:将本地文件 local-file 传送至远程主机。
mput local-file:将多个文件传输至远程主机。
pwd:显示远程主机的当前工作目录。
bye:退出 ftp 会话过程(和 quit 命令相同)。

1      环境准备
1.1        版本
Linux 系统版本:Ubuntu Server 12.04.1 LTS;

Swift 版本:1.0(稍后安装);

Python 版本:2.7.3(稍后安装);

Python-swiftclient 版本:1.3.0(稍后安装)。

Ubuntu 下 Swift 多节点安装测试小结  http://www.linuxidc.com/Linux/2014-02/97347.htm

1.2        节点 IP
IP:192.168.1.107。

1.3        替换镜像(可选步骤)
网速较慢或者安装软件失败的情况下,可以考虑替换成国内的镜像:

vsroot@ubuntu:~$ sudo sed -i’s#us.archive.ubuntu.com#mirrors.163.com#g’ /etc/apt/sources.list

vsroot@ubuntu:~$ sudo apt-get update

1.4        系统时间
vsroot@ubuntu:~$ date #查看系统时间是否正确,正确的话则忽略下面两步

vsroot@ubuntu:~$ sudo date -s”2013-11-04 15:05:57″ #设置系统时间

vsroot@ubuntu:~$ sudo hwclock –w #写入硬件时间

1.5        关闭防火墙
请确保已关闭 SELinux。

vsroot@ubuntu:~$ sudo ufw disable #关闭防火墙

2      通用的 OS 配置
2.1        创建 Swift 用户
vsroot@ubuntu:~$ sudo useradd -mk/home/swift -s /bin/bash swift

vsroot@ubuntu:~$ sudo passwd swift # 不妨把用户 swift 的密码设置成 swift

编辑 /etc/sudoers,在文件末尾添加以下内容:

vsroot@ubuntu:~$ sudo vim /etc/sudoers

# User alias specification

swift  ALL=(ALL) NOPASSWD:ALL

之后就可以切换到 swift 用户进行后续操作了:

vsroot@ubuntu:~$ su swift

2.2        安装 Swift 依赖库
swift@ubuntu:~$ sudo apt-get install curlgcc memcached rsync sqlite3 xfsprogs git-core libffi-dev python-setuptools

swift@ubuntu:~$ sudo apt-get installpython-coverage python-dev python-nose python-simplejson python-xattrpython-eventlet python-greenlet python-pastedeploy python-netifaces python-pippython-dnspython python-mock

2.3        安装 Swift 相关软件
swift@ubuntu:~$ sudo add-apt-repositorycloud-archive:grizzly

swift@ubuntu:~$ sudo apt-get update

swift@ubuntu:~$ sudo apt-get install swiftpython-swiftclient openssh-server

2.4        创建 Swift 工作目录
swift@ubuntu:~$ sudo mkdir -p /etc/swift

swift@ubuntu:~$ sudo chown -R swift:swift/etc/swift/

2.5        创建 Swift 配置文件
swift@ubuntu:~$ cat>/etc/swift/swift.conf <<EOF

[swift-hash]

# random unique strings that can neverchange (DO NOT LOSE)

swift_hash_path_prefix = `od -t x8 -N 8 -An </dev/random`

swift_hash_path_suffix = `od -t x8 -N 8 -An </dev/random`

EOF

2.6        设置 IP 的环境变量
根据自身真实 IP 设置如下:

swift@ubuntu:~$ export LOCAL_NET_IP=192.168.1.107

考虑到 export 命令只对当前用户的当前会话生效,也可以考虑将环境变量写到 /etc/profile 中:

swift@ubuntu:~$ sudo vim /etc/profile

swift@ubuntu:~$ source /etc/profile #当前会话立即生效

2.7        创建 Swift 服务目录并修改开机配置文件
swift@ubuntu:~$ sudo mkdir -p/var/cache/swift /var/cache/swift2 /var/cache/swift3 /var/cache/swift4

swift@ubuntu:~$ sudo chown swift:swift/var/cache/swift*

swift@ubuntu:~$ sudo mkdir -p/var/run/swift

swift@ubuntu:~$ sudo chown swift:swift/var/run/swift

swift@ubuntu:~$ sudo vim /etc/rc.local

sudo mkdir -p /var/cache/swift/var/cache/swift2 /var/cache/swift3 /var/cache/swift4

sudo chown swift:swift /var/cache/swift*

sudo mkdir -p /var/run/swift

sudo chown swift:swift /var/run/swift

exit 0

3      配置 Proxy 服务
3.1        安装 swift-proxy 库
swift@ubuntu:~$ sudo apt-get installswift-proxy memcached

3.2        配置 memcached 并监听默认的端口
swift@ubuntu:~$ sudo perl -pi -e “s/-l127.0.0.1 /-l $LOCAL_NET_IP/” /etc/memcached.conf # 替换成自己的 IP

3.3        重启 memcached 服务器
swift@ubuntu: ~$ sudo service memcachedrestart

最好检查一下 memcached 服务是否已经正常启动。

3.4        创建 Proxy 服务器配置文件
swift@ubuntu:~$ cat>/etc/swift/proxy-server.conf <<EOF

[DEFAULT]

bind_port = 8080

workers = 1

user = swift

log_facility = LOG_LOCAL1

eventlet_debug = true

 

[pipeline:main]

# Yes, proxy-logging appears twice. This isnot a mistake.

pipeline = healthcheck proxy-logging cachetempauth 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

memcache_servers = $LOCAL_NET_IP:11211

 

[filter:proxy-logging]

use = egg:swift#proxy_logging

EOF

3.5        确保所有配置文件都属于 swift 用户
swift@ubuntu:~$ sudo chown -R swift:swift/etc/swift

Ubuntu Server 11.10 下使用 Swauth 认证多节点安装 Swift http://www.linuxidc.com/Linux/2012-04/58100.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计21561字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中