next up previous contents
Next: 設定 Swift Service Ring Up: 物件儲存 Swift Previous: Swift 安裝   Contents

建立 Swift Storage Node

  1. 查看 /dev/vdb 及 /dev/vdc 各有 104 M,並已切割好 /dev/vdb1 及 /dev/vdc1。 如果沒切割好分的分割區,就先執行 fdisk -uc 進入分割。
    [root@kvm4 ~]# fdisk -luc /dev/vdb /dev/vdc
    
    Disk /dev/vdb: 104 MB, 104857600 bytes
    15 heads, 14 sectors/track, 975 cylinders, total 204800 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x9d217a56
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vdb1            2048      186367       92160   83  Linux
    
    Disk /dev/vdc: 104 MB, 104857600 bytes
    15 heads, 14 sectors/track, 975 cylinders, total 204800 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x1eb6d3a5
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vdc1            2048      186367       92160   83  Linux
    
  2. 將 /dev/vdb1 格式成 ext4。
    [root@kvm4 ~]# mkfs.ext4 /dev/vdb1
    mke2fs 1.41.12 (17-May-2010)
    Filesystem label=
    OS type: Linux
    Block size=1024 (log=0)
    Fragment size=1024 (log=0)
    Stride=0 blocks, Stripe width=0 blocks
    23040 inodes, 92160 blocks
    4608 blocks (5.00%) reserved for the super user
    First data block=1
    Maximum filesystem blocks=67371008
    12 block groups
    8192 blocks per group, 8192 fragments per group
    1920 inodes per group
    Superblock backups stored on blocks: 
    	8193, 24577, 40961, 57345, 73729
    
    Writing inode tables: done                            
    Creating journal (4096 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 33 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    
  3. 將 /dev/vdc1 格式成 ext4。
    [root@kvm4 ~]# mkfs.ext4 /dev/vdc1
    mke2fs 1.41.12 (17-May-2010)
    Filesystem label=
    OS type: Linux
    Block size=1024 (log=0)
    Fragment size=1024 (log=0)
    Stride=0 blocks, Stripe width=0 blocks
    23040 inodes, 92160 blocks
    4608 blocks (5.00%) reserved for the super user
    First data block=1
    Maximum filesystem blocks=67371008
    12 block groups
    8192 blocks per group, 8192 fragments per group
    1920 inodes per group
    Superblock backups stored on blocks: 
    	8193, 24577, 40961, 57345, 73729
    
    Writing inode tables: done                            
    Creating journal (4096 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 25 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    
  4. 建立掛載點,並設定開機自動掛載,注意掛載參數必須包含 acl 及 user_xattr
    [root@kvm4 ~]# mkdir -p /srv/node/z{1,2}d1
    [root@kvm4 ~]# cp /etc/fstab /etc/fstab.orig
    [root@kvm4 ~]# echo "/dev/vdb1 /srv/node/z1d1 ext4 acl,user_xattr 0 0" >> /etc/fstab
    [root@kvm4 ~]# echo "/dev/vdc1 /srv/node/z2d1 ext4 acl,user_xattr 0 0" >> /etc/fstab
    
  5. 重新掛載 /etc/fstab 中的掛載點,沒有訊息表示一切正常。
    [root@kvm4 ~]# mount -a
    [root@kvm4 ~]#
    
  6. 改變目錄 /srv/node 的擁有者及群組皆為 swift
    [root@kvm4 ~]# chown -R swift:swift /srv/node/
    [root@kvm4 ~]# ll -d /srv/node/
    drwxr-xr-x. 4 swift swift 4096 Jan 24 22:51 /srv/node/
    
  7. 重置目錄 /srv 的 SELinux context。
    [root@kvm4 ~]# restorecon -Rv /srv/
    restorecon reset /srv/node context unconfined_u:object_r:var_t:s0->system_u:object_r:swift_data_t:s0
    restorecon reset /srv/node/z1d1 context system_u:object_r:file_t:s0->system_u:object_r:swift_data_t:s0
    restorecon reset /srv/node/z1d1/lost+found context system_u:object_r:file_t:s0->system_u:object_r:swift_data_t:s0
    restorecon reset /srv/node/z2d1 context system_u:object_r:file_t:s0->system_u:object_r:swift_data_t:s0
    restorecon reset /srv/node/z2d1/lost+found context system_u:object_r:file_t:s0->system_u:object_r:swift_data_t:s0
    
  8. 先備份 swift 主設定檔及服務 account, container 及 object 設定檔。
    [root@kvm4 ~]# cp /etc/swift/swift.conf /etc/swift/swift.conf.orig
    [root@kvm4 ~]# cp /etc/swift/account-server.conf /etc/swift/account-server.conf.orig
    [root@kvm4 ~]# cp /etc/swift/container-server.conf /etc/swift/container-server.conf.orig
    [root@kvm4 ~]# cp /etc/swift/object-server.conf /etc/swift/object-server.conf.orig
    
  9. 設定 swift 主設定檔 /etc/swift/swift.conf,檔案存放位置的字首(prefix)及字尾(suffix) 的 hash。
    [root@kvm4 ~]# openstack-config --set /etc/swift/swift.conf swift-hash swift_hash_path_suffix $(openssl rand -hex 10)
    [root@kvm4 ~]# openstack-config --set /etc/swift/swift.conf swift-hash swift_hash_path_prefix $(openssl rand -hex 10)
    
  10. 設定 account, container 及 object 連結 ip。
    [root@kvm4 ~]# openstack-config --set /etc/swift/account-server.conf DEFAULT bind_ip 192.168.122.4
    [root@kvm4 ~]# openstack-config --set /etc/swift/container-server.conf DEFAULT bind_ip 192.168.122.4
    [root@kvm4 ~]# openstack-config --set /etc/swift/object-server.conf DEFAULT bind_ip 192.168.122.4
    
  11. 啟動 account, container 及 object 服務並設定開機啟動。
    [root@kvm4 ~]# /etc/init.d/openstack-swift-account start
    Starting openstack-swift-account:                  [  OK  ]
    [root@kvm4 ~]# chkconfig openstack-swift-account on
    [root@kvm4 ~]# /etc/init.d/openstack-swift-container start
    Starting openstack-swift-container:                [  OK  ]
    [root@kvm4 ~]# chkconfig openstack-swift-container on
    [root@kvm4 ~]# /etc/init.d/openstack-swift-object start
    Starting openstack-swift-object:                   [  OK  ]
    [root@kvm4 ~]# chkconfig openstack-swift-object on
    
  12. 若變更設定後要重新啟動 account, container 及 object 服務,可使用 swift-init 一次重新啟動所有服務。
    [root@kvm4 ~(keystone_admin)]$ swift-init all restart
    



2015-12-29