昨天有位哥们儿看了我的文章后向我反应安装完毕服务器重启后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就可以了。