当前位置:网站首页>Common cluster scripts

Common cluster scripts

2022-06-25 06:41:00 BigData_ LYT

Take three nodes as an example
First of all to enter /root/bin Under the table of contents

cd /root/bin

View all nodes java process (jpsall)

establish jpsal file

vim jpsall

Enter the following

#!/bin/bash
for host in master node1 node2
do
	echo =============== $host ===============
	ssh $host jps 
done

to jpsall File permissions

chmod 777 jpsall

Run with the following command

jasall

Restart all nodes (reboot.sh)

establish reboot.sh file

vim reboot.sh

Enter the following

#!/bin/bash
for i in node2 node1 master
do
	echo ============== $i  restart  =============
	ssh $i "sudo reboot"
	sleep 1s;
done

to reboot.sh File permissions

chmod 777 reboot.sh

Run with the following command

reboot.sh

Close all nodes (shutdown.sh)

establish shutdown.sh file

vim shutdown.sh

Enter the following

#!/bin/bash
for i in node2 node1 master
do
	echo ============= $i  To turn it off  =============
	ssh $i "sudo shutdown -h now"
	sleep 1s;
done

to shutdown.sh File permissions

chmod 777 shutdown.sh

Run with the following command

shutdown.sh

Synchronize files to other nodes (xsync)

establish xsync file

vim xsync

Enter the following

#!/bin/bash
#1.  Judge the number of parameters 
if [ $# -lt 1 ]
then
    echo Not Enough Arguement!
    exit;
fi

#2.  Traverse all machines in the cluster 
for host in master node1 node2
do
    echo ====================  $host  ====================
    #3.  Traverse all directories , Send... One by one 

    for file in [email protected]
    do
        #4.  Judge whether the file exists 
        if [ -e $file ]
            then
                #5.  Get parent directory 
                pdir=$(cd -P $(dirname $file); pwd)

                #6.  Get the name of the current file 
                fname=$(basename $file)
                ssh $host "mkdir -p $pdir"
                rsync -av $pdir/$fname $host:$pdir
            else
                echo $file does not exists!
        fi
    done
done

to xsync File permissions

chmod 777 xsync

Run with the following command

xsync  File path 

ZooKeeper Cluster startup 、 Off and status (zk.sh)

establish zk.sh file

vim zk.sh

Enter the following

#!/bin/bash
if [ $# -lt 1 ]
 then 
   echo "NO Args Input Error!!!"
   exit     
fi
case $1 in
"start") {
	for i in master node1 node2
	do
		echo ============= zookeeper $i  start-up  =============
		ssh $i "source /etc/profile;/usr/local/soft/zookeeper-3.4.6/bin/zkServer.sh start"
	done
}
;;
"stop") {
	for i in master node1 node2
	do
		echo ============= zookeeper $i  stop it  =============
		ssh $i "source /etc/profile;/usr/local/soft/zookeeper-3.4.6/bin/zkServer.sh stop"
	done
}
;;
"status") {
	for i in master node1 node2
	do
		echo ============= zookeeper $i  state  =============
		ssh $i "source /etc/profile;/usr/local/soft/zookeeper-3.4.6/bin/zkServer.sh status"
	done
}
;;
*)
echo "Input args Error!!"
;;
esac

to zk.sh File permissions

chmod 777 zk.sh

Run with the following command

zk.sh start
zk.sh status
zk.sh stop

kafka Startup and shutdown of cluster (kk.sh)

establish kk.sh file

vim kk.sh

Enter the following

#!/bin/bash
case $1 in
"start"){
        for i in master node1 node2
                do
                        echo ========$i  start-up kafka========
                        ssh $i "source /etc/profile;/usr/local/soft/kafka_2.11-1.0.0/bin/kafka-server-start.sh -daemon /usr/local/soft/kafka_2.11-1.0.0/config/server.properties"
                done
};;
"stop"){
        for i in master node1 node2
                do
                        echo ========$i  stop it kafka========
                        ssh $i "source /etc/profile;/usr/local/soft/kafka_2.11-1.0.0/bin/kafka-server-stop.sh stop"
                done
};;
esac

to kk.sh File permissions

chmod 777 kk.sh

Run with the following command

kk.sh start
kk.sh stop

原网站

版权声明
本文为[BigData_ LYT]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250430554920.html