rocketmq 集群启动停止脚本 rocketmq集群namesrv脚本 rocketmq集群broker集群start stop脚本 rocketmq集群一键启动,停止傻瓜脚本

1. 当前模式为三台机器:worker1,worker2, worker3

2. 当前模式为三个注册中心,两个broker-a, broker-a-s, broker-b, broker-b-s

3. 脚本:

#!/bin/bash

ROCKETMQ_PATH="/opt/module/rocketmq-all-5.1.4-bin-release/bin"

# 检查输入参数
if [ "$#" -ne 1 ]; then
    echo "使用方法: $0 "
    exit 1
fi


function start_cluster() {
	echo "*******************准备启动注册中心*******************"
		for host in worker1 worker2 worker3;do
			echo "当前节点:$host"
			#ssh -t -t $host << EOF
			ssh -T $host << EOF
			cd "$ROCKETMQ_PATH"
			#echo $(pwd)
			nohup ./mqnamesrv > startNameServer.log 2>&1 &
			echo "启动中..."
			#jps
			exit
EOF
			current_time=$(date +"%Y-%m-%d %H:%M:%S")
			echo "当前节点:$host注册中心启动成功 date=${current_time}*******************"
		done

		sleep 2
		current_time2=$(date +"%Y-%m-%d %H:%M:%S")
		echo "休眠结束。date=$current_time2"
		# 等待 NamesrvStartup 进程启动成功
		
		echo "****************************************************************"
		echo "*                                                               *"
		echo "*******************准备启动worker2节点broker.*******************"
		echo "*                                                               *"
		echo "****************************************************************"
		ssh -T worker2 << EOF
           echo "等待 NamesrvStartup 进程启动成功..."
           until jps | grep NamesrvStartup; do
				sleep 5
           done
		   echo "准备启动worker2节点broker"
		   cd "$ROCKETMQ_PATH"
		   # 启动worker2节点 broker-a
		   echo "启动worker2节点的 broker-a"
		   nohup ./mqbroker -c ../conf/2m-2s-async/broker-a.properties  > /dev/null 2>&1 &
		   # 启动 brokder-b-s
		   sleep 2
		   echo "启动worker2节点的 broker-b-s"
		   nohup ./mqbroker -c ../conf/2m-2s-async/broker-b-s.properties > /dev/null 2>&1  &
		   exit
EOF
		# 连接worker3
		echo "****************************************************************"
		echo "*                                                               *"
		echo "*******************准备启动worker3节点broker.*******************"
		echo "*                                                              *"
		echo "****************************************************************"
		ssh -T worker3 << EOF
			echo "等待 NamesrvStartup 进程启动成功..."
			until jps | grep NamesrvStartup; do
					sleep 5
			done
			echo "准备启动worker3节点broker"
			cd "$ROCKETMQ_PATH"
			# 启动worker3节点 broker-b
			echo "启动worker3节点的 broker-b"
			nohup ./mqbroker -c ../conf/2m-2s-async/broker-b.properties > /dev/null 2>&1  &
			sleep 2
			# 启动 brokder-b-s
			echo "启动worker2节点的 broker-a-s"
			nohup ./mqbroker -c ../conf/2m-2s-async/broker-a-s.properties > /dev/null 2>&1 &
			exit
EOF
		echo "*******************注册中心集群启动成功,broker集群启动成功*******************"

}

function stop_cluster() {
	echo "==================准备停止broker集群========================"
		echo "停止worker2节点broker"
		ssh -T worker2 << EOF
		cd "$ROCKETMQ_PATH"
		./mqshutdown broker
		exit
EOF
		echo "停止worker3节点broker"
		ssh -T worker3 << EOF
		cd "$ROCKETMQ_PATH"
		./mqshutdown broker
		exit
EOF
	
		echo "===================准备停止注册中心========================="
		for host in worker2 worker3 worker1;do
			echo "******************* $host *******************"
			#ssh -t -t $host << EOF
			ssh -T $host << EOF
			cd "$ROCKETMQ_PATH"
			#HOST_NAME=\$(cat /proc/sys/kernel/hostname)
			#HOST_NAME=$(ssh -t $host 'hostname')
			#echo "ceshi..=========================$HOST_NAME"
			#echo $HOST_NAME
			if [ "$host" = "worker2" ] || [ "$host" = "worker3" ]; then
				echo "$host 等待broker结束"
				until ! jps | grep -v grep | grep BrokerStartup; do
					sleep 5
				done
			fi
			#echo $(pwd)
			./mqshutdown namesrv
			echo "已下线注册中心..."
			#jps
			exit
EOF
		done

}



# 判断输入参数是start还是stop
case "$1" in
	"start")
		start_cluster
		;;
	"stop")
		stop_cluster
		;;
	*)
		echo "未知操作:$1"
		exit 1
		;;
esac

4. 如使用有问题,可酌情修改

你可能感兴趣的:(rocketmq,rocketmq,linux,运维)