#!/bin/sh array=(‘192.168.147.128‘ ‘192.168.147.129‘ ‘192.168.147.131‘) path="/usr/local/zookeeper/bin/" for var in ${array[*]} do process_count=$(ssh $var ‘ps -ef|grep zookeeper |grep -v grep |wc -l‘) if [ "$process_count" -eq 1 ];then echo -e "($var)的zookeeper服务正常" res1=$(ssh $var ‘sh $pathzkServer.sh status | grep -w follower | wc -l‘) if [[ $res1 -eq 1 ]];then echo "($var)是从节点" else echo "($var)是主节点" fi else echo -e "($var)的zookeeper服务未启动" fi done
由于中间做测试任务去了,现在接着之前一篇的文章(https://www.cnblogs.com/qianjunjun/p/13915442.html)继续写
直接贴shell脚本如上
简单解释下思路:将zookeeper所在的服务器ip放到一个数组里面,遍历查询每台服务的zookeeper服务状态,路径也做下参数化,方便修改。
通过远程连接批量查看zookeeper服务状态和判断主从节点
原文:https://www.cnblogs.com/qianjunjun/p/14080679.html