使用ansible命令,部署glusterfs集羣

網上部署glusterfs集羣,都是採用登陸到主機,執行命令的方式。若是瞭解ansible,使用ansible批量管理主機,部署glusterfs集羣更方便。centos

 

測試環境服務器

有4臺虛擬機,全部機器都安裝centos7.4系統。測試

tmaster,tslave1,tslave2做爲glusterfs服務器端節點,phn做爲glusterfs客戶端節點。centos7


10.101.19.12 tmaster
10.101.19.13 tslave1
10.101.19.14 tslave2
10.101.17.54 phn.net

還有一臺ansible節點,用來管理其餘主機。(假設你已經裝好了ansible節點)code

 

ansible的hosts文件regexp

[clusterfs]
10.101.19.12
10.101.19.13
10.101.19.14
10.101.17.54

[clusterfsserver]
10.101.19.12
10.101.19.13
10.101.19.14

[clusterfsclient]
10.101.17.54

 

部署過程server

1. 在ansible機器上中執行,初始化主機環境blog

# ping全部主機
ansible clusterfs -m ping部署

 

# 修改時區(可選)
ansible clusterfs -m file -a 'path=/etc/localtime src=/usr/share/zoneinfo/Asia/Shanghai state=link'
ansible clusterfs -a 'date -R'

 

# 修改hosts文件
ansible clusterfs -m lineinfile -a 'path=/etc/hosts regexp=tmaster$ line="10.101.19.12 tmaster"'
ansible clusterfs -m lineinfile -a 'path=/etc/hosts regexp=tslave1$ line="10.101.19.13 tslave1"'
ansible clusterfs -m lineinfile -a 'path=/etc/hosts regexp=tslave2$ line="10.101.19.14 tslave2"'
ansible clusterfs -m lineinfile -a 'path=/etc/hosts regexp=phn$ line="10.101.17.54 phn"'

ansible clusterfs -a "ping tmaster -c 1"
ansible clusterfs -a "ping phn -c 1"


2. 在ansible機器上中執行,配置glusterfs服務器節點

# 爲clusterfs服務器節點,安裝軟件
ansible clusterfsserver -m package -a 'name=centos-release-gluster state=present'
ansible clusterfsserver -m package -a 'name=glusterfs state=present'
ansible clusterfsserver -m package -a 'name=glusterfs-server state=present'
ansible clusterfsserver -m package -a 'name=glusterfs-fuse state=present'
ansible clusterfsserver -m package -a 'name=glusterfs-rdma state=present'

 

# 爲clusterfs服務器節點,啓動服務
ansible clusterfsserver -m service -a 'name=glusterd enabled=yes state=started'
ansible clusterfsserver -a 'systemctl status glusterd'

 

# 爲clusterfs服務器節點,建立數據目錄
ansible clusterfsserver -m file -a 'path=/opt/gluster/data state=directory'


3. 在master節點上執行,建立集羣,和添加volume等
gluster peer probe tmaster 
gluster peer probe tslave1 
gluster peer probe tslave2
gluster peer status

 

gluster volume info
gluster volume create models replica 3 tmaster:/opt/gluster/data tslave1:/opt/gluster/data tslave2:/opt/gluster/data force
gluster volume info
gluster volume start models


4. 在ansible機器上中執行,爲客戶端節點,安裝軟件等
ansible clusterfsclient -m package -a 'name=glusterfs state=present'
ansible clusterfsclient -m package -a 'name=glusterfs-fuse state=present'

 

爲客戶端節點,掛載卷
ansible clusterfsclient -m file -a 'path=/opt/gfsmount  state=directory'
ansible clusterfsclient -m mount -a 'path=/opt/gfsmount  state=mounted fstype=glusterfs src=tmaster:models'
ansible clusterfsclient -a "df -h"


5. 在10.101.17.54客戶端測試
time dd if=/dev/zero of=/opt/gfsmount/hello bs=100M count=1 

 

參考

http://blog.csdn.net/phn_csdn/article/details/75153913

相關文章
相關標籤/搜索