1. 程式人生 > >Openstack Swift 安裝部署總結

Openstack Swift 安裝部署總結

環境

  • 硬體

    這裡只使用了一臺伺服器,既作為Controller Node,也作為Storage Node

主機名 IP OS 磁碟 檔案系統
sf-dev 10.202.127.4 Centos-7.4 /dev/sdb
/dev/sdc
/dev/sdd
XFS
  • 配置可用的Openstack源

    這裡使用了清華開源映象。配置伺服器映象:

    cd /etc/yum.repos.d/
    vim CentOS-Base.repo
    

    增加如下配置

    ...
    [openstack]
    name=Openstack
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/cloud/x86_64/openstack-pike/
    gpgcheck=0
    ...
    

    使用YUM跟新庫

    yum update -y
    

Swift元件安裝於配置

1. 安裝必要的元件包

# yum install openstack-swift-proxy python-swiftclient \
  python-keystoneclient python-keystonemiddleware \
  memcached
  • 從Swift源映象獲取代理服務配置檔案,並進行配置

    # curl -o /etc/swift/proxy-server.conf https://git.openstack.org/cgit/openstack/swift/plain/etc/proxy-server.conf-sample?h=stable/pike
    

    編輯代理伺服器配置檔案/etc/swift/proxy-server.conf

    1. 編輯 [DEFAULT] 段內容,配置如下內容

      [DEFAULT]
      ...
      bind_port = 8080
      user = swift
      swift_dir = /etc/swift
      
    2. 編輯 [pipeline:main]

      [pipeline:main]
      pipeline = catch_errors gatekeeper healthcheck proxy-logging cache container_sync bulk tempurl ratelimit tempauth copy container-quotas account-quotas slo dlo versioned_writes proxy-logging proxy-server  
      
    3. 編輯 [app:proxy-server] 段內容,允許自動建立賬戶

      [app:proxy-server]
      use = egg:swift#proxy
      ...
      account_autocreate = True
      
    4. [filter:tempauth] 段中,設定允許的的賬戶/使用者

      [filter:tempauth]
      ...
      user_admin_admin = admin .admin .reseller_admin
      user_test_tester = testing .admin
      
    5. [filter:cache] 段中,設定memcache位置

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

注意:如果控制節點與儲存節點分離,以上配置只需在控制節點進行配置,如果使用keystone請參考配置說明,更詳細的說明請閱讀官方文件

2. 儲存節點元件包安裝於配置說明

  • 安裝實用軟體包

    # yum install xfsprogs rsync
    
  • 格式化磁碟

    # mkfs.xfs /dev/sdb -f
    # mkfs.xfs /dev/sdc -f
    # mkfs.xfs /dev/sdd -f
    
  • 建立mount點

    # mkdir -p /srv/node/sdb
    # mkdir -p /srv/node/sdc
    # mkdir -p /srv/node/sdd
    
  • 編輯 /etc/fstab 檔案,新增如下內容:

    /dev/sdb /srv/node/sdb xfs noatime,nodiratime,nobarrier,logbufs=8 0 2
    /dev/sdc /srv/node/sdc xfs noatime,nodiratime,nobarrier,logbufs=8 0 2
    /dev/sdd /srv/node/sdd xfs noatime,nodiratime,nobarrier,logbufs=8 0 2
    
  • Mount 裝置

    # mount /srv/node/sdb
    # mount /srv/node/sdc
    # mount /srv/node/sdd
    
  • 建立並編輯 /etc/rsyncd.conf 檔案,內容如下:

    uid = swift
    gid = swift
    log file = /var/log/rsyncd.log
    pid file = /var/run/rsyncd.pid
    address = 10.202.127.4 #控制節點IP
    
    [account]
    max connections = 2
    path = /srv/node/
    read only = False
    lock file = /var/lock/account.lock
    
    [container]
    max connections = 2
    path = /srv/node/
    read only = False
    lock file = /var/lock/container.lock
    
    [object]
    max connections = 2
    path = /srv/node/
    read only = False
    lock file = /var/lock/object.lock
    
  • 儲存節點軟體包安裝

    # yum install openstack-swift-account openstack-swift-container \
      openstack-swift-object
    
  • 從Swift源映象獲取賬戶(accounting)、容器(container)以及物件(object)服務配置檔案,並進行配置

    # curl -o /etc/swift/account-server.conf https://git.openstack.org/cgit/openstack/swift/plain/etc/account-server.conf-sample?h=stable/pike
    # curl -o /etc/swift/container-server.conf https://git.openstack.org/cgit/openstack/swift/plain/etc/container-server.conf-sample?h=stable/pike
    # curl -o /etc/swift/object-server.conf https://git.openstack.org/cgit/openstack/swift/plain/etc/object-server.conf-sample?h=stable/pike
    
  • 編輯賬戶服務配置檔案 /etc/swift/account-server.conf

    1. [DEFAULT] 中配置如下資訊:

      [DEFAULT]
      ...
      bind_ip = 10.202.127.4
      bind_port = 6202
      user = swift
      swift_dir = /etc/swift
      devices = /srv/node
      mount_check = True
      
    2. 編輯 [pipeline:main]

      [pipeline:main]
      pipeline = healthcheck recon account-server
      
    3. [filter:recon] 中,設定recon cache 目錄:

      [filter:recon]
      use = egg:swift#recon
      ...
      recon_cache_path = /var/cache/swift
      
  • 編輯賬戶服務配置檔案 /etc/swift/container-server.conf

    1. [DEFAULT] 中配置如下資訊:

      [DEFAULT]
      ...
      bind_ip = 10.202.127.4
      bind_port = 6201
      user = swift
      swift_dir = /etc/swift
      devices = /srv/node
      mount_check = True
      
    2. 編輯 [pipeline:main]

      [pipeline:main]
      pipeline = healthcheck recon container-server
      
    3. [filter:recon] 中,設定recon cache 目錄:

      [filter:recon]
      use = egg:swift#recon
      ...
      recon_cache_path = /var/cache/swift
      
  • 編輯賬戶服務配置檔案 /etc/swift/object-server.conf

    1. [DEFAULT] 中配置如下資訊:

      [DEFAULT]
      ...
      bind_ip = 10.202.127.4
      bind_port = 6200
      user = swift
      swift_dir = /etc/swift
      devices = /srv/node
      mount_check = True
      
    2. 編輯 [pipeline:main]

      [pipeline:main]
      pipeline = healthcheck recon object-server
      
    3. [filter:recon] 中,設定recon cache 目錄:

      [filter:recon]
      use = egg:swift#recon
      ...
      recon_cache_path = /var/cache/swift
      recon_lock_path = /var/lock
      
  • Mount 點目錄所屬許可權設定

    # chown -R swift:swift /srv/node
    
  • 建立 recon目錄,並設定目錄所屬許可權

    # mkdir -p /var/cache/swift
    # chown -R root:swift /var/cache/swift
    # chmod -R 775 /var/cache/swift
    

3. 建立Rings

在啟動物件儲存服務前,需要建立並初始化account,container,object的rings。這裡使用一個region,1個zone。總共設定2^10(1024)個最大分割槽(partitions),使用3副本策略(replicas),設定1小時來限制需要多次移動分割槽時為最小間隔

  • 建立account ring

    cd /etc/swift
    # swift-ring-builder account.builder create 10 3 1
    

    新增所有儲存到ring

    # swift-ring-builder account.builder add \
      --region 1 --zone 1 --ip 10.202.127.4 --port 6202 --device sdb --weight 100
    # swift-ring-builder account.builder add \
      --region 1 --zone 1 --ip 10.202.127.4 --port 6202 --device sdc --weight 100
    # swift-ring-builder account.builder add \
      --region 1 --zone 1 --ip 10.202.127.4 --port 6202 --device sdd --weight 100
    

    Rebalance the ring

    # swift-ring-builder account.builder rebalance
    

    確認ring

    # swift-ring-builder account.builder
    
  • 建立container ring

    cd /etc/swift
    # swift-ring-builder container.builder create 10 3 1
    

    新增所有儲存到ring

    # swift-ring-builder container.builder add \
      --region 1 --zone 1 --ip 10.202.127.4 --port 6201 --device sdb --weight 100
    # swift-ring-builder container.builder add \
      --region 1 --zone 1 --ip 10.202.127.4 --port 6201 --device sdc --weight 100
    # swift-ring-builder container.builder add \
      --region 1 --zone 1 --ip 10.202.127.4 --port 6201 --device sdd --weight 100
    

    Rebalance the ring

    # swift-ring-builder container.builder rebalance
    

    確認ring

    # swift-ring-builder container.builder
    
  • 建立object ring

    cd /etc/swift
    # swift-ring-builder object.builder create 10 3 1
    

    新增所有儲存到ring

    # swift-ring-builder object.builder add \
      --region 1 --zone 1 --ip 10.202.127.4 --port 6200 --device sdb --weight 100
    # swift-ring-builder object.builder add \
      --region 1 --zone 1 --ip 10.202.127.4 --port 6200 --device sdc --weight 100
    # swift-ring-builder object.builder add \
      --region 1 --zone 1 --ip 10.202.127.4 --port 6200 --device sdd --weight 100
    

    Rebalance the ring

    # swift-ring-builder object.builder rebalance
    

    確認ring

    # swift-ring-builder object.builder
    

注意:如果有多個儲存節點,需要將ring配置檔案 account.ring.gz, container.ring.gzobject.ring.gz 分發到各個儲存節點的 /etc/swift 目錄下

3. 配置swift.conf 並啟動各元件服務

  • 從swift git倉庫中獲取配置檔案到 /etc/swift/ 目錄

    # curl -o /etc/swift/swift.conf \
      https://git.openstack.org/cgit/openstack/swift/plain/etc/swift.conf-sample?h=stable/pike
    

    編輯配置檔案/etc/swift/swift.conf

    1. [swift-hash] 中,設定如下內容:

      [swift-hash]
      ...
      swift_hash_path_suffix = HASH_PATH_SUFFIX #替換為自己的內容,如swift
      swift_hash_path_prefix = HASH_PATH_PREFIX #替換為自己的內容,如swift
      
    2. 建立並配置預設策略

      [storage-policy:0]
      ...
      name = Policy-0
      default = yes
      
    3. 如果是多儲存節點,將配置檔案 swift.conf 拷貝到各節點的 /etc/swift 目錄下

    4. 修改所有節點 /etc/swift/ 目錄所屬許可權如下:

      # chown -R root:swift /etc/swift
      
  • 控制節點啟動代理服務和memcache服務

    # systemctl enable openstack-swift-proxy.service memcached.service
    # systemctl start openstack-swift-proxy.service memcached.service
    
  • 儲存節點啟動如下服務

    # systemctl enable openstack-swift-account.service openstack-swift-account-auditor.service \
      openstack-swift-account-reaper.service openstack-swift-account-replicator.service
    # systemctl start openstack-swift-account.service openstack-swift-account-auditor.service \
      openstack-swift-account-reaper.service openstack-swift-account-replicator.service
    # systemctl enable openstack-swift-container.service \
      openstack-swift-container-auditor.service openstack-swift-container-replicator.service \
      openstack-swift-container-updater.service
    # systemctl start openstack-swift-container.service \
      openstack-swift-container-auditor.service openstack-swift-container-replicator.service \
      openstack-swift-container-updater.service
    # systemctl enable openstack-swift-object.service openstack-swift-object-auditor.service \
      openstack-swift-object-replicator.service openstack-swift-object-updater.service
    # systemctl start openstack-swift-object.service openstack-swift-object-auditor.service \
      openstack-swift-object-replicator.service openstack-swift-object-updater.service
    

服務驗證

新建並編輯 testrc 檔案

cd $HOME
vim testrc

寫入 /etc/swift/proxy-server.conf 配置檔案中 配置的使用者許可權資訊,如下:

export ST_AUTH=http://10.202.127.4:8080/auth/v1.0
export ST_USER=test:tester
export ST_KEY=testing

執行上訴配置指令碼,使配置資訊生效

. testrc

檢視swift服務狀態

swift stat

獲取 X-Storage-UrlX-Auth-Token

curl -v -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' http://127.0.0.1:8080/auth/v1.0

檢視賬戶

curl -v -H 'X-Auth-Token: <token-from-x-auth-token-above>' <url-from-x-storage-url-above>

我們可以使用如下命令獲取賬戶下容器列表

swift list

獲取容器下的物件列表

swift list <container>