简单说明:
- RocketMQ 在4.5版本之后可以基于Dledger部署自动容灾切换的RocketMQ集群
- 本博文检录集群部署和组扩展过程,包括2个NameServer实例和两组3实例的BrokerServer组
- 集群主机列表:
IP 主机名 集群角色 资源 系统版本
-------------- ------ --------- ----- -------
192.168.77.101 vm1 ns1 bs11 2U/4G CentOS6
192.168.77.102 vm2 bs12 bs13 2U/4G CentOS7
192.168.77.103 vm3 ns2 bs21 2U/4G CentOS7
192.168.77.104 vm4 bs22 bs23 2U/4G CentOS6
主机部署:
- 依据《CentOS6实验机模板搭建部署》和《CentOS7实验机模板搭建部署》部署四台虚拟机
- vm1和vm4配置主机名和hosts解析
hostname vm1
# hostname vm4
echo "$(grep -E '127|::1' /etc/hosts)">/etc/hosts
cat >>/etc/hosts<<EOF
192.168.77.101 vm1 ns1 bs11
192.168.77.102 vm2 bs12 bs13
192.168.77.103 vm3 ns2 bs21
192.168.77.104 vm4 bs22 bs23
EOF
sed -i "s/^HOSTNAME.*$/HOSTNAME=$(hostname)/g" /etc/sysconfig/network
- vm2和vm3配置主机名和hosts解析
HOSTNAME=vm2
# HOSTNAME=vm3
hostnamectl set-hostname "$HOSTNAME"
echo "$HOSTNAME">/etc/hostname
echo "$(grep -E '127|::1' /etc/hosts)">/etc/hosts
cat >>/etc/hosts<<EOF
192.168.77.101 vm1 ns1 bs11
192.168.77.102 vm2 bs12 bs13
192.168.77.103 vm3 ns2 bs21
192.168.77.104 vm4 bs22 bs23
EOF
四台主机部署安装jdk和rocketmq
# 安装配置jdk1.8
mkdir -pv /usr/local/java
cd /usr/local/java
tar -xf /tmp/jdk-8u241-linux-x64.tar.gz
chown -R root: .
cd /usr/local
ln -s java/jdk1.8.0_241 jdk
echo 'export JAVA_HOME=/usr/local/jdk'>>/etc/profile
echo 'export CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib'>>/etc/profile
echo 'export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH'>>/etc/profile
source /etc/profile
java -version
# 安装配置RocketMQ
cd /tmp
wget https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.7.1/rocketmq-all-4.7.1-bin-release.zip
mkdir -pv /usr/local/RocketMQ
cd /usr/local/RocketMQ
unzip /tmp/rocketmq-all-4.7.1-bin-release.zip
cd /usr/local/
ln -s RocketMQ/rocketmq-all-4.7.1-bin-release rocketmq
echo 'export ROCKETMQ_HOME=/usr/local/rocketmq'>>/etc/profile
echo 'export PATH=$PATH:$ROCKETMQ_HOME/bin'>>/etc/profile
source /etc/profile
mkdir -pv /data/rocketmq/store/commitlog
mkdir -pv /data/logs
cd $ROCKETMQ_HOME/conf
sed -i 's#${user.home}#/data#g' *.xml
cd $ROCKETMQ_HOME/bin
sed -i 's/-Xms4g/-Xms1g/g' runserver.sh
sed -i 's/-Xmx4g/-Xmx1g/g' runserver.sh
sed -i 's/-Xms8g/-Xms1g/g' runbroker.sh
sed -i 's/-Xmx8g/-Xmx1g/g' runbroker.sh
vm1和vm3配置启动NameServer
cd $ROCKETMQ_HOME/bin
sh mqnamesrv &
# sh mqshutdown namesrv
jps -m
netstat -tupln|grep 9876
echo '# RocketMQ 4.7.1 NameServer start and stop'>>/etc/rc.local
echo 'source /etc/profile;sh ${ROCKETMQ_HOME}/bin/mqnamesrv &'>>/etc/rc.local
echo '# source /etc/profile;sh ${ROCKETMQ_HOME}/bin/mqshutdown namesrv'>>/etc/rc.local
vm1和vm2配置启动第一个BrokerServer组
- vm1 配置 bs11
Role=bs11
RoleId=n0
GroupName=Group1
BrokerPort=31911
cd $ROCKETMQ_HOME
cat >conf/dledger/Vincent-Group1-${Role}.conf<<EOF
brokerClusterName = Vincent
brokerName=${GroupName}
listenPort=${BrokerPort}
namesrvAddr=ns1:9876;ns2:9876
storePathRootDir=/data/rocketmq/${Role}
storePathCommitLog=/data/rocketmq/${Role}/commitlog
enableDLegerCommitLog=true
dLegerGroup=${GroupName}
dLegerPeers=n0-bs11:40911;n1-bs12:40912;n2-bs13:40913
dLegerSelfId=${RoleId}
sendMessageThreadPoolNums=2
EOF
sh mqbroker -c$ROCKETMQ_HOME/conf/dledger/Vincent-Group1-${Role}.conf &
# sh mqshutdown broker
jps -m
netstat -tupln|grep -E '309|409'
echo '# RocketMQ 4.7.1 BrokerServer start and stop'>>/etc/rc.local
echo "source /etc/profile;sh \${ROCKETMQ_HOME}/bin/mqbroker -c\$ROCKETMQ_HOME/conf/dledger/Vincent-Group1-${Role}.conf &">>/etc/rc.local
echo '# source /etc/profile;sh ${ROCKETMQ_HOME}/bin/mqshutdown broker'>>/etc/rc.local
- vm2 配置 bs12
Role=bs12
RoleId=n1
GroupName=Group1
BrokerPort=31912
cd $ROCKETMQ_HOME
cat >conf/dledger/Vincent-Group1-${Role}.conf<<EOF
brokerClusterName = Vincent
brokerName=${GroupName}
listenPort=${BrokerPort}
namesrvAddr=ns1:9876;ns2:9876
storePathRootDir=/data/rocketmq/${Role}
storePathCommitLog=/data/rocketmq/${Role}/commitlog
enableDLegerCommitLog=true
dLegerGroup=${GroupName}
dLegerPeers=n0-bs11:40911;n1-bs12:40912;n2-bs13:40913
dLegerSelfId=${RoleId}
sendMessageThreadPoolNums=2
EOF
sh mqbroker -c$ROCKETMQ_HOME/conf/dledger/Vincent-Group1-${Role}.conf &
# sh mqshutdown broker
jps -m
netstat -tupln|grep -E '309|409'
echo '# RocketMQ 4.7.1 BrokerServer start and stop'>>/etc/rc.local
echo "source /etc/profile;sh \${ROCKETMQ_HOME}/bin/mqbroker -c\$ROCKETMQ_HOME/conf/dledger/Vincent-Group1-${Role}.conf &">>/etc/rc.local
echo '# source /etc/profile;sh ${ROCKETMQ_HOME}/bin/mqshutdown broker'>>/etc/rc.local
- vm2 配置 bs13
Role=bs13
RoleId=n2
GroupName=Group1
BrokerPort=31913
cd $ROCKETMQ_HOME
cat >conf/dledger/Vincent-Group1-${Role}.conf<<EOF
brokerClusterName = Vincent
brokerName=${GroupName}
listenPort=${BrokerPort}
namesrvAddr=ns1:9876;ns2:9876
storePathRootDir=/data/rocketmq/${Role}
storePathCommitLog=/data/rocketmq/${Role}/commitlog
enableDLegerCommitLog=true
dLegerGroup=${GroupName}
dLegerPeers=n0-bs11:40911;n1-bs12:40912;n2-bs13:40913
dLegerSelfId=${RoleId}
sendMessageThreadPoolNums=2
EOF
sh mqbroker -c$ROCKETMQ_HOME/conf/dledger/Vincent-Group1-${Role}.conf &
# sh mqshutdown broker
jps -m
netstat -tupln|grep -E '309|409'
echo '# RocketMQ 4.7.1 BrokerServer start and stop'>>/etc/rc.local
echo "source /etc/profile;sh \${ROCKETMQ_HOME}/bin/mqbroker -c\$ROCKETMQ_HOME/conf/dledger/Vincent-Group1-${Role}.conf &">>/etc/rc.local
echo '# source /etc/profile;sh ${ROCKETMQ_HOME}/bin/mqshutdown broker'>>/etc/rc.local
- 任意主机验证配置
cd $ROCKETMQ_HOME
sh bin/mqadmin clusterList -n ns1:9876
sh bin/mqadmin clusterList -n ns2:9876
vm3和vm4配置启动第二个BrokerServer组,即组扩展
- vm3 配置 bs21
Role=bs21
RoleId=n0
GroupName=Group2
BrokerPort=31911
cd $ROCKETMQ_HOME
cat >conf/dledger/Vincent-Group1-${Role}.conf<<EOF
brokerClusterName = Vincent
brokerName=${GroupName}
listenPort=${BrokerPort}
namesrvAddr=ns1:9876;ns2:9876
storePathRootDir=/data/rocketmq/${Role}
storePathCommitLog=/data/rocketmq/${Role}/commitlog
enableDLegerCommitLog=true
dLegerGroup=${GroupName}
dLegerPeers=n0-bs21:40911;n1-bs22:40912;n2-bs23:40913
dLegerSelfId=${RoleId}
sendMessageThreadPoolNums=2
EOF
sh mqbroker -c$ROCKETMQ_HOME/conf/dledger/Vincent-Group1-${Role}.conf &
# sh mqshutdown broker
jps -m
netstat -tupln|grep -E '309|409'
echo '# RocketMQ 4.7.1 BrokerServer start and stop'>>/etc/rc.local
echo "source /etc/profile;sh \${ROCKETMQ_HOME}/bin/mqbroker -c\$ROCKETMQ_HOME/conf/dledger/Vincent-Group1-${Role}.conf &">>/etc/rc.local
echo '# source /etc/profile;sh ${ROCKETMQ_HOME}/bin/mqshutdown broker'>>/etc/rc.local
- vm4 配置 bs12
Role=bs22
RoleId=n1
GroupName=Group2
BrokerPort=31912
cd $ROCKETMQ_HOME
cat >conf/dledger/Vincent-Group1-${Role}.conf<<EOF
brokerClusterName = Vincent
brokerName=${GroupName}
listenPort=${BrokerPort}
namesrvAddr=ns1:9876;ns2:9876
storePathRootDir=/data/rocketmq/${Role}
storePathCommitLog=/data/rocketmq/${Role}/commitlog
enableDLegerCommitLog=true
dLegerGroup=${GroupName}
dLegerPeers=n0-bs21:40911;n1-bs22:40912;n2-bs23:40913
dLegerSelfId=${RoleId}
sendMessageThreadPoolNums=2
EOF
sh mqbroker -c$ROCKETMQ_HOME/conf/dledger/Vincent-Group1-${Role}.conf &
# sh mqshutdown broker
jps -m
netstat -tupln|grep -E '309|409'
echo '# RocketMQ 4.7.1 BrokerServer start and stop'>>/etc/rc.local
echo "source /etc/profile;sh \${ROCKETMQ_HOME}/bin/mqbroker -c\$ROCKETMQ_HOME/conf/dledger/Vincent-Group1-${Role}.conf &">>/etc/rc.local
echo '# source /etc/profile;sh ${ROCKETMQ_HOME}/bin/mqshutdown broker'>>/etc/rc.local
- vm4 配置 bs13
Role=bs23
RoleId=n2
GroupName=Group2
BrokerPort=31913
cd $ROCKETMQ_HOME
cat >conf/dledger/Vincent-Group1-${Role}.conf<<EOF
brokerClusterName = Vincent
brokerName=${GroupName}
listenPort=${BrokerPort}
namesrvAddr=ns1:9876;ns2:9876
storePathRootDir=/data/rocketmq/${Role}
storePathCommitLog=/data/rocketmq/${Role}/commitlog
enableDLegerCommitLog=true
dLegerGroup=${GroupName}
dLegerPeers=n0-bs21:40911;n1-bs22:40912;n2-bs23:40913
dLegerSelfId=${RoleId}
sendMessageThreadPoolNums=2
EOF
sh mqbroker -c$ROCKETMQ_HOME/conf/dledger/Vincent-Group1-${Role}.conf &
# sh mqshutdown broker
jps -m
netstat -tupln|grep -E '309|409'
echo '# RocketMQ 4.7.1 BrokerServer start and stop'>>/etc/rc.local
echo "source /etc/profile;sh \${ROCKETMQ_HOME}/bin/mqbroker -c\$ROCKETMQ_HOME/conf/dledger/Vincent-Group1-${Role}.conf &">>/etc/rc.local
echo '# source /etc/profile;sh ${ROCKETMQ_HOME}/bin/mqshutdown broker'>>/etc/rc.local
- 任意主机验证配置
cd $ROCKETMQ_HOME
sh bin/mqadmin clusterList -n ns1:9876
sh bin/mqadmin clusterList -n ns2:9876
[TOC]