(2)编写脚本zk_start_ssh.sh #/bin/bash ZKSERVERS=(192.168.22.135 192.168.25.136 192.168.25.137) echo ==========总共${#ZKSERVERS[@]}台服务器========== for SERVER in ${ZKSERVERS[@]} do dat=`date '+%Y-%m-%d %H:%M:%S'` echo ========start zookeeper $SERVER $dat =========== ssh root@$SERVER "source /etc/profile;/opt/apps/zookeeper-3.4.13/bin/zkServer.sh start;exit;" echo ========start zookeeper $SERVER success $dat=========== done echo ==========自动化脚本任务执行完成========== ~ (3)编写脚本zk_kill_ssh.sh #/bin/bash ZKSERVERS=(192.168.22.135 192.168.29.136 192.168.22.137) echo ==========总共${#ZKSERVERS[@]}台服务器========== for SERVER in ${ZKSERVERS[@]} do dat=`date '+%Y-%m-%d %H:%M:%S'` echo ========kill zookeeper $SERVER $dat =========== ssh root@$SERVER "ps -ef | grep 'zookeeper' | grep -v grep | awk '{print \$2}'| xargs kill;exit;" echo ========kill zookeeper $SERVER success $dat=========== done echo ==========自动化脚本任务执行完成==========