1、部署规划-3台服务器
(1)服务器准备
- 192.168.0.1(主)
- 192.168.0.2(从)
- 192.168.0.3(从)
(2)核对空间,内存
- df -h
- free -h
(3)确认启动用户及部署路径
- 用户:applin【确认有应用路径的写入执行权限,755,或应用路径归属于applin】
- 应用路径:/software/
- 数据存储路径:/software/rocketmq-all-5.0.0-bin-release/store
- 日志存储路径:/software/rocketmq-all-5.0.0-bin-release/logs
2、获取rocketmq-5.0.0版本并上传到服务器
(1)获取文件
(2)通过WinScp或其他上传包文件到指定服务器路径
- 192.168.0.1:/software/rocketmq-all-5.0.0-bin-release.zip
- 192.168.0.2:/software/rocketmq-all-5.0.0-bin-release.zip
- 192.168.0.3:/softwarerocketmq-all-5.0.0-bin-release.zip
3、dleger高可用集群部署
3.1、3台服务器统一操作
(1)新建日志+数据存储路径
bash
cd /software
unzip rocketmq-all-5.0.0-bin-release.zip
su - applin
mkdir -p /software/rocketmq-all-5.0.0-bin-release/store
mkdir -p /software/rocketmq-all-5.0.0-bin-release/logs
cd /software/rocketmq-all-5.0.0-bin-release
(2)修改日志路径
bash
执行命令1: cd /software/rocketmq-all-5.0.0-bin-release/conf
执行命令2: sed -i 's?${user.home}/logs/rocketmqlogs?/software/rocketmq-all-5.0.0-bin-release/logs?' /software/rocketmq-all-5.0.0-bin-release/conf/logback_broker.xml
执行命令3: sed -i 's?${user.home}/logs/rocketmqlogs?/software/rocketmq-all-5.0.0-bin-release/logs?' /software/rocketmq-all-5.0.0-bin-release/conf/logback_controller.xml
执行命令4: sed -i 's?${user.home}/logs/rocketmqlogs?/software/rocketmq-all-5.0.0-bin-release/logs?' /software/rocketmq-all-5.0.0-bin-release/conf/logback_namesrv.xml
执行命令5: sed -i 's?${user.home}/logs/rocketmqlogs?/software/rocketmq-all-5.0.0-bin-release/logs?' /software/rocketmq-all-5.0.0-bin-release/conf/logback_proxy.xml
执行命令6: sed -i 's?${user.home}/logs/rocketmqlogs?/software/rocketmq-all-5.0.0-bin-release/logs?' /software/rocketmq-all-5.0.0-bin-release/conf/logback_tools.xml
(3)修改启动脚本内存及环境变量
- 修改启动脚本runserver.sh,将环境变量改为实际路径(2个方法)
bash
执行命令1: cd /software/rocketmq-all-5.0.0-bin-release/bin
执行命令2: sed -i 's#${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m#${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m#' /software/rocketmq-all-5.0.0-bin-release/bin/runserver.sh
执行命令3:vim runserver.sh查看上述是否修改成功,同时更改环境变量如下,2个方法选其一
(1)[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/software/jdk/jdk_linux
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
#[ ! -e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)!"
(2)[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/software/jdk_linux
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/software/jdk_linux
[ ! -e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)!"
- 修改启动脚本runbroker.sh,将环境变量改为实际路径(2个方法)
bash
执行命令1: cd /software/rocketmq-all-5.0.0-bin-release/bin
执行命令2: sed -i 's#JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g"#JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g"#' /software/rocketmq-all-5.0.0-bin-release/bin/runbroker.sh
执行命令3:vim runbroker.sh查看上述是否修改成功,同时更改环境变量如下,2个方法选其一
(1)[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/software/jdk/jdk_linux
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
#[ ! -e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)!"
(2)[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/software/jdk_linux
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/software/jdk_linux
[ ! -e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)!"
3.2、3台服务器分别操作
目前看这三项有区别:
listenPort
dLegerSelfId与dLegerPeers保持对应。
brokerIP1
(1) IP1 - 192.168.0.1(主)
bash
执行命令1: cd /software/rocketmq-all-5.0.0-bin-release/conf/dledger
执行命令2: vim broker-n0.conf
## 集群名
brokerClusterName = RaftCluster
## broker组名,同一个RaftClusterGroup内,brokerName名要一样
brokerName=RaftNode00
## 监听的端口
listenPort=30911
## 你设置的NameServer地址和端口
namesrvAddr=192.168.0.1:9876;192.168.0.2:9876;192.168.0.3:9876
storePathRootDir=/software/rocketmq-all-5.0.0-bin-release/store/node00
storePathCommitLog=/software/rocketmq-all-5.0.0-bin-release/store/node00/commitlog
enableDLegerCommitLog=true
dLegerGroup=RaftNode00
## n0 n1 n2 分别是broker1,broker2,broker3 的 dLegerSelfId
## 例如:dLegerPeers=n0-服务器1的IP:40911;n1-服务器2的IP:40912;n2-服务器3的IP:40913
dLegerPeers=n0-192.168.0.1:40911;n1-192.168.0.2:40912;n2-192.168.0.3:40913
## must be unique
## 这个值必须是在同一个RaftClusterGroup内唯一的
dLegerSelfId=n0
sendMessageThreadPoolNums=16
brokerIP1=192.168.0.1
执行命令3: nohup sh /software/rocketmq-all-5.0.0-bin-release/bin/mqnamesrv &
执行命令4: nohup sh /software/rocketmq-all-5.0.0-bin-release/bin/mqbroker -c /software/rocketmq-all-5.0.0-bin-release/conf/dledger/broker-n0.conf &
(2) IP2 - 192.168.0.2(从)
bash
执行命令1: cd /software/rocketmq-all-5.0.0-bin-release/conf/dledger
执行命令2: vim broker-n1.conf
执行命令1: cd /software/rocketmq-all-5.0.0-bin-release/conf/dledger
执行命令2: vim broker-n1.conf
## 集群名
brokerClusterName = RaftCluster
## broker组名,同一个RaftClusterGroup内,brokerName名要一样
brokerName=RaftNode00
## 监听的端口
listenPort=30921
## 你设置的NameServer地址和端口
namesrvAddr=192.168.0.1:9876;192.168.0.2:9876;192.168.0.3:9876
storePathRootDir=/software/rocketmq-all-5.0.0-bin-release/store/node00
storePathCommitLog=/software/rocketmq-all-5.0.0-bin-release/store/node00/commitlog
enableDLegerCommitLog=true
dLegerGroup=RaftNode00
## n0 n1 n2 分别是broker1,broker2,broker3 的 dLegerSelfId
## 例如:dLegerPeers=n0-服务器1的IP:40911;n1-服务器2的IP:40912;n2-服务器3的IP:40913
dLegerPeers=n0-192.168.0.1:40911;n1-192.168.0.2:40912;n2-192.168.0.3:40913
## must be unique
## 这个值必须是在同一个RaftClusterGroup内唯一的
dLegerSelfId=n1
sendMessageThreadPoolNums=16
brokerIP1=192.168.0.2
执行命令3: nohup sh /software/rocketmq-all-5.0.0-bin-release/bin/mqnamesrv &
执行命令4: nohup sh /software/rocketmq-all-5.0.0-bin-release/bin/mqbroker -c /software/rocketmq-all-5.0.0-bin-release/conf/dledger/broker-n1.conf &
(3) IP3 - 192.168.0.3(从)
bash
执行命令1: cd /software/rocketmq-all-5.0.0-bin-release/conf/dledger
执行命令2: vim broker-n2.conf
## 集群名
brokerClusterName = RaftCluster
## broker组名,同一个RaftClusterGroup内,brokerName名要一样
brokerName=RaftNode00
## 监听的端口
listenPort=30931
## 你设置的NameServer地址和端口
namesrvAddr=192.168.0.1:9876;192.168.0.2:9876;192.168.0.3:9876
storePathRootDir=/software/rocketmq-all-5.0.0-bin-release/store/node00
storePathCommitLog=/software/rocketmq-all-5.0.0-bin-release/store/node00/commitlog
enableDLegerCommitLog=true
dLegerGroup=RaftNode00
## n0 n1 n2 分别是broker1,broker2,broker3 的 dLegerSelfId
## 例如:dLegerPeers=n0-服务器1的IP:40911;n1-服务器2的IP:40912;n2-服务器3的IP:40913
dLegerPeers=n0-192.168.0.1:40911;n1-192.168.0.2:40912;n2-192.168.0.3:40913
## must be unique
## 这个值必须是在同一个RaftClusterGroup内唯一的
dLegerSelfId=n2
sendMessageThreadPoolNums=16
brokerIP1=192.168.0.3
执行命令3: nohup sh /software/rocketmq-all-5.0.0-bin-release/bin/mqnamesrv &
执行命令4: nohup sh /software/rocketmq-all-5.0.0-bin-release/bin/mqbroker -c /software/rocketmq-all-5.0.0-bin-release/conf/dledger/broker-n2.conf &
4******、验证******
(1)查看集群服务是否启动成功:jps
命令执行后,可查看到两个进程,NamesrvStartup和BrokerStartup
(2)在集群中任意一个节点的bin目录下执行如下命令:
bash
执行命令1: cd /software/rocketmq-all-5.0.0-bin-release/bin
执行命令2: sh mqadmin clusterList -n 127.0.0.1:9876
结果中addr中有broker信息。
#BID显示3个,0+1+2,ACTIVATED显示3个,1个true+2个false。
(2)kill主broker并在此查看集群情况,master切换是否成功。重新启动后原master服务器变为从。【BID的0表示主】
5、日志
(1)Dleger高可用集群,3台中至少2台启动才不会报错
(2)核对配置项是否有错误
(3)空间不足、内存不足,清理后重启应用