同步执行命令脚本xcall
- 在一个节点上输入命令可以同步到其余节点执行
- 脚本目录:
/use/local/bin/
进入/use/local/bin/目录 vim一个xcall.sh的文件
cd /use/local/bin
vim xcall.sh
插入以下代码
#!/bin/sh
pcount=$#
if((pcount==0));then
echo no args...;
exit;
fi
echo ==================masternode==================
$@
echo ==================namenode==================
ssh namenode $@
for((host=0; host<=1; host++)); do
echo ==================slave$host==================
ssh slave$host $@
done
masternode和namenode都是主机名,逻辑很简单,可以对应修改
赋予其权限
chmod +x xcall.sh
软连接jps
每台机器上都要进行软连接
ln -s /root/bigdata/jdk/jdk1.8.0_144/bin/jps /usr/local/bin/jps
运行结果
Zookeeper
和xcall一样,将这些脚本放到/usr/local/bin/
目录下然后赋予其执行权限就可一键启动/关闭/查看状态zookeeper
zkstart.sh
for host in masternode namenode slave0
do
echo "===============$host================"
ssh $host "source /root/bigdata/zookeeper/apache-zookeeper-3.5.7-bin/bin/zkServer.sh start"
echo "$host zk is running..."
done
zkstop.sh
for host in masternode namenode slave0
do
echo "===============$host================"
ssh $host "source /root/bigdata/zookeeper/apache-zookeeper-3.5.7-bin/bin/zkServer.sh stop"
echo "$host zk is stopping..."
done
zkstatus.sh
for host in masternode namenode slave0
do
echo "===============$host================"
ssh $host "source /root/bigdata/zookeeper/apache-zookeeper-3.5.7-bin/bin/zkServer.sh status"
done