2、安装一些必需依赖项
主要是关于Python和git的,我用的是Ubuntu,所以一路apt-get~~~
apt-get update
apt-get install curl gcc memcached rsync sqlite3 xfsprogs git-core libffi-dev python-setuptools
apt-get install python-coverage python-dev python-nose python-simplejson python-xattr python-eventlet python-greenlet python-pastedeploy python-netifaces python-pip python-dnspython python-mock
3、这里是需要选择一种方式作为底层存储
一个是新建一个分区格式化为xfs文件系统,一个是创建一个回环设备,并格式化为xfs文件系统。这里我是选择的用回环设备来做文件系统。
这里的edit的话就用vi打开直接在里面添加一段代码。
创建分区
fdisk /dev/sdb
mkfs.xfs /dev/sdb1
编辑/etc/fstab这个文件
/dev/sdb1 /mnt/sdb1 xfs noatime,nodiratime,nobarrier,logbufs=8 0 0
穿件挂载点,挂载xfs文件系统,并创建一个目录
mkdir /mnt/sdb1
mount /mnt/sdb1
mkdir /mnt/sdb1/1 /mnt/sdb1/2 /mnt/sdb1/3 /mnt/sdb1/4
chown root:root /mnt/sdb1/*
mkdir /srv
for x in {1..4}; do ln -s /mnt/sdb1/$x /srv/$x; done
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 /var/run/swift
# **Make sure to include the trailing slash after /srv/$x/**
for x in {1..4}; do chown -R root:root /srv/$x/; done
4、安装swift
就是在git上面下载swift和python-swiftclient的代码,进行安装。
cd $HOME; git clone https://github.com/openstack/python-swiftclient.git
cd $HOME/python-swiftclient; sudo python setup.py develop; cd -
git clone https://github.com/openstack/swift.git
cd $HOME/swift; sudo python setup.py develop; cd -
pip install -r swift/test-requirements.txt
5、配置rsync
这个应该是一个镜像备份工具,swift对象的副本是基于推送模式来复制更新的,可以使用rsync将文件同步到对等节点,同时account和container的复制更新通过http或rsync来推送数据上丢失的记录。
这里将/etc/default/rsync的参数RSYNC_ENABLE设置为true,然后启动rsync服务。注意!这里的address是rsync服务器监听的ip地址,等待客户端推送复制更新,如果这里是多台服务器,这里监听的是对方的ip地址。
sudo cp $HOME/swift/doc/saio/rsyncd.conf /etc/
sudo sed -i "s//${USER}/" /etc/rsyncd.conf
结果如下:
uid =
gid =
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
6、启动高性能缓存
这里最好都需要开启一下这个进程,中间这里可能会缺少chkconfig,直接apt-get一个就可以了。
service memcached start
chkconfig memcached on
7、配置rsyslog,创建log和设置log目录owner和权限
这里swift默认将日志信息输出到文件/var/log/syslog中,这里可以个人设置一个rsyslog,可以把各个节点的日志文件分开。
cp /root/swift/doc/saio/rsyslog.d/10-swift.conf /etc/rsyslog.d/
可以打开配置文件看一下,这里的拆成一个log或者都合并起来,我保持的默认。
# 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.* ~
local6.*;local6.!notice /var/log/swift/expirer.log
local6.notice /var/log/swift/expirer.error
local6.* ~
8、配置每个节点
cd $HOME/swift/doc; sudo cp -r saio/swift /etc/swift; cd -
sudo chown -R ${USER}:${USER} /etc/swift
find /etc/swift/ -name \*.conf | xargs sudo sed -i "s//${USER}/"
这个时候可以到/etc/swift下去查看各个配置文件,进行需要的配置。
9、设置swift runnin script
拷贝脚本
cd $HOME/swift/doc; cp -r saio/bin $HOME/bin; cd -
chmod +x $HOME/bin/*
sed -i "s/dev\/sdb1/srv\/swift-disk/" $HOME/bin/resetswift
安装想跑的test的配置文件
cp $HOME/swift/test/sample.conf /etc/swift/test.conf
编辑.bashrc
echo "export SWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf" >> /root/.bashrc
echo "export PATH=${PATH}:/root/bin" >> /root/.bashrc
初始化swift rings
remakerings
启动swift daemon,其中包括proxy、account、container和object
startmain
获得
X-Storage-Url 和 X-Auth-Token,此处的用户名密码来自/etc/swift/test.conf这里的curl是一个工具,利用URL规则在命令行下工作的文件传输工具,auth-token是作为用户身份和权限的认证。
接下来就是几个test了
例如:
/root/swift/.functests
最后显示都是OK的~
安装结束以后,目录大概是这个样子的:
root@ubuntu5118:~# ls
bin python-swiftclient swift
root@ubuntu5118:~# tree -d //root目录下的文件树
.
|-- bin
|-- python-swiftclient
| |-- bin
| |-- doc
| | |-- manpages
| | `-- source
| | |-- _static
| | `-- _templates
| |-- pbr-0.8.2-py2.7.egg
| | |-- EGG-INFO
| | `-- pbr
| | |-- hooks
| | `-- tests
| | `-- testpackage
| | |-- data_files
| | |-- pbr_testpackage
| | | `-- package_data
| | `-- src
| |-- python_swiftclient.egg-info
| |-- swiftclient
| `-- tests
| |-- functional
| `-- unit
`-- swift
|-- bin
|-- doc
| |-- manpages
| |-- saio
| | |-- bin
| | |-- rsyslog.d
| | `-- swift
| | |-- account-server
| | |-- container-server
| | `-- object-server
| `-- source
| |-- _ga
| |-- _static
| `-- _theme
|-- etc
|-- examples
| |-- apache2
| `-- wsgi
|-- locale
|-- swift //swift有这3类存储服务器,其中container服务器负责处理object的列表,例如综述以及存了哪些object
| |-- account
| |-- cli
| |-- common
| | |-- middleware
| | | `-- x_profile
| | `-- ring
| |-- container
| |-- obj
| `-- proxy
| `-- controllers
|-- swift.egg-info
`-- test //这里有3个测试可以跑一下,注意unit test可能会报错,提示是权限问题,解决方法是在函数test_os_error里面,加入下两行:uid = os.geteuid() ,if uid == 0 : return(python代码哦~)
|-- functional
|-- probe
`-- unit
|-- account
|-- cli
|-- common
| |-- middleware
| `-- ring
|-- container
|-- obj
|-- proxy
| `-- controllers
`-- test_locale
`-- eo
`-- LC_MESSAGES
71 directories