分类: 云计算
2014-02-23 12:20:36
执行下列命令安装管理面板:
sudo apt-get install openstack-dashboard
重启Apache:
sudo service apache2 restart
好消息,现在打开浏览器输入server1的IP地址,就可以看到OpenStack的管理面板登陆界面了。默认用户名和密码都是“admin”。在管理面板中,可以进行创建密匙对,创建、编辑安全群组,新建实例,添加卷等操作。具体内容详见后文“OpenStack Dashboard”章节。
安装Swift
最重要的部分是swift的代理、账户、容器及对象服务器:
sudo apt-get install swift swift-proxy swift-account swift-container swift-object
随后安装一些支持组件,xfsprogs(支持XFS文件系统)、python.pastedeploy(访问keystone)和curl(测试swift):
sudo apt-get install xfsprogs curl python-pastedeploy
Swift存储端
有两种方法来创建或制备存储端,一种是采用现有的分区或卷作为存储设备,另一种是创建环回文件(Loopback file)并将当做存储设备。安装时,两种方式自选。
1. 分区作为存储设备
如果在安装OS时为Swift预留了一个分区,你就可以直接使用它。如果该分区没有使用过或仍是空闲空间(比如 /dev/sdb3),就应该把它格式化为xfs文件系统,接着编辑 /etc/fstab中该分区的挂载点(注意:请根据实际情况选择你自定的设备,本教程假定手头未使用也没分区的空闲空间在 /dev/sdb上):
sudo fdisk /dev/sdb
Type n for new partition
Type e for extended partion
Choose appropriate partition number ( or go with the default )
Choose first and last sectors to set the hard disk size (or go with defaults)
Note that 83 is the partition type number for Linux
Type w to write changes to the disk
上述命令将创建一个譬如 /dev/sdb3的分区,接着我们便将其格式化为XFS。记得格式化前要先使用命令“sudo fdisk -l”查看当前分区表,确定系统列出的分区含有你即将格式化的目标分区。最后,如果刚才xfsprogs成功安装的话,我们才能够使用以下命令:
partprobe
sudo mkfs.xfs -i size=1024 /dev/sdb3
sudo tune2fs -l /dev/sdb3 |grep -i inode
创建一个该分区的挂载点,并命名为“swift_backend”:
sudo mkdir /mnt/swift_backend
紧接着编辑 /etc/fstab文件写入如下内容以便系统启动时自动加载这个分区:
/dev/sdb3 /mnt/swift_backend xfs noatime,nodiratime,nobarrier,logbufs=8 0 0
2. 环回文件作为存储设备
创建一个空文件作为Swift存储的环回设备,在这里我们使用disk copy命令创建它并命名为swift-disk,还将为其分配1G的磁盘空间。如果空间不够,可以通过改变seek值来增加空间。随后格式化为XFS:
sudo dd if=/dev/zero of=/srv/swift-disk bs=1024 count=0 seek=1000000
sudo mkfs.xfs -i size=1024 /srv/swift-disk
file /srv/swift-disk
swift-disk1: SGI XFS filesystem data (blksz 4096, inosz 1024, v2 dirs.)
创建挂载点:
sudo mkdir /mnt/swift_backend
写入 /etc/fstab:
/srv/swift-disk /mnt/swift_backend xfs loop,noatime,nodiratime,nobarrier,logbufs=8 0 0
3. 使用存储 挂载存储分区前,需要创建一些设备节点并设置其属主和主群为“Swift”:
sudo mount /mnt/swift_backend
pushd /mnt/swift_backend
sudo mkdir node1 node2 node3 node4
popd
sudo chown swift.swift /mnt/swift_backend/*(确保相关目录和文件的owner和group均为swift)
for i in {1..4}; do sudo ln -s /mnt/swift_backend/node$i /srv/node$i; done;
sudo mkdir -p /etc/swift/account-server /etc/swift/container-server /etc/
swift/object-server /srv/node1/device /srv/node2/device /srv/node3/device /srv/node4/device
sudo mkdir /run/swift
sudo chown -L -R swift.swift /etc/swift /srv/node[1-4]/ /run/swift
为了在系统启动时启动Swift服务,需要把如下两行命令写入 /etc/rc.local里,位置在“exit 0;”之前:
sudo mkdir /run/swift
sudo chown swift.swift /run/swift
配置Swift组件
详细的配置选项参见。如果安装了swift-doc包的话,则可以在/usr/share/doc/swift-doc/html目录下直接查看。Python使用paste.deploy管理配置。默认配置选项在[DEFAULT]段中,后面配置其它特殊项会覆盖默认段中的相关内容。格式如下:
THE SYNTAX set option_name = value
以下是一份paste.deploy的配置样例,仅供参考:
[DEFAULT]
name1 = globalvalue
name2 = globalvalue
name3 = globalvalue
set name4 = globalvalue
[pipeline:main]
pipeline = myapp
[app:myapp]
use = egg:mypkg#myapp
name2 = localvalue
set name3 = localvalue
set name5 = localvalue
name6 = localvalue
创建并编辑 /etc/swift/swift.conf文件,并写入如下配置:
[swift-hash]
# random unique string that can never change (DO NOT LOSE). I'm using 03c9f48da2229770.
# od -t x8 -N 8 -A n < /dev/random
# The above command can be used to generate random a string.
swift_hash_path_suffix = 03c9f48da2229770
特别的,当建立更多的节点时,你需要记住随机串。不要照抄本例,请通过以下命令生成自己的随机字符串:
od -t x8 -N 8 -A n < /dev/random
1. 配置Swift代理服务器
代理服务器是swift的门卫,它的职责是检测合法性。它将审查:一、请求是否伪造,二、请求使用资源的用户身份。具体操作由keystone之类的认证服务器来协助完成。
创建并编辑 /etc/swift/proxy-server.conf并增加如下内容:
[DEFAULT]
bind_port = 8080
user = swift
swift_dir = /etc/swift
[pipeline:main]
# Order of execution of modules defined below
pipeline = catch_errors healthcheck cache authtoken keystone proxy-server
[app:proxy-server]
use = egg:swift#proxy
allow_account_management = true
account_autocreate = true
set log_name = swift-proxy
set log_facility = LOG_LOCAL0
set log_level = INFO
set access_log_name = swift-proxy
set access_log_facility = SYSLOG
set access_log_level = INFO
set log_headers = True
account_autocreate = True
[filter:healthcheck]
use = egg:swift#healthcheck
[filter:catch_errors]
use = egg:swift#catch_errors
[filter:cache]
use = egg:swift#memcache
set log_name = cache
[filter:authtoken]
paste.filter_factory = keystone.middleware.auth_token:filter_factory
auth_protocol = http
auth_host = 127.0.0.1
auth_port = 35357
auth_token = admin
service_protocol = http
service_host = 127.0.0.1
service_port = 5000
admin_token = admin
admin_tenant_name = service
admin_user = swift
admin_password = swift
delay_auth_decision = 0
[filter:keystone]
paste.filter_factory = keystone.middleware.swift_auth:filter_factory
operator_roles = admin, swiftoperator
is_admin = true
注意:可以使用apt-get安装swift-doc软件包,安装后许多文档都收录在/usr/share/doc/swift-doc/html下,本配置样例也是如此。
2. 配置Swift账户服务器 默认swift容器服务配置文件为 /etc/swift/account-server.conf:
[DEFAULT]
bind_ip = 0.0.0.0
workers = 2
[pipeline:main]
pipeline = account-server
[app:account-server]
use = egg:swift#account
[account-replicator]
[account-auditor]
[account-reaper]
所有的account server配置文件都在 /etc/swift/account-server目录中。与 /srv里的设备相对应,我们创建1.conf、2.conf等等文件,并将它们放到/etc/swift/account-server/下。以下是/etc/swift/account-server/1.conf配置文件的内容:
[DEFAULT]
devices = /srv/node1
mount_check = false
bind_port = 6012
user = swift
log_facility = LOG_LOCAL2
[pipeline:main]
pipeline = account-server
[app:account-server]
use = egg:swift#account
[account-replicator]
vm_test_mode = no
[account-auditor]
[account-reaper]
对其它设备也是如此,比如/srv/node2、/srv/node3、/srv/node4等,我们分别创建2.conf,3.conf和4.conf与之对应。现在利用1.conf进行复制生成其余文件,并一一设置唯一的绑定端口及本地日志值:
sudo cp /etc/swift/account-server/1.conf /etc/swift/account-server/2.conf
sudo cp /etc/swift/account-server/1.conf /etc/swift/account-server/3.conf
sudo cp /etc/swift/account-server/1.conf /etc/swift/account-server/4.conf
sudo sed -i 's/6012/6022/g;s/LOCAL2/LOCAL3/g;s/node1/node2/g' /etc/swift/account-server/2.conf
sudo sed -i 's/6012/6032/g;s/LOCAL2/LOCAL4/g;s/node1/node3/g' /etc/swift/account-server/3.conf
sudo sed -i 's/6012/6042/g;s/LOCAL2/LOCAL5/g;s/node1/node4/g' /etc/swift/account-server/4.conf
3. 配置Swift容器服务器 默认swift容器服务配置文件为 /etc/swift/container-server.conf:
[DEFAULT]
bind_ip = 0.0.0.0
workers = 2
[pipeline:main]
pipeline = container-server
[app:container-server]
use = egg:swift#container
[container-replicator]
[container-updater]
[container-auditor]
[container-sync]
与account-server类似,我们同样创建 /etc/swift/container-server/1.conf等等文件与 /srv设备匹配,这是1.conf文件内容:
[DEFAULT]
devices = /srv/node1
mount_check = false
bind_port = 6011
user = swift
log_facility = LOG_LOCAL2
[pipeline:main]
pipeline = container-server
[app:container-server]
use = egg:swift#container
[container-replicator]
vm_test_mode = no
[container-updater]
接着利用1.conf继续创建2.conf、3.conf和4.conf。并修改端口(分别是6021、6031和6041)及本地日志值(LOG_LOCAL3、LOG_LOCAL4和 LOG_LOCAL5)。
4. 配置Swift对象服务器 默认swift容器服务配置文件为 /etc/swift/object-server.conf:
[DEFAULT]
bind_ip = 0.0.0.0
workers = 2
[pipeline:main]
pipeline = object-server
[app:object-server]
use = egg:swift#object
[object-replicator]
[object-updater]
[object-auditor]
与account-server和container-server一样,我们同样创建 /etc/swift/object-server/1.conf等等文件与 /srv设备匹配,这是1.conf文件内容:
[DEFAULT]
devices = /srv/node1
mount_check = false
bind_port = 6010
user = swift
log_facility = LOG_LOCAL2
[pipeline:main]
pipeline = object-server
[app:object-server]
use = egg:swift#object
[object-replicator]
vm_test_mode = no
[object-updater]
[object-auditor]
继而利用1.conf继续创建2.conf、3.conf和4.conf。并修改端口(分别是6020、6030和6040)及本地日志值(LOG_LOCAL3、LOG_LOCAL4和 LOG_LOCAL5)。
5. 配置Swift Ring服务器 Ring是swift的一个极为重要的组件,它维护着对象的真实物理位置信息,对象的副本及多种设备。创建与对象服务、容器服务和账户服务相对应的ring-builder文件:
pushd /etc/swift
sudo swift-ring-builder object.builder create 18 3 1
sudo swift-ring-builder container.builder create 18 3 1
sudo swift-ring-builder account.builder create 18 3 1
注意:执行以上命令时需要在 /etc/swift目录下。
命令中的参数指定了分区、副本和小时的数量,用来限制分区多次移动。可以参考man页面中的swift-ring-builder获取更多信息。
现在添加区域以均衡ring服务。命令格式如下:
swift-ring-builder
执行下列命令:
sudo swift-ring-builder object.builder add z1-127.0.0.1:6010/device 1
sudo swift-ring-builder object.builder add z2-127.0.0.1:6020/device 1
sudo swift-ring-builder object.builder add z3-127.0.0.1:6030/device 1
sudo swift-ring-builder object.builder add z4-127.0.0.1:6040/device 1
sudo swift-ring-builder object.builder rebalance
sudo swift-ring-builder container.builder add z1-127.0.0.1:6011/device 1
sudo swift-ring-builder container.builder add z2-127.0.0.1:6021/device 1
sudo swift-ring-builder container.builder add z3-127.0.0.1:6031/device 1
sudo swift-ring-builder container.builder add z4-127.0.0.1:6041/device 1
sudo swift-ring-builder container.builder rebalance
sudo swift-ring-builder account.builder add z1-127.0.0.1:6012/device 1
sudo swift-ring-builder account.builder add z2-127.0.0.1:6022/device 1
sudo swift-ring-builder account.builder add z3-127.0.0.1:6032/device 1
sudo swift-ring-builder account.builder add z4-127.0.0.1:6042/device 1
sudo swift-ring-builder account.builder rebalance
启动Swift服务
使用以下命令启动swift和REST API:
sudo swift-init main start
sudo swift-init rest start
测试Swift
可以通过Swift命令或Horizon提供的Web管理面板测试Swift是否正确运行。
首先,将 /etc/swift目录的属主设为swift.swift:
sudo chown -R swift.swift /etc/swift
执行以下命令查看是否能得到正确的account、容器数量和存储的对象信息:
swift -v -V 2.0 -A
StorageURL:
Auth Token: ba9df200a92d4a5088dcd6b7dcc19c0d
Account: AUTH_c7970080576646c6959ee35970cf3199
Containers: 1
Objects: 1
Bytes: 77
Accept-Ranges: bytes
X-Trans-Id: tx11c64e218f984749bc3ec37ea46280ee
至此,终于安装完毕!