One-click shell script to start hadoop, zookeeper and jps to view all nodes

Not much to say, just go to the script.

Start hadoop:

#!/bin/sh

#start hdfs
echo "hdfs is starting..."
ssh hadoop102 "/opt/module/hadoop-2.7.2/sbin/start-dfs.sh"

#start yarn
echo "yarn is starting..."
ssh hadoop103 "/opt/module/hadoop-2.7.2/sbin/start-yarn.sh"

It should be noted here that my main node is hadoop102, the child nodes are hadoop103 and hadoop104 hdfs are on 102, and yarn is on 103 .

Close hadoop:

#!/bin/sh


#stop yarn
echo "yarn is stoping..."
ssh hadoop103 "/opt/module/hadoop-2.7.2/sbin/stop-yarn.sh"

#stop hdfs
echo "hdfs is stoping..."
ssh hadoop102  "/opt/module/hadoop-2.7.2/sbin/stop-dfs.sh"

echo "hadoop is stopped"

Start zookeeper

#!/bin/sh

for i  in root@hadoop102 root@hadoop103 root@hadoop104
do
    echo "the zookeeper in $i  is start..."
   ssh $i "source /etc/profile;/opt/module/zookeeper-3.4.10/bin/zkServer.sh start"
done

Close zookeeper

#!/bin/bash
for i  in root@hadoop102 root@hadoop103 root@hadoop104
do
    echo "the zookeeper in $i  is stop..."
    ssh $i "source /etc/profile;/opt/module/zookeeper-3.4.10/bin/zkServer.sh stop"
done

It should be noted here that you must source /etc/profile, because zookeeper depends on jdk, but SSH login does not read the file where jdk environment variables are located, so JAVA_HOME can be read by source .

View the progress of all nodes with one click

#!/bin/sh

for i  in root@hadoop102 root@hadoop103 root@hadoop104
do
    echo "===================== $i ======================="
    ssh $i  '/opt/module/jdk1.8.0_144/bin/jps'
done

We can echo PATH

Insert picture description here

/usr/local/bin is already in the path, so we can put all the above scripts in this directory, so that we can run these scripts no matter which directory we execute in.

Guess you like

Origin blog.csdn.net/weixin_44080445/article/details/108911725