大数据环境部署之集群启动脚本

2022-11-14 14:55:45 浏览数 (1)

创建脚本

集群进程查看脚本

创建脚本

代码语言:javascript复制
mkdir /data/tools/bigdata/mysh/
vi /data/tools/bigdata/mysh/ha-call.sh

内容如下

代码语言:javascript复制
#!/bin/bash

#集群所有进程查看脚本

USAGE="使用方法:sh ha-call.sh jps or sh ha-call.sh 'jps -l;java -version'"
if [ $# -eq 0 ];then
        echo $USAGE
        exit 1
fi
NODES=("hadoop01" "hadoop02" "hadoop03")
for NODE in ${NODES[*]};do
        echo "--------$NODE--------"
        ssh $NODE "$*"
done
echo "----------------------------------------------------------------------------------------"
echo "--------ha-call.sh 脚本执行完成!--------"
echo "----------------------------------------------------------------------------------------"

修改权限

代码语言:javascript复制
chmod 777 /data/tools/bigdata/mysh/ha-call.sh

测试

代码语言:javascript复制
ha-call.sh jps
#或者
ha-call.sh 'jps -l;java -version'

集群ZK启动脚本

创建脚本

代码语言:javascript复制
mkdir /data/tools/bigdata/mysh/
vi /data/tools/bigdata/mysh/ha-zk.sh

内容如下

代码语言:javascript复制
#!/bin/bash

#zookeeper集群启动/停止/查看状态脚本

USAGE="使用方法:sh ha-zk.sh start/stop/status"
if [ $# -ne 1 ];then
        echo $USAGE
        exit 1
fi
NODES=("hadoop01" "hadoop02" "hadoop03")

case $1 in
"start")
        for NODE in ${NODES[*]};do
                echo "--------$NODE启动zookeeper--------"
                ssh $NODE "$ZK_HOME/bin/zkServer.sh start"
        done
        ;;
"stop")
        for NODE in ${NODES[*]};do
                echo "--------$NODE停止zookeeper--------"
                ssh $NODE "$ZK_HOME/bin/zkServer.sh stop"
        done
        ;;
"status")
        for NODE in ${NODES[*]};do
                echo "--------$NODE查看zookeeper状态--------"
                ssh $NODE "$ZK_HOME/bin/zkServer.sh status"
        done
        ;;
*)
        echo $USAGE
        ;;
esac
echo "----------------------------------------------------------------------------------------"
echo "--------ha-zk.sh脚本执行完成!--------"
echo "----------------------------------------------------------------------------------------"

修改权限

代码语言:javascript复制
chmod 777 /data/tools/bigdata/mysh/ha-zk.sh

测试

代码语言:javascript复制
ha-zk.sh start
ha-zk.sh stop
ha-zk.sh status

集群Hadoop启动脚本

依赖ZK

创建脚本

代码语言:javascript复制
mkdir /data/tools/bigdata/mysh/
vi /data/tools/bigdata/mysh/ha-hadoop.sh

内容如下

代码语言:javascript复制
#!/bin/bash

#ha-hadoop集群启动停止以及查看进程脚本

USAGE="使用方法:sh ha-hadoop.sh start/stop/status"
if [ $# -ne 1 ];then
	echo $USAGE
	exit 1
fi

NODES=("hadoop01" "hadoop02" "hadoop03")
case $1 in
"start")	
	#开始启动ha-hadoop集群
	for NODE in ${NODES[*]};do
		echo "--------$NODE启动ha-hadoop集群--------"
		if [ "hadoop01" = $NODE ];then
			ssh $NODE "$HADOOP_HOME/sbin/start-dfs.sh && $HADOOP_HOME/sbin/mr-jobhistory-daemon.sh start historyserver"		
		fi
		if [ "hadoop02" = $NODE ];then
			ssh $NODE "$HADOOP_HOME/sbin/yarn-daemon.sh start resourcemanager"	
		fi
		if [ "hadoop03" = $NODE ];then
			ssh $NODE "$HADOOP_HOME/sbin/start-yarn.sh"	
		fi
	done
	;;
"stop")
	#开始停止ha-hadoop集群
	for NODE in ${NODES[*]};do
		echo "--------$NODE停止ha-hadoop集群--------"
		if [ "hadoop01" = $NODE ];then
			ssh $NODE "$HADOOP_HOME/sbin/stop-dfs.sh && $HADOOP_HOME/sbin/mr-jobhistory-daemon.sh stop historyserver"		
		fi
		if [ "hadoop02" = $NODE ];then
			ssh $NODE "$HADOOP_HOME/sbin/yarn-daemon.sh stop resourcemanager"	
		fi
		if [ "hadoop03" = $NODE ];then
			ssh $NODE "$HADOOP_HOME/sbin/stop-yarn.sh"	
		fi
	done
	;;
"status")
	for NODE in ${NODES[*]};do
		echo "--------$NODE查看ha-hadoop集群进程--------"
		ssh $NODE "jps"	
	done
	;;
*)
	echo $USAGE 
	;;
esac
echo "----------------------------------------------------------------------------------------"
echo "--------ha-hadoop.sh脚本执行完成!--------"
echo "----------------------------------------------------------------------------------------"

修改权限

代码语言:javascript复制
chmod 777 /data/tools/bigdata/mysh/ha-hadoop.sh

测试

代码语言:javascript复制
ha-hadoop.sh start
ha-hadoop.sh stop
ha-hadoop.sh status

集群Flink启动脚本

依赖ZK和Hadoop

创建脚本

代码语言:javascript复制
mkdir /data/tools/bigdata/mysh/
vi /data/tools/bigdata/mysh/ha-flink.sh

内容如下

代码语言:javascript复制
#!/bin/bash

#ha-flink集群(yarn模式)启动停止以及进程查看脚本

USAGE="使用方法:sh ha-flink.sh start/stop/status"
if [ $# -ne 1 ];then
	echo $USAGE
	exit 1
fi


NODES=("hadoop01" "hadoop02" "hadoop03")

case $1 in
"start")
	#开始启动ha-flink集群
	for NODE in ${NODES[*]};do
		echo "--------$NODE启动ha-flink集群--------"
		if [ "hadoop01" = $NODE  ];then
			ssh $NODE "$FLINK_HOME/bin/start-cluster.sh && $FLINK_HOME/bin/historyserver.sh start"
		fi
	done
	;;
"stop")
	#开始停止ha-flink集群
	for NODE in ${NODES[*]};do
		echo "--------$NODE停止ha-flink集群--------"
		if [ "hadoop01" = $NODE  ];then
			ssh $NODE "$FLINK_HOME/bin/stop-cluster.sh && $FLINK_HOME/bin/historyserver.sh stop"
		fi
	done
	;;
"status")
	echo "--------查看ha-flink集群进程信息"
	for NODE in ${NODES[*]};do
		echo "--------$NODE 查看ha-flink集群进程--------"
		ssh $NODE "jps"	
	done
	;;
*)
	echo $USAGE
	;;
esac
echo "----------------------------------------------------------------------------------------"
echo "--------ha-flink.sh 脚本执行完成!--------"
echo "----------------------------------------------------------------------------------------"

修改权限

代码语言:javascript复制
chmod 777 /data/tools/bigdata/mysh/ha-flink.sh

测试

代码语言:javascript复制
ha-flink.sh start
ha-flink.sh status
ha-flink.sh stop

配置环境变量

之前配置过可以跳过。

添加环境变量

代码语言:javascript复制
cd /etc/profile.d/

创建配置文件

代码语言:javascript复制
vi /etc/profile.d/mysh.sh

加入:

代码语言:javascript复制
export MYSH_HOME=/data/tools/bigdata/mysh/ 
export PATH=$MYSH_HOME:$PATH

配置立即生效

代码语言:javascript复制
source /etc/profile

查看MYSH_HOME

代码语言:javascript复制
echo $MYSH_HOME

配置分发

代码语言:javascript复制
distribution.sh $MYSH_HOME
ssh hadoop02 "source /etc/profile"
ssh hadoop03 "source /etc/profile"

0 人点赞