2015年12月9日 星期三

RHEL 的 OpenStack (五)--執行與管理 Swift 物件儲存服務

佈署Swift物件儲存服務

<<什麼是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
練習1:
  1. # yum -y install openstack-swift-proxy openstack-swift-object openstack-swift-container openstack-swift-account python-swiftclient memcached 
  2. # source /root/keystonerc_admin
  3. # keystone tenant-list | grep services
  4. # keystone user-create --name swift --pass redhat --tenant services
  5. # keystone role-list | grep admin
  6. # keystone role-create --name SwiftOperator
  7. # keystone user-role-add --user swift --role admin --tenant services
  8. # keystone service-list | grep swift
  9. # keystone service-create --name swift --type object-store --description "OpenStack Object Storage"
  10. # 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
練習2:
  1. # mkdir -p /srv/node/z{1,2}d1
  2. # cp /etc/fstab /etc/fstab.orig
  3. # echo "/dev/vdc1 /srv/node/z1d1 xfs defaults 0 0" >> /etc/fstab
  4. # echo "/dev/vdd1 /srv/node/z2d1 xfs defaults 0 0" >> /etc/fstab
  5. # mount -a
  6. # df -h | grep srv
  7. # chown -R swift:swift /srv/node
  8. # restorecon -rv /srv
  9. # cp /etc/swift/*.conf /root/swift_orig/
  10. # crudini --set /etc/swift/swift.conf swift-hash swift_hash_path_prefix $(openssl rand -hex 10)
  11. # crudini --set /etc/swift/swift.conf swift-hash swift_hash_path_suffix $(openssl rand -hex 10)
  12. # cp /etc/swift/swift.conf /etc/swift/swift.conf.orig2
  13. # crudini --set /etc/swift/account-server.conf DEFAULF bind_ip 10.1.1.1
  14. # crudini --set /etc/swift/container-server.conf DEFAULF bind_ip 10.1.1.1
  15. # crudini --set /etc/swift/object-server.conf DEFAULF bind_ip 10.1.1.1
設定Swift Rings
  • Rings決定資料儲放在儲存節點叢集的哪一個地方
  • Rings 需要三個檔案:Object, Container, Account Services
  • Rings 檔案可由 swift-ring-builder 工具依下列三個參數產生:
    1. Partition power
    2. Replica count
    3. 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 目錄
練習3:
  1. # source /root/keystonerc_admin
  2. # swift-ring-builder /etc/swift/account.builder create 12 2 1
  3. # swift-ring-builder /etc/swift/container.builder create 12 2 1
  4. # swift-ring-builder /etc/swift/object.builder create 12 2 1
  5. # 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
  6.  # 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
  7. # 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
  8. # swift-ring-builder /etc/swift/account.builder rebalance
  9. # swift-ring-builder /etc/swift/container.builder rebalance
  10. # swift-ring-builder /etc/swift/object.builder rebalance
  11. # ls /etc/swift/*gz
  12. # systemctl enable openstack-swift-account
  13. # systemctl enable openstack-swift-container
  14. # systemctl enable openstack-swift-object
  15. # openstack-service start swift
  16. # chown -R root:swift /etc/swift
  17. # tail /var/log/messages
佈署Swift代理服務
  • 物件儲存代理服務用來決定哪一個節點被引導去存取
練習4:
  1. # cp /etc/swift/proxy-server.conf /etc/swift/proxy-server.conf.orig
  2. # crudini --set /etc/swift/proxy-server.conf filter:authtoken admin_tenant_name services
  3. # crudini --set /etc/swift/proxy-server.conf filter:authtoken auth_host 10.1.1.1
  4. # crudini --set /etc/swift/proxy-server.conf filter:authtoken auth_uri http://10.1.1.1:5000
  5. # crudini --set /etc/swift/proxy-server.conf filter:authtoken admin_user swift
  6. # crudini --set /etc/swift/proxy-server.conf filter:authtoken admin_password redhat
  7. # systemctl start memcached
  8. # systemctl start openstack-swift-proxy
  9. # tail /var/log/messages
  10. # systemctl enable memcached
  11. # systemctl enable openstack-swift-proxy
在Swift中管理物件
  • 利用 swift 可以查詢儲存空間
練習5:
  1. # cd /etc/swift
  2. # grep bind_port *.conf
  3. # cd 
  4. # ls -al /srv/node/
  5. # swift-ring-builder /etc/swift/account.builder
  6. # swift-ring-builder /etc/swift/container.builder
  7. # swift-ring-builder /etc/swift/object.builder
  8. # 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
  9. # openstack-service restart swift
  10. # source /root/keystonerc_admin
  11. # keystone user-get swift
  12. # keystone role-list
  13. # keystone service-get swift
  14. # keystone catalog --service object-store
  15. # swift list
  16. # swift post c1
  17. # swift post c2
  18. # echo "hello" > data1.file
  19. # swift upload c1 data1.file
  20. # echo "hello2" > data2.file
  21. # swift upload c1 data2.file
  22. # head -c 1024 /dev/urandom > data3.file
  23. # swift upload c2 data3.file
  24. # swift list
  25. # swift list c1
  26. # swift list c2
  27. # find /srv/node/ -type f -name "*data"
  28. # find /srv/node/ -type f -name "*data" -exec file {} \;
  29. # cat /srv/node/z1d1/....
Swift物件儲存服務的除錯
練習6: