使用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

相关文章
相关标签/搜索