单台节点维护多服务器脚本

平时很多时候,想在一台几点维护其他机器,可以写成这样的单个脚本,在单台服务器执行进行维护:

#!/bin/bash
# 存放位置:/usr/bin/xxx ;chmod +x ;
func_usage()
{
echo usage: xxx args
echo args:
cat << EOF
参数                       说明
---------------------------------------------
jps                        java 进程
df                         磁盘使用状态
free                       机器空闲状态
ps xxx                     查看xxx进程
reboot                     重启服务器
shutdown                   关闭服务器

startmysql                 启动 mysql
stopmysql                  关闭 mysql
mysqlstatus                mysql 状态

startzk                    启动 zkServer
stopzk                     关闭 zkServer
zktatus                    zkServer 状态

startkafka                 启动 kafkaServer
stopkafka                  关闭 kafkaServer

starhadoop                 启动hadoop
stophadoop                 关闭hadoop

starthive                  启动hive
stophive                   关闭hive

startspark                 启动spark
stopspark                  关闭spark

starthbase                 启动hbase
stophbase                  关闭hbase

startdoris                 启动doris
stopdoris                  关闭doris


beeline                    启动beeline

startck                    启动 clickhouse
stopck                     关闭 clickhouse
ckstatus                   clickhouse 状态

EOF
}

#2 获取文件名称
p1=$1
p2=$2
echo $p1
echo $p2

case $1 in 
	"startmysql")
        echo -------------------lsyk01 -----------;
		echo "mysql.server start"
		echo "   "
        /opt/mysql-5.7.29/support-files/mysql.server start;
;;

	"stopmysql")
        echo -------------------lsyk01 -----------;
		echo "mysql.server stop"
		echo "   "
        /opt/mysql-5.7.29/support-files/mysql.server stop;     
;;

	"mysqlstatus")
        echo -------------------lsyk01 -----------;
		echo "mysql.server status"
		echo "   "
        /opt/mysql-5.7.29/support-files/mysql.server status;       
;;


	"startzk")
		for i in lsyk01 lsyk02 lsyk03
			do 
				echo -------------------------------- $i zookeeper 启动 ---------------------------
				echo "zkServer.sh start"
				ssh $i "source /etc/profile;/opt/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start;"
				echo "   "
		done
;;       

	"stopzk")
		for i in lsyk01 lsyk02 lsyk03
			do 
				echo -------------------------------- $i zookeeper 关闭 ---------------------------
				echo "zkServer.sh stop"
				ssh $i "source /etc/profile;/opt/apache-zookeeper-3.6.3-bin/bin/zkServer.sh stop;"
				echo "   "
		done
;;       
        
	"zkstatus")
		for i in lsyk01 lsyk02 lsyk03
			do 
				echo -------------------------------- $i zookeeper 状态 ---------------------------
				echo "zkServer.sh status"
				ssh $i "source /etc/profile;/opt/apache-zookeeper-3.6.3-bin/bin/zkServer.sh status;"
				echo "   "
		done
;;       
        
	"startkafka")
		for i in lsyk01 lsyk02 lsyk03
			do 
				echo -------------------------------- $i kafka 启动 ---------------------------
				echo "kafka-server-start.sh -daemon /opt/kafka_2.13-3.2.0/config/server.properties"
				ssh $i "source /etc/profile;/opt/kafka_2.13-3.2.0/bin/kafka-server-start.sh -daemon /opt/kafka_2.13-3.2.0/config/server.properties"
				echo "   "
		done
;;
	"stopkafka")
		for i in lsyk01 lsyk02 lsyk03
			do 
				echo -------------------------------- $i kafka 停止 ---------------------------
				echo "kafka-server-stop.sh"
				ssh $i "source /etc/profile;/opt/kafka_2.13-3.2.0/bin/kafka-server-stop.sh"
				echo "   "
		done
;;


	"beeline")
        echo -------------------lsyk01 -----------;
		echo "beeline -u jdbc:hive2://lsyk01:10000 -n root"
		echo "   "
        beeline -u jdbc:hive2://lsyk01:10000 -n root;      
;;



	"starthadoop")
		echo "启动all..."
        echo -------------------lsyk01 -----------;
		echo "start-all.sh"
		echo "   "
        $HADOOP_HOME/sbin/start-all.sh;
		sleep 3
		echo "启动mr历史服务..."
        echo -------------------lsyk01 -----------;
		echo "mapred --daemon start historyserver"
		echo "   "
        mapred --daemon start historyserver;      

;;

	"stophadoop")
		echo "关闭mr历史服务..."
        echo -------------------lsyk01 -----------;
		echo "mapred --daemon stop historyserver"
		echo "   "
        mapred --daemon stop historyserver;   
		sleep 3	
		echo "关闭all..."
        echo -------------------lsyk01 -----------;
		echo "stop-all.sh"
		echo "   "
        $HADOOP_HOME/sbin/stop-all.sh;     

;;

	"starthive")
		echo "启动mysql..."
        echo -------------------lsyk01 -----------;
		echo "mysql.server start"
		echo "   "
        /opt/mysql-5.7.29/support-files/mysql.server start;     
		sleep 3
		echo "启动hive..."
        echo -------------------lsyk01 -----------;
		echo "nohup hive --service metastore 2>&1 &"
		echo "   "
        nohup hive --service metastore 2>&1 & 
		sleep 3
		echo "nohup hive --service hiveserver2 2>&1 &"
		echo "   "
        nohup hive --service hiveserver2 2>&1 & 

;;



	"stophive")
		echo "关闭hive..."
        echo -------------------lsyk01 -----------;
		echo "ps -ef 2>/dev/null | grep -v grep | grep -i hiveserver2 | awk '{print $2}' | xargs kill -9>"
		echo "   "
        ps -ef 2>/dev/null | grep -v grep | grep -i hiveserver2 | awk '{print $2}' | xargs kill -9;  
		sleep 3
		echo "ps -ef 2>/dev/null | grep -v grep | grep -i hivemetastore | awk '{print $2}' | xargs kill -9"
		echo "   "
        ps -ef 2>/dev/null | grep -v grep | grep -i hivemetastore | awk '{print $2}' | xargs kill -9;    
		sleep 3

		echo "关闭mysql..."
        echo -------------------lsyk01 -----------;
		echo "mysql.server stop"
		echo "   "
        /opt/mysql-5.7.29/support-files/mysql.server stop;       

;;


	"startspark")
        echo -------------------lsyk01 -----------;
		echo "$SPARK_HOME/sbin/start-all.sh"
		echo "   "
        $SPARK_HOME/sbin/start-all.sh; 
		sleep 3
		echo "$SPARK_HOME/sbin/start-history-server.sh"
		echo "   "
        $SPARK_HOME/sbin/start-history-server.sh; 
;;

	"stopspark")
        echo -------------------lsyk01 -----------;
		echo "$SPARK_HOME/sbin/stop-history-server.sh"
        $SPARK_HOME/sbin/stop-history-server.sh; 
		sleep 3
		echo "   "
		echo "$SPARK_HOME/sbin/stop-all.sh"
		echo "   "
        $SPARK_HOME/sbin/stop-all.sh; 		
;;


	"starthbase")
        echo -------------------lsyk01 -----------;
		echo "$HBASE_HOME/bin/start-hbase.sh"
		echo "   "
        $HBASE_HOME/bin/start-hbase.sh; 		
;;


	"stophbase")
        echo -------------------lsyk01 -----------;
		echo "$HBASE_HOME/bin/stop-hbase.sh"
		echo "   "
        $HBASE_HOME/bin/stop-hbase.sh; 		
;;

	"startdoris")
        echo -------------------lsyk01 -----------;
		echo "$DORIS_HOME/fe/bin/start_fe.sh --daemon"
		echo "   "
        $DORIS_HOME/fe/bin/start_fe.sh --daemon; 	
		sleep 3
		for i in lsyk02 lsyk03 lsyk04
			do 
				echo -------------------------------- $i doris 启动 ---------------------------
				echo "$DORIS_HOME/be/bin/start_be.sh --daemon;"
				ssh $i $DORIS_HOME/be/bin/start_be.sh --daemon;
				echo "   "
		done	
				
;;


	"stopdoris")        
		for i in lsyk02 lsyk03 lsyk04
			do 
				echo -------------------------------- $i doris 启动 ---------------------------
				echo "$DORIS_HOME/be/bin/stop_be.sh;"
				ssh $i $DORIS_HOME/be/bin/stop_be.sh;
				echo "   "
		done
			
		echo -------------------lsyk01 doris 关闭 -----------;
		echo "$DORIS_HOME/fe/bin/stop_fe.sh"
		echo "   "
        $DORIS_HOME/fe/bin/stop_fe.sh; 
				
;;

	"startck")
		for i in lsyk01 lsyk02 lsyk03
			do 
				echo -------------------------------- $i clickhouse 启动 ---------------------------
				echo "clickhouse start"
				ssh $i "export BASH_ENV=/etc/profile;/usr/bin/clickhouse start;"
				echo "   "
		done
		
;;

	"stopck")
		for i in lsyk01 lsyk02 lsyk03
			do 
				echo -------------------------------- $i clickhouse 关闭 ---------------------------
				echo "clickhouse stop"
				ssh $i "export BASH_ENV=/etc/profile;/usr/bin/clickhouse stop;"
				echo "   "
		done
		
;;

	"ckstatus")
		for i in lsyk01 lsyk02 lsyk03
			do 
				echo -------------------------------- $i clickhouse 状态 ---------------------------
				echo "clickhouse status"
				ssh $i "export BASH_ENV=/etc/profile;/usr/bin/clickhouse status;"
				echo "   "
		done
;;



##############################

	"startCDH")
        echo -------------------lsyk01 -----------;
        ssh lsyk01 systemctl start cloudera-scm-server;
        ssh lsyk01 systemctl start cloudera-scm-agent;
        echo -------------------lsyk02 -----------;
        ssh lsyk02 systemctl start cloudera-scm-agent;
        echo -------------------lsyk03 -----------;
        ssh lsyk03 systemctl start cloudera-scm-agent;
		echo -------------------lsyk04 -----------;
        ssh lsyk04 systemctl start cloudera-scm-agent;
		echo -------------------lsyk05 -----------;
        ssh lsyk05 systemctl start cloudera-scm-agent;
;;

	"stopCDH")
        echo -------------------lsyk02 -----------;
        ssh lsyk02 systemctl start cloudera-scm-agent;
        echo -------------------lsyk03 -----------;
        ssh lsyk03 systemctl start cloudera-scm-agent;
		echo -------------------lsyk04 -----------;
        ssh lsyk04 systemctl start cloudera-scm-agent;
		echo -------------------lsyk05 -----------;
        ssh lsyk05 systemctl start cloudera-scm-agent;
        echo -------------------lsyk01 -----------      ;
        ssh lsyk01 systemctl start cloudera-scm-agent;
        ssh lsyk01 systemctl start cloudera-scm-server;
;;



	"free")
		for i in lsyk01 lsyk02 lsyk03 lsyk04 lsyk05
			do 
				echo -------------------------------- $i free -h ---------------------------
				ssh $i free -h
				echo "   "
		done
;;

	"df")
		for i in lsyk01 lsyk02 lsyk03 lsyk04 lsyk05
			do 
				echo -------------------------------- $i df -h ---------------------------
				ssh $i df -h
				echo "   "
		done

;;

	"ps")
		for i in lsyk01 lsyk02 lsyk03 lsyk04 lsyk05
			do 
				echo -------------------------------- $i ps  "$p2" ---------------------------
				ssh $i ps -ef |grep -i "$p2" ;
				echo "   "
		done

;;

	"reboot")
		for i in  lsyk02 lsyk03 lsyk04 lsyk05 lsyk01
			do 
				echo -------------------------------- $i reboot ---------------------------
				ssh $i reboot;
				echo "   "
		done
		
;;

	"shutdown")
		for i in  lsyk02 lsyk03 lsyk04 lsyk05 lsyk01
			do 
				echo -------------------------------- $i shutdown -h now ---------------------------
				ssh $i shutdown -h now;
				echo "   "
		done

;;

	"jps")
		for i in lsyk01 lsyk02 lsyk03 lsyk04 lsyk05
			do 
				echo -------------------------------- $i jps ---------------------------
				ssh $i "export BASH_ENV=/etc/profile; /usr/java/jdk1.8.0_333/bin/jps;"
				echo "   "
		done
		
;;


	"start-dfs.sh")
        echo -------------------lsyk01 -----------;
		echo "start-dfs.sh"
		echo "   "
        start-dfs.sh;
;;

	"stopdfs.sh")
        echo -------------------lsyk01 -----------;
		echo "stop-dfs.sh"
		echo "   "
        stop-dfs.sh;     
;;

	"startyarn.sh")
        echo -------------------lsyk01 -----------;
		echo "start-yarn.sh"
		echo "   "
        start-yarn.sh;      
;;

	"stopyarn.sh")
        echo -------------------lsyk01 -----------;
		echo "stop-yarn.sh"
		echo "   "
        stop-yarn.sh;      
;;

	"startmrhis")
        echo -------------------lsyk01 -----------;
		echo "mapred --daemon start historyserver"
		echo "   "
        mapred --daemon start historyserver;      
;;

	"stopmrhis")
        echo -------------------lsyk01 -----------;
		echo "mapred --daemon stop historyserver"
		echo "   "
        mapred --daemon stop historyserver;      
;;

	*)
		func_usage

;;

esac

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值