OpenStack Swift服务安装脚本

Controller

#!/bin/sh

install_swift(){
	set -o errexit
	set -x	
	readonly passwd=openstack
	readonly controller_ip=172.16.199.11
	readonly compute_ip=172.16.199.31	

	#服务证书和端点
	source ./admin-openrc
	#创建swift user
	openstack user create --domain default --password $passwd swift
	#siwft用户添加admin角色
	openstack role add --project service --user swift admin
	
	#创建swift服务
	openstack service create --name swift --description "OpenStack Object Storage" object-store
	#创建服务端点
	openstack endpoint create --region RegionOne object-store public http://controller:8080/v1/AUTH_%\(tenant_id\)s
	openstack endpoint create --region RegionOne object-store internal http://controller:8080/v1/AUTH_%\(tenant_id\)s 
	openstack endpoint create --region RegionOne object-store admin http://controller:8080/v1

	#安装swift
	(echo 'y')|apt-get install swift swift-proxy python-swiftclient python-keystonemiddleware python-memcache
	
	#创建swift配置目录
	mkdir /etc/swift
	mv proxy-server.conf /etc/swift
	
	#/etc/swift/swift.conf
	echo "[swift-hash]
	swift_hash_path_suffix = swift_shared_path
	swift_hash_path_prefix = swift_shared_path" >> /etc/swift/swift.conf
	sed -i 's/^[\t]*//g' /etc/swift/swift.conf
	
	chown -R swift. /etc/swift
	
	#create rings
	swift-ring-builder /etc/swift/account.builder create 12 2 1 
	swift-ring-builder /etc/swift/container.builder create 12 2 1 
	swift-ring-builder /etc/swift/object.builder create 12 2 1
	
	#添加存储节点
	swift-ring-builder /etc/swift/account.builder add r0z0-$controller_ip:6002/device0 100
	swift-ring-builder /etc/swift/container.builder add r0z0-$controller_ip:6001/device0 100 
	swift-ring-builder /etc/swift/object.builder add r0z0-$controller_ip:6000/device0 100

	swift-ring-builder /etc/swift/account.builder add r1z1-$compute_ip:6002/device1 100 
	swift-ring-builder /etc/swift/container.builder add r1z1-$compute_ip:6001/device1 100 
	swift-ring-builder /etc/swift/object.builder add r1z1-$compute_ip:6000/device1 100

	#平衡存储
	swift-ring-builder /etc/swift/account.builder rebalance
	swift-ring-builder /etc/swift/container.builder rebalance 
	swift-ring-builder /etc/swift/object.builder rebalance

	#更改权限
	chown swift. /etc/swift/*.gz
	#重启swift-proxy
	systemctl restart swift-proxy
	
	#控制节点安装swift
	#安装组件
	(echo 'y')|apt-get install swift swift-account swift-container swift-object xfsprogs
	#Using a loopback device for storage
	#创建文件
	truncate -s 1GB /srv/swift-disk
	#格式化文件
	mkfs.xfs /srv/swift-disk
	#创建device0目录
	mkdir -p /srv/node/device0
	#挂载/srv/swift-disk到device0
	mount -o noatime,nodiratime,nobarrier /srv/swift-disk /srv/node/device0
	#修改权限
	chown -R swift. /srv/node
	#设置开机挂载
	sed -i '$a\ /srv/swift-disk  /srv/node/device0  xfs  noatime,nodiratime,nobarrier 0 0' /etc/fstab
	
	#修改权限
	chown swift. /etc/swift/*.gz
	
	#/etc/swift/account-server.conf
	sed -i "2s/^bind_ip\s.*/bind_ip = 0.0.0.0/" /etc/swift/account-server.conf
	head -n 2 /etc/swift/account-server.conf | tail -n 1
	sed -i "3s/^bind_port\s.*/bind_port = 6002/" /etc/swift/account-server.conf
	head -n 3 /etc/swift/account-server.conf | tail -n 1 

	#/etc/swift/container-server.conf
	sed -i "2s/^bind_ip\s.*/bind_ip = 0.0.0.0/" /etc/swift/container-server.conf
	head -n 2 /etc/swift/container-server.conf | tail -n 1            
	sed -i "3s/^bind_port\s.*/bind_port = 6001/" /etc/swift/container-server.conf
	head -n 3 /etc/swift/container-server.conf | tail -n 1

	#/etc/swift/object-server.conf
	sed -i "2s/^bind_ip\s.*/bind_ip = 0.0.0.0/" /etc/swift/object-server.conf
	head -n 2 /etc/swift/object-server.conf | tail -n 1            
	sed -i "3s/^bind_port\s.*/bind_port = 6000/" /etc/swift/object-server.conf
	head -n 3 /etc/swift/object-server.conf | tail -n 1
	
	#/etc/rsyncd.conf
	mv rsyncd.conf /etc
	sed -i "7s/^address\s.*/address = $controller_ip/" /etc/rsyncd.conf
	head -n 7 /etc/rsyncd.conf | tail -n 1	

	#/etc/default/rsync	
	sed -i "8s/^RSYNC_ENABLE\s.*/RSYNC_ENABLE=true/" /etc/default/rsync
	head -n 8 /etc/default/rsync | tail -n 1

	#重启rsync并设置开机启动	
	systemctl restart rsync
	systemctl enable rsync

	for ringtype in account container object; do 
		systemctl start swift-$ringtype
	    	systemctl enable swift-$ringtype
	    	for service in replicator updater auditor; do
        		if [ $ringtype != 'account' ] || [ $service != 'updater' ]; then
            			systemctl start swift-$ringtype-$service
            			systemctl enable swift-$ringtype-$service
        		fi
    		done
	done	
}

install_swift

proxy-server.conf

# create new
[DEFAULT]
bind_ip = 0.0.0.0
bind_port = 8080
user = swift

[pipeline:main]
pipeline = catch_errors gatekeeper healthcheck proxy-logging cache container_sync bulk ratelimit authtoken keystoneauth container-quotas account-quotas slo dlo versioned_writes proxy-logging proxy-server

[app:proxy-server]
use = egg:swift#proxy
allow_account_management = true
account_autocreate = true

# Keystone auth info
[filter:authtoken]
paste.filter_factory = keystonemiddleware.auth_token:filter_factory
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = swift
password = openstack
delay_auth_decision = true

[filter:keystoneauth]
use = egg:swift#keystoneauth
operator_roles = admin,user

[filter:healthcheck]
use = egg:swift#healthcheck

[filter:cache]
use = egg:swift#memcache
memcache_servers = controller:11211

[filter:ratelimit]
use = egg:swift#ratelimit

[filter:domain_remap]
use = egg:swift#domain_remap

[filter:catch_errors]
use = egg:swift#catch_errors

[filter:cname_lookup]
use = egg:swift#cname_lookup

[filter:staticweb]
use = egg:swift#staticweb

[filter:tempurl]
use = egg:swift#tempurl

[filter:formpost]
use = egg:swift#formpost

[filter:name_check]
use = egg:swift#name_check

[filter:list-endpoints]
use = egg:swift#list_endpoints

[filter:proxy-logging]
use = egg:swift#proxy_logging

[filter:bulk]
use = egg:swift#bulk

[filter:slo]
use = egg:swift#slo

[filter:dlo]
use = egg:swift#dlo

[filter:container-quotas]
use = egg:swift#container_quotas

[filter:account-quotas]
use = egg:swift#account_quotas

[filter:gatekeeper]
use = egg:swift#gatekeeper

[filter:container_sync]
use = egg:swift#container_sync

[filter:xprofile]
use = egg:swift#xprofile

[filter:versioned_writes]
use = egg:swift#versioned_writes

rsyncd.conf

# create new
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
uid = swift
gid = swift
# IP address of this Node
address = 10.0.0.71

[account]
path            = /srv/node
read only       = false
write only      = no
list            = yes
incoming chmod  = 0644
outgoing chmod  = 0644
max connections = 25
lock file =     /var/lock/account.lock

[container]
path            = /srv/node
read only       = false
write only      = no
list            = yes
incoming chmod  = 0644
outgoing chmod  = 0644
max connections = 25
lock file =     /var/lock/container.lock

[object]
path            = /srv/node
read only       = false
write only      = no
list            = yes
incoming chmod  = 0644
outgoing chmod  = 0644
max connections = 25
lock file =     /var/lock/object.lock

[swift_server]
path            = /etc/swift
read only       = true
write only      = no
list            = yes
incoming chmod  = 0644
outgoing chmod  = 0644
max connections = 5
lock file =  	/var/lock/swift_server.lock

Compute

#!/bin/sh

install_swift(){
	set -o errexit
	set -x
	readonly controller_ip=172.16.199.11
	readonly compute_ip=172.16.199.31
	readonly controller_username=ubuntu
	readonly controller_passwd=ubuntu
	
	echo "----------安装和配置存储节点-------------"
	#安装组件
	(echo 'y')|apt-get install swift swift-account swift-container swift-object xfsprogs
	#Using a loopback device for storage
	#创建文件
	truncate -s 1GB /srv/swift-disk
	#格式化文件
	mkfs.xfs /srv/swift-disk
	#创建device1目录
	mkdir -p /srv/node/device1
	#挂载/srv/swift-disk到device1
	mount -o noatime,nodiratime,nobarrier /srv/swift-disk /srv/node/device1
	#修改权限
	chown -R swift. /srv/node
	#设置开机挂载
	sed -i '$a\ /srv/swift-disk  /srv/node/device1  xfs  noatime,nodiratime,nobarrier 0 0' /etc/fstab
	#从控制节点(swift-proxy)拷贝文件到计算节点
	scp $controller_username@$controller_ip:/etc/swift/*.gz /etc/swift/
	#修改权限
	chown swift. /etc/swift/*.gz

	#/etc/swift/swift.conf
	echo "[swift-hash]
	swift_hash_path_suffix = swift_shared_path
	swift_hash_path_prefix = swift_shared_path" >> /etc/swift/swift.conf
	sed -i 's/^[\t]*//g' /etc/swift/swift.conf		
	
	#/etc/swift/account-server.conf
	sed -i "2s/^bind_ip\s.*/bind_ip = 0.0.0.0/" /etc/swift/account-server.conf
	head -n 2 /etc/swift/account-server.conf | tail -n 1
	sed -i "3s/^bind_port\s.*/bind_port = 6002/" /etc/swift/account-server.conf
	head -n 3 /etc/swift/account-server.conf | tail -n 1 

	#/etc/swift/container-server.conf
	sed -i "2s/^bind_ip\s.*/bind_ip = 0.0.0.0/" /etc/swift/container-server.conf
	head -n 2 /etc/swift/container-server.conf | tail -n 1            
	sed -i "3s/^bind_port\s.*/bind_port = 6001/" /etc/swift/container-server.conf
	head -n 3 /etc/swift/container-server.conf | tail -n 1

	#/etc/swift/object-server.conf
	sed -i "2s/^bind_ip\s.*/bind_ip = 0.0.0.0/" /etc/swift/object-server.conf
	head -n 2 /etc/swift/object-server.conf | tail -n 1            
	sed -i "3s/^bind_port\s.*/bind_port = 6000/" /etc/swift/object-server.conf
	head -n 3 /etc/swift/object-server.conf | tail -n 1
	
	#/etc/rsyncd.conf
	mv rsyncd.conf /etc
	sed -i "7s/^address\s.*/address = $compute_ip/" /etc/rsyncd.conf
	head -n 7 /etc/rsyncd.conf | tail -n 1	

	#/etc/default/rsync	
	sed -i "8s/^RSYNC_ENABLE\s.*/RSYNC_ENABLE=true/" /etc/default/rsync
	head -n 8 /etc/default/rsync | tail -n 1

	#重启rsync并设置开机启动	
	systemctl restart rsync
	systemctl enable rsync

	for ringtype in account container object; do 
		systemctl start swift-$ringtype
		systemctl enable swift-$ringtype
		for service in replicator updater auditor; do
        		if [ $ringtype != 'account' ] || [ $service != 'updater' ]; then
            		systemctl start swift-$ringtype-$service
            		systemctl enable swift-$ringtype-$service
        		fi
		done
	done
}

install_swift

rsyncd.conf

# create new
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
uid = swift
gid = swift
# IP address of this Node
address = 10.0.0.71

[account]
path            = /srv/node
read only       = false
write only      = no
list            = yes
incoming chmod  = 0644
outgoing chmod  = 0644
max connections = 25
lock file =     /var/lock/account.lock

[container]
path            = /srv/node
read only       = false
write only      = no
list            = yes
incoming chmod  = 0644
outgoing chmod  = 0644
max connections = 25
lock file =     /var/lock/container.lock

[object]
path            = /srv/node
read only       = false
write only      = no
list            = yes
incoming chmod  = 0644
outgoing chmod  = 0644
max connections = 25
lock file =     /var/lock/object.lock

[swift_server]
path            = /etc/swift
read only       = true
write only      = no
list            = yes
incoming chmod  = 0644
outgoing chmod  = 0644
max connections = 5
lock file =  	/var/lock/swift_server.lock

参考

Object Storage Install Guide

你可能感兴趣的:(OpenStack)