目標(biāo)
緊接著《Ubuntu16手動(dòng)安裝OpenStack——cinder篇》,本文汗贫,我們來研究一下swift的安裝配置。主要參考OpenStack Queens : Configure Swift 和 Object Storage Install Guide浇衬。
cinder和swift都是關(guān)于存儲(chǔ)的組件漩怎,那么它們有什么區(qū)別呢?
cinder的存儲(chǔ)侨赡,就像是普通硬盤蓖租。可以方便快捷地本地存取修改數(shù)據(jù)辆毡,還可以按需添加減少硬盤菜秦。
swift的存儲(chǔ)甜害,就像是百度云盤舶掖。只能存取數(shù)據(jù),不能在云端進(jìn)行修改尔店,適用于備份眨攘。如果非要修改,那么需要下載到本地修改嚣州,修改完再上傳鲫售。在openstack實(shí)際應(yīng)用中,swift常用來存儲(chǔ)鏡像這種不需要經(jīng)常修改的文件该肴。
swift簡(jiǎn)介
OpenStack Object Storage 是一個(gè)多租戶對(duì)象存儲(chǔ)系統(tǒng)情竹。它具有高度可擴(kuò)展性,可以通過RESTful HTTP API以低成本管理大量非結(jié)構(gòu)化數(shù)據(jù)匀哄。
代理服務(wù)器(swift-proxy-server)
接受OpenStack Object Storage API和原始HTTP請(qǐng)求秦效,上傳文件,修改元數(shù)據(jù)和創(chuàng)建容器涎嚼。它還為Web瀏覽器提供文件或容器列表阱州。為了提高性能,代理服務(wù)器可以使用通常使用memcache部署的可選緩存法梯。
帳戶服務(wù)器(swift-account-server)
管理使用對(duì)象存儲(chǔ)定義的帳戶苔货。
容器服務(wù)器(swift-container-server)
在對(duì)象存儲(chǔ)中管理容器或文件夾的映射。
對(duì)象服務(wù)器(swift-object-server)
管理存儲(chǔ)節(jié)點(diǎn)上的實(shí)際對(duì)象,例如文件夜惭。
Various periodic processes
在大型數(shù)據(jù)存儲(chǔ)上執(zhí)行內(nèi)務(wù)處理任務(wù)姻灶。復(fù)制服務(wù)可確保群集的一致性和可用性。其他定期流程包括審計(jì)員诈茧,更新者和收割者木蹬。
WSGI中間件
處理身份驗(yàn)證,通常是OpenStack Identity若皱。
swift client
允許用戶通過命令行客戶端進(jìn)行授權(quán)镊叁,然后為admin用戶、經(jīng)銷商用戶或swift用戶向REST API提交命令走触。
swift-init
初始化環(huán)文件構(gòu)建的腳本晦譬,將守護(hù)程序名稱作為參數(shù)并提供命令。詳細(xì)文檔在這里互广。
swift-recon
一種客戶端工具敛腌,用于檢索由swift-recon中間件收集的有關(guān)群集的各種指標(biāo)和遙測(cè)信息。
swift-ring-builder
存儲(chǔ)環(huán)構(gòu)建和重新平衡實(shí)用程序惫皱。詳細(xì)文檔在這里像樊。
架構(gòu)
一般來說,swift至少需要三個(gè)存儲(chǔ)節(jié)點(diǎn)旅敷,如下結(jié)構(gòu)生棍。
之前的安裝中,我們只使用了兩個(gè)節(jié)點(diǎn)媳谁,一個(gè)控制節(jié)點(diǎn)涂滴,一個(gè)計(jì)算節(jié)點(diǎn)。本文中晴音,我們把swift安裝在控制節(jié)點(diǎn)和計(jì)算節(jié)點(diǎn)柔纵,領(lǐng)會(huì)精神。如果要增加存儲(chǔ)節(jié)點(diǎn)锤躁,修改Ring files搁料,然后參照計(jì)算節(jié)點(diǎn)配置即可。
控制節(jié)點(diǎn)安裝:
Swift Proxy
Swift-Account
Swift-Container
Swift-Object
計(jì)算節(jié)點(diǎn)安裝:
Swift Proxy
Swift-Account
Swift-Container
Swift-Object
控制節(jié)點(diǎn)
root用戶
為了避免權(quán)限問題系羞,建議切換到root用戶進(jìn)行操作(否則要加很多sudo)郭计。
sudo -i
服務(wù)證書和端點(diǎn)
1、使admin環(huán)境生效
. admin-openrc
2觉啊、添加swift用戶
openstack user create --domain default --project service --password openstack swift
3拣宏、把a(bǔ)dmin角色添加給swift用戶
openstack role add --project service --user swift admin
4、創(chuàng)建swift服務(wù)
openstack service create --name swift --description "OpenStack Object Storage" object-store
5杠人、創(chuàng)建服務(wù)端點(diǎn)
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 Proxy
1勋乾、安裝swift-proxy
apt-get -y install swift swift-proxy python-swiftclient python-keystonemiddleware python-memcache
2宋下、創(chuàng)建swift配置目錄
mkdir /etc/swift
3、vi /etc/swift/proxy-server.conf
辑莫,新建proxy-server.conf內(nèi)容如下:
# 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,SwiftOperator
[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
4学歧、vi /etc/swift/swift.conf
,新建swift.conf內(nèi)容為:
# create new (it is shared among Swift Nodes - any words you like)
[swift-hash]
swift_hash_path_suffix = swift_shared_path
swift_hash_path_prefix = swift_shared_path
5各吨、修改權(quán)限
chown -R swift. /etc/swift
配置Ring files
1枝笨、創(chuàng)建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
12、2揭蜒、1這三個(gè)參數(shù)横浑,分別代表part_power、replicas屉更、min_part_hours徙融。
part_power是以2為底數(shù)的指數(shù)的冪,即2^ part_power瑰谜,所得的值表示總共的partition的數(shù)目欺冀。如果設(shè)置為2,則2^2=4萨脑,表示總共有4個(gè)partition隐轩。
replicas表示每個(gè)object在swift中儲(chǔ)存的數(shù)目。
min_part_hours表示一個(gè)partiton能夠再次更改的最小時(shí)間渤早。防止沒有進(jìn)行同步便進(jìn)行下次更改职车。
2、添加存儲(chǔ)節(jié)點(diǎn)
swift-ring-builder /etc/swift/account.builder add r0z0-172.16.0.105:6002/device0 100
swift-ring-builder /etc/swift/container.builder add r0z0-172.16.0.105:6001/device0 100
swift-ring-builder /etc/swift/object.builder add r0z0-172.16.0.105:6000/device0 100
swift-ring-builder /etc/swift/account.builder add r1z1-172.16.0.106:6002/device1 100
swift-ring-builder /etc/swift/container.builder add r1z1-172.16.0.106:6001/device1 100
swift-ring-builder /etc/swift/object.builder add r1z1-172.16.0.106:6000/device1 100
3蛛芥、平衡存儲(chǔ)
swift-ring-builder /etc/swift/account.builder rebalance
swift-ring-builder /etc/swift/container.builder rebalance
swift-ring-builder /etc/swift/object.builder rebalance
4提鸟、更改權(quán)限
chown swift. /etc/swift/*.gz
5军援、重啟swift-proxy
systemctl restart swift-proxy
計(jì)算節(jié)點(diǎn)
root用戶
為了避免權(quán)限問題仅淑,建議切換到root用戶進(jìn)行操作(否則要加很多sudo)。
sudo -i
磁盤分區(qū)
1胸哥、《Ubuntu16手動(dòng)安裝OpenStack——cinder篇》一文中涯竟,因?yàn)橛?jì)算節(jié)點(diǎn)(存儲(chǔ)節(jié)點(diǎn))的sdb用于cinder服務(wù)了,所以我們需要在計(jì)算節(jié)點(diǎn)再添加一塊硬盤sdc空厌,用于swift服務(wù)庐船。
2、查看硬盤
fdisk -l
3嘲更、對(duì)sdc進(jìn)行分區(qū)
fdisk /dev/sdc
- 輸入 m 顯示所有命令提示筐钟。
- 輸入 p 顯示硬盤分割情形。
- 輸入 a 設(shè)定硬盤啟動(dòng)區(qū)赋朦。
- 輸入 n 設(shè)定新的硬盤分割區(qū)篓冲。輸入 e 硬盤為[延伸]分割區(qū)(extend)李破,輸入 p 硬盤為[主要]分割區(qū)(primary)。
- 輸入 t 改變硬盤分割區(qū)屬性壹将。
- 輸入 d 刪除硬盤分割區(qū)屬性嗤攻。
- 輸入 q 結(jié)束不存入硬盤分割區(qū)屬性。
- 輸入 w 結(jié)束并寫入硬盤分割區(qū)屬性诽俯。
4妇菱、命令行輸入n,添加一個(gè)新的分區(qū)暴区;接下來選擇p闯团,設(shè)置一個(gè)主分區(qū)(e為擴(kuò)展分區(qū));接下來分區(qū)號(hào)選擇1仙粱;再接下來設(shè)置起止扇區(qū)號(hào)偷俭,選擇默認(rèn)值即可(2048到max);最后輸入w缰盏,確認(rèn)寫入硬盤分區(qū)涌萤。
安裝配置
1、下載安裝相關(guān)組件
apt-get -y install swift swift-account swift-container swift-object xfsprogs
2口猜、使用xfs格式化空閑磁盤
mkfs.xfs -i size=1024 -s size=4096 /dev/sdc1
3负溪、創(chuàng)建device1文件夾
mkdir -p /srv/node/device1
4、掛載/dev/sdc1到device1
mount -o noatime,nodiratime,nobarrier /dev/sdc1 /srv/node/device1
5济炎、修改權(quán)限
chown -R swift. /srv/node
6川抡、vi /etc/fstab
,設(shè)置開機(jī)掛載
# add to the end
/dev/sdc1 /srv/node/device1 xfs noatime,nodiratime,nobarrier 0 0
7须尚、從控制節(jié)點(diǎn)(swift-proxy)拷貝文件到計(jì)算節(jié)點(diǎn)
scp voidking@172.16.0.105:/etc/swift/*.gz /etc/swift/
8崖堤、修改權(quán)限
chown swift. /etc/swift/*.gz
9、vi /etc/swift/swift.conf
耐床,新建swift.conf內(nèi)容如下:
# set the value which is set on Proxy Node
[swift-hash]
swift_hash_path_suffix = swift_shared_path
swift_hash_path_prefix = swift_shared_path
10密幔、vi /etc/swift/account-server.conf
,如下修改:
# line 2: make sure the value is follows
bind_ip = 0.0.0.0
bind_port = 6002
11撩轰、vi /etc/swift/container-server.conf
胯甩,如下修改:
# line 2: make sure the value is follows
bind_ip = 0.0.0.0
bind_port = 6001
12、vi /etc/swift/object-server.conf
堪嫂,如下修改:
# line 2: make sure the value is follows
bind_ip = 0.0.0.0
bind_port = 6000
13偎箫、vi /etc/rsyncd.conf
,新建rsyncd.conf內(nèi)容如下:
# create new
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
uid = swift
gid = swift
# IP address of this Node
address = 172.16.0.106
[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
14皆串、vi /etc/default/rsync
淹办,如下修改:
# line 8: change
RSYNC_ENABLE=true
15、重啟rsync并設(shè)置開機(jī)啟動(dòng)
systemctl restart rsync
systemctl enable rsync
16恶复、重啟其他swift服務(wù)并設(shè)置開機(jī)啟動(dòng)
for ringtype in account container object; do
systemctl restart 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
至此怜森,一個(gè)存儲(chǔ)節(jié)點(diǎn)配置成功齐遵,下面再配置一個(gè)swift存儲(chǔ)節(jié)點(diǎn)在控制節(jié)點(diǎn)上。
控制節(jié)點(diǎn)
root用戶
為了避免權(quán)限問題塔插,建議切換到root用戶進(jìn)行操作(否則要加很多sudo)梗摇。
sudo -i
磁盤分區(qū)
1、在控制節(jié)點(diǎn)再添加一塊硬盤sdb想许,用于swift服務(wù)伶授。
2、參考計(jì)算節(jié)點(diǎn)的分區(qū)方法流纹,給sdb分區(qū)糜烹。
安裝配置
1、下載安裝相關(guān)組件
apt-get -y install swift swift-account swift-container swift-object xfsprogs
2漱凝、使用xfs格式化空閑磁盤
mkfs.xfs -i size=1024 -s size=4096 /dev/sdb1
3疮蹦、創(chuàng)建device0文件夾
mkdir -p /srv/node/device0
4、掛載/dev/sdc1到device1
mount -o noatime,nodiratime,nobarrier /dev/sdb1 /srv/node/device0
5茸炒、修改權(quán)限
chown -R swift. /srv/node
6愕乎、vi /etc/fstab
,設(shè)置開機(jī)掛載
# add to the end
/dev/sdb1 /srv/node/device0 xfs noatime,nodiratime,nobarrier 0 0
7壁公、修改權(quán)限
chown swift. /etc/swift/*.gz
8感论、vi /etc/swift/account-server.conf
,如下修改:
# line 2: make sure the value is follows
bind_ip = 0.0.0.0
bind_port = 6002
9紊册、vi /etc/swift/container-server.conf
比肄,如下修改:
# line 2: make sure the value is follows
bind_ip = 0.0.0.0
bind_port = 6001
10、vi /etc/swift/object-server.conf
囊陡,如下修改:
# line 2: make sure the value is follows
bind_ip = 0.0.0.0
bind_port = 6000
11芳绩、vi /etc/rsyncd.conf
,新建rsyncd.conf內(nèi)容如下:
# create new
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
uid = swift
gid = swift
# IP address of this Node
address = 172.16.0.105
[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
12撞反、vi /etc/default/rsync
妥色,如下修改:
# line 8: change
RSYNC_ENABLE=true
13、重啟rsync并設(shè)置開機(jī)啟動(dòng)
systemctl restart rsync
systemctl enable rsync
14痢畜、重啟其他swift服務(wù)并設(shè)置開機(jī)啟動(dòng)
for ringtype in account container object; do
systemctl restart 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
至此垛膝,控制節(jié)點(diǎn)的swift存儲(chǔ)也配置完成。
使用
以下操作在控制節(jié)點(diǎn)執(zhí)行丁稀。
服務(wù)角色和用戶
1、使admin環(huán)境生效
. admin-openrc
2倚聚、創(chuàng)建一個(gè)swiftservice服務(wù)
openstack project create --domain default --description "Swift Service Project" swiftservice
3线衫、創(chuàng)建SwiftOperator角色
openstack role create SwiftOperator
4、創(chuàng)建user01用戶惑折,密碼為openstack
openstack user create --domain default --project swiftservice --password openstack user01
5授账、給user01添加SwiftOperator角色
openstack role add --project swiftservice --user user01 SwiftOperator
客戶端
1枯跑、安裝swift-client
apt-get -y install python-openstackclient python-keystoneclient python-swiftclient
2、vi ~/swift-openrc
白热,創(chuàng)建環(huán)境配置文件swift-openrc敛助,內(nèi)容為:
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default
export OS_PROJECT_NAME=swiftservice
export OS_USERNAME=user01
export OS_PASSWORD=openstack
export OS_AUTH_URL=http://controller:5000/v3
export OS_IDENTITY_API_VERSION=3
export PS1='[\u@\h \W(swift)]\$ '
3、使環(huán)境生效
. swift-openrc
4屋确、查看swift狀態(tài)
swift stat
[圖片上傳失敗...(image-2db55a-1545009719236)]
5纳击、創(chuàng)建一個(gè)container
openstack container create test_container
openstack container list
6、vim test.txt
攻臀,新建test.txt焕数,內(nèi)容為“hello openstack”。
7刨啸、上傳test.txt文件到test_container
openstack object create test_container test.txt
8堡赔、查看test_container中的文件
openstack object list test_container
9、下載test.txt文件
rm test.txt
ll
openstack object save test_container test.txt
ll
10设联、刪除test_container中的test.txt文件
openstack object list test_container
openstack object delete test_container test.txt
openstack object list test_container
11善已、刪除test_container
openstack container list
openstack container delete test_container
openstack container list