【Zanuck 镇】GlusterFS集群一键启动脚本(Centos:shell)

昨天有位哥们儿看了我的文章后向我反应安装完毕服务器重启后gluster挂载不了的问题,我帮他解决后写了个多机启动的脚本。(脚本是刚需,一般gluster集群在10台以上,如果给你1000台服务器,整体断电后重启,还要一个一个ssh上去启动?)

首先,小镇在这里说明下gluster+zfs的启动挂载的先后顺序,要保证glusterfs能识别到zfs的存储池必须要先将zpool import,而且小镇不推荐zfs开启自动启动,原因请百度。如果能详细控制服务启动顺序,就能更好的掌控过程。

脚本包含总共3个文件:


ip.txt写入需要启动的服务器ip。

localstart.sh用于启动本地服务。

auto_gluster.sh用于远程连接传递localstart.sh并执行


localstart.sh

#!/bin/bash

#zpool的名称
pool_name="diskstation"

#判断zpool状态,如没导入便import
pool_status=`zpool list`
if [ "no pools available" == "$pool_status" ];then
  zpool import $pool_name
fi

#判断glusterd的状态,如没有启动则启动
gluster_status=`systemctl status glusterd.service|grep Active`
if [[ "$gluster_status" =~ "dead" ]];then
  systemctl start  glusterd.service
fi

auto_gluster.sh

#!/bin/bash
user='root'
passwd='zhentianyu28'

for ip in `cat ip.txt`
  do
    /usr/bin/expect <<-EOF
	  spawn scp localstart.sh $user@$ip:/root
	  expect {
		"yes/no" { send "yes\r"; exp_continue}
		"password:" { send "$passwd\r" }
	  }
	  spawn ssh -p 22 $user@$ip
	  expect {
		"yes/no" { send "yes\r"; exp_continue}
		"password:" { send "$passwd\r" }
	  }
	  expect "*#"
	  send "chmod +x /root/localstart.sh\r"
	  expect "*#"
	  send "/root/localstart.sh\r"
	  expect "*#"
	EOF
  done

  
chmod +x `pwd`/localstart.sh
`pwd`/localstart.sh

while [ 1 == 1 ]
do
  gluster_status=`gluster peer status|grep Disconnected`
  if [ -z "$gluster_status" ];then
    break  
  fi
  sleep 1
done

mount -t glusterfs 192.168.1.130:zt-volume /opt/zty

exit
在1.130上执行auto_gluster.sh就可以了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值