<<什麼是Swift 物件儲存服務?>>
物件儲存使用下列三個觀念:
- Storage replicas
- Storage zones
- Storage regions
<<Swift 物件儲存服務架構>>
OpenStack 物件儲存服務是一個模組化的服務,包含下列可用模組:
- openstack-swift-proxy
- openstack-swift-object
- openstack-swift-container
- openstack-swift-account
所有服務可在每一個節點或是指定的機器上!下列元件,可在適合的機器上操作:
- Ring files
- Object storage: /srv/node
- Housekeeping processes
<<物件儲存服務佈署設定檔>>
- All services run on all nodes: Simplest setup
- Dedicated proxy nodes, all other services combined on other nodes
- Dedicated proxy nodes, dedicated object service node, container and account services combined on other nodes
- # yum -y install openstack-swift-proxy openstack-swift-object openstack-swift-container openstack-swift-account python-swiftclient memcached
- # source /root/keystonerc_admin
- # keystone tenant-list | grep services
- # keystone user-create --name swift --pass redhat --tenant services
- # keystone role-list | grep admin
- # keystone role-create --name SwiftOperator
- # keystone user-role-add --user swift --role admin --tenant services
- # keystone service-list | grep swift
- # keystone service-create --name swift --type object-store --description "OpenStack Object Storage"
- # keystore endpoint-create --service swift --region RegionOne --publicurl "http://10.1.1.1:8080/v1/AUTH_%(tenant_id)s" --adminurl "http://10.1.1.1:8080/v1/AUTH_%(tenant_id)s" --internalurl "http://10.1.1.1:8080/v1/AUTH_%(tenant_id)s"
佈署Swift儲存節點
- 物件儲存服務存放物件於檔案系統上!檔案系統通常也連結數個節點!
- 檔案系統通常被格式化成 ext4 或 xfs 格式,並掛載在/srv/node 目錄下!
- 任何被指定的儲存節點,必須要安裝下列套件:openstack-swift-object , openstack-swift-container, openstack-swift-account
- # mkdir -p /srv/node/z{1,2}d1
- # cp /etc/fstab /etc/fstab.orig
- # echo "/dev/vdc1 /srv/node/z1d1 xfs defaults 0 0" >> /etc/fstab
- # echo "/dev/vdd1 /srv/node/z2d1 xfs defaults 0 0" >> /etc/fstab
- # mount -a
- # df -h | grep srv
- # chown -R swift:swift /srv/node
- # restorecon -rv /srv
- # cp /etc/swift/*.conf /root/swift_orig/
- # crudini --set /etc/swift/swift.conf swift-hash swift_hash_path_prefix $(openssl rand -hex 10)
- # crudini --set /etc/swift/swift.conf swift-hash swift_hash_path_suffix $(openssl rand -hex 10)
- # cp /etc/swift/swift.conf /etc/swift/swift.conf.orig2
- # crudini --set /etc/swift/account-server.conf DEFAULF bind_ip 10.1.1.1
- # crudini --set /etc/swift/container-server.conf DEFAULF bind_ip 10.1.1.1
- # crudini --set /etc/swift/object-server.conf DEFAULF bind_ip 10.1.1.1
- Rings決定資料儲放在儲存節點叢集的哪一個地方
- Rings 需要三個檔案:Object, Container, Account Services
- Rings 檔案可由 swift-ring-builder 工具依下列三個參數產生:
- Partition power
- Replica count
- min_part_hours
- zone是第四個參數,用來增加硬體到 Rings
- 範例:# swift-ring-builder /etc/swift/account.builder add z1-10.1.1.1:6202/accounts 100
- /etc/swift 目錄內容,需要複製到每個節點的 /etc/swift 目錄
- # source /root/keystonerc_admin
- # 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
- # for i in 1 2; do
>swift-ring-builder /etc/swift/account.builder add z${i}-172.25.0.10:6202/z${i}d1 100
>done - # for i in 1 2; do
>swift-ring-builder /etc/swift/container.builder add z${i}-172.25.0.10:6201/z${i}d1 100
>done - # for i in 1 2; do
>swift-ring-builder /etc/swift/object.builder add z${i}-172.25.0.10:6200/z${i}d1 100
>done - # swift-ring-builder /etc/swift/account.builder rebalance
- # swift-ring-builder /etc/swift/container.builder rebalance
- # swift-ring-builder /etc/swift/object.builder rebalance
- # ls /etc/swift/*gz
- # systemctl enable openstack-swift-account
- # systemctl enable openstack-swift-container
- # systemctl enable openstack-swift-object
- # openstack-service start swift
- # chown -R root:swift /etc/swift
- # tail /var/log/messages
- 物件儲存代理服務用來決定哪一個節點被引導去存取
- # cp /etc/swift/proxy-server.conf /etc/swift/proxy-server.conf.orig
- # crudini --set /etc/swift/proxy-server.conf filter:authtoken admin_tenant_name services
- # crudini --set /etc/swift/proxy-server.conf filter:authtoken auth_host 10.1.1.1
- # crudini --set /etc/swift/proxy-server.conf filter:authtoken auth_uri http://10.1.1.1:5000
- # crudini --set /etc/swift/proxy-server.conf filter:authtoken admin_user swift
- # crudini --set /etc/swift/proxy-server.conf filter:authtoken admin_password redhat
- # systemctl start memcached
- # systemctl start openstack-swift-proxy
- # tail /var/log/messages
- # systemctl enable memcached
- # systemctl enable openstack-swift-proxy
- 利用 swift 可以查詢儲存空間
- # cd /etc/swift
- # grep bind_port *.conf
- # cd
- # ls -al /srv/node/
- # swift-ring-builder /etc/swift/account.builder
- # swift-ring-builder /etc/swift/container.builder
- # swift-ring-builder /etc/swift/object.builder
- # vim /etc/swift/proxy-server.conf
[DEFAULT]
bind_port = 8080
[pipeline:main]
pipeline = ... keystone ...
[app:proxy-server]
allow_account_management = true
account_autocreate = true
[filter:keystone]
operator_roles = admin, SwiftOperator
[filter:authtoken]
paste.filter_factory = keystonemiddleware.auth_token:filter_factory
admin_tenant_name = services
admin_user = swift
admin_password = redhat
auth_host = 10.1.1.1
auth_port = 35357
auth_protocol = http
signing_dir = /tmp/keystone-signing-swift
auth_uri = http://10.1.1.1:5000
- # openstack-service restart swift
- # source /root/keystonerc_admin
- # keystone user-get swift
- # keystone role-list
- # keystone service-get swift
- # keystone catalog --service object-store
- # swift list
- # swift post c1
- # swift post c2
- # echo "hello" > data1.file
- # swift upload c1 data1.file
- # echo "hello2" > data2.file
- # swift upload c1 data2.file
- # head -c 1024 /dev/urandom > data3.file
- # swift upload c2 data3.file
- # swift list
- # swift list c1
- # swift list c2
- # find /srv/node/ -type f -name "*data"
- # find /srv/node/ -type f -name "*data" -exec file {} \;
- # cat /srv/node/z1d1/....
練習6: