其他分享
首页 > 其他分享> > 【RocketMQ 课程笔记】8.RocketMQ生产环境多Master多Slave环境部署实战

【RocketMQ 课程笔记】8.RocketMQ生产环境多Master多Slave环境部署实战

作者:互联网

生产多Master多Slave环境部署实战

环境说明

NameServer

Broker-A

Broker-B

关闭清除已有实例

清除原有并关闭已有线程

pkill java
rm -rf /usr/local/rocketmq-4.9.2
rm -f /usr/local/rocketmq-all-4.9.2-bin-release.zip

部署Name Server

103 NameServer

yum -y install java-1.8.0-openjdk-devel.x86_64
sudo cat >> /etc/profile <<-'EOF'
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export JRE_HOME=$JAVA_HOME/jre
export LASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
EOF

source /etc/profile
echo $JAVA_HOME

cd /usr/local
# 官网下的太慢,用我提供的OSS加速下载
# wget --no-check-certificate https://manongbiji.oss-cnbeijing.aliyuncs.com/ittailkshow/rocketmq/download/rocketmq-all-4.9.2-bin-release.zip
wget --no-check-certificate https://manongbiji.oss-cnbeijing.aliyuncs.com/ittailkshow/rocketmq/download/rocketmq-all-4.9.2-bin-release.zip

unzip rocketmq-all-4.9.2-bin-release.zip
cd /usr/local/rocketmq-4.9.2
sed -i 's/-Xms4g -Xmx4g -XX:MetaspaceSize=128m/-Xms1g -Xmx1g -
XX:MetaspaceSize=128m/g' ./bin/runserver.sh
firewall-cmd --zone=public --add-port=9876/tcp --permanent
firewall-cmd --reload
# sh ./bin/mqnamesrv
nohup sh ./bin/mqnamesrv > nqnamesrv.log &

113 NameServer

yum -y install java-1.8.0-openjdk-devel.x86_64
sudo cat >> /etc/profile <<-'EOF'
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
EOF

source /etc/profile
echo $JAVA_HOME

cd /usr/local
# 官网下的太慢,用我提供的OSS加速下载
# wget --no-check-certificate https://manongbiji.oss-cnbeijing.aliyuncs.com/ittailkshow/rocketmq/download/rocketmq-all-4.9.2-binrelease.zip
wget --no-check-certificate https://manongbiji.oss-cnbeijing.aliyuncs.com/ittailkshow/rocketmq/download/rocketmq-all-4.9.2-binrelease.zip
unzip rocketmq-all-4.9.2-bin-release.zip

cd /usr/local/rocketmq-4.9.2
sed -i 's/-Xms4g -Xmx4g -XX:MetaspaceSize=128m/-Xms1g -Xmx1g -
XX:MetaspaceSize=128m/g' ./bin/runserver.sh
firewall-cmd --zone=public --add-port=9876/tcp --permanent
firewall-cmd --reload
# sh ./bin/mqnamesrv
nohup sh ./bin/mqnamesrv > nqnamesrv.log &

部署2Master-2Slave

Broker-A:104主

yum -y install java-1.8.0-openjdk-devel.x86_64
sudo cat >> /etc/profile <<-'EOF'
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
EOF

source /etc/profile
echo $JAVA_HOME

cd /usr/local
# 官网下的太慢,用我提供的OSS加速下载
# wget --no-check-certificate https://dlcdn.apache.org/rocketmq/4.9.2/rocketmqall-4.9.2-bin-release.zip
wget --no-check-certificate https://manongbiji.oss-cnbeijing.aliyuncs.com/ittailkshow/rocketmq/download/rocketmq-all-4.9.2-binrelease.zip
unzip rocketmq-all-4.9.2-bin-release.zip

cd /usr/local/rocketmq-4.9.2
sed -i 's/-Xms8g -Xmx8g/-Xms1g -Xmx1g/g' ./bin/runbroker.sh

cat > master-a.properties <<-'EOF'
#集群名称,同一个集群下的broker要求统一
brokerClusterName=DefaultCluster

#broker名称
brokerName=broker-a

#brokerId=0代表主节点,大于零代表从节点
brokerId=0

#删除日志文件时间点,默认凌晨 4 点
deleteWhen=04

#日志文件保留时间,默认 48 小时
fileReservedTime=48

#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
# SLAVE 从属服务器
brokerRole=SYNC_MASTER

#刷盘方式
#- ASYNC_FLUSH 异步刷盘,性能好宕机会丢数
#- SYNC_FLUSH 同步刷盘,性能较差不会丢数
flushDiskType=SYNC_FLUSH

#末尾追加,NameServer节点列表,使用分号分割
namesrvAddr=192.168.31.103:9876;192.168.31.113:9876

autoCreateTopicEnable=false
EOF

firewall-cmd --zone=public --add-port=10911/tcp --permanent
firewall-cmd --reload

# sh ./bin/mqbroker -c ./single-master.properties
nohup sh ./bin/mqbroker -c ./master-a.properties > broker.log &

Broker-A:114从

yum -y install java-1.8.0-openjdk-devel.x86_64
sudo cat >> /etc/profile <<-'EOF'
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
EOF
source /etc/profile
echo $JAVA_HOME

cd /usr/local
# 官网下的太慢,用我提供的OSS加速下载
# wget --no-check-certificate https://dlcdn.apache.org/rocketmq/4.9.2/rocketmqall-4.9.2-bin-release.zip
wget --no-check-certificate https://manongbiji.oss-cnbeijing.aliyuncs.com/ittailkshow/rocketmq/download/rocketmq-all-4.9.2-binrelease.zip
unzip rocketmq-all-4.9.2-bin-release.zip
cd /usr/local/rocketmq-4.9.2
sed -i 's/-Xms8g -Xmx8g/-Xms1g -Xmx1g/g' ./bin/runbroker.sh

cat > slave-a.properties <<-'EOF'
#集群名称,同一个集群下的broker要求统一 
brokerClusterName=DefaultCluster

#broker名称
brokerName=broker-a

#brokerId=0代表主节点,大于零代表从节点
brokerId=1

#删除日志文件时间点,默认凌晨 4 点
deleteWhen=04

#日志文件保留时间,默认 48 小时
fileReservedTime=48

#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
brokerRole=SLAVE

#刷盘方式
#- ASYNC_FLUSH 异步刷盘,性能好宕机会丢数
#- SYNC_FLUSH 同步刷盘,性能较差不会丢数
flushDiskType=SYNC_FLUSH

#末尾追加,NameServer节点列表,使用分号分割
namesrvAddr=192.168.31.103:9876;192.168.31.113:9876

autoCreateTopicEnable=false
EOF

firewall-cmd --zone=public --add-port=10911/tcp --permanent
firewall-cmd --reload

# sh ./bin/mqbroker -c ./slave-a.properties
nohup sh ./bin/mqbroker -c ./slave-a.properties > broker.log &

Broker-B:105主

yum -y install java-1.8.0-openjdk-devel.x86_64
sudo cat >> /etc/profile <<-'EOF'
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
EOF
source /etc/profile
echo $JAVA_HOME

cd /usr/local
# 官网下的太慢,用我提供的OSS加速下载
# wget --no-check-certificate https://dlcdn.apache.org/rocketmq/4.9.2/rocketmqall-4.9.2-bin-release.zip
wget --no-check-certificate https://manongbiji.oss-cnbeijing.aliyuncs.com/ittailkshow/rocketmq/download/rocketmq-all-4.9.2-binrelease.zip
unzip rocketmq-all-4.9.2-bin-release.zip
cd /usr/local/rocketmq-4.9.2
sed -i 's/-Xms8g -Xmx8g/-Xms1g -Xmx1g/g' ./bin/runbroker.sh

cat > master-b.properties <<-'EOF'
#集群名称,同一个集群下的broker要求统一
brokerClusterName=DefaultCluster

#broker名称
brokerName=broker-b

#brokerId=0代表主节点,大于零代表从节点
brokerId=0

#删除日志文件时间点,默认凌晨 4 点
deleteWhen=04

#日志文件保留时间,默认 48 小时
fileReservedTime=48

#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
brokerRole=SYNC_MASTER

#刷盘方式
#- ASYNC_FLUSH 异步刷盘,性能好宕机会丢数
#- SYNC_FLUSH 同步刷盘,性能较差不会丢数
flushDiskType=SYNC_FLUSH

#末尾追加,NameServer节点列表,使用分号分割
namesrvAddr=192.168.31.103:9876;192.168.31.113:9876

autoCreateTopicEnable=false
EOF

firewall-cmd --zone=public --add-port=10911/tcp --permanent
firewall-cmd --reload

# sh ./bin/mqbroker -c ./master-b.properties
nohup sh ./bin/mqbroker -c ./master-b.properties > broker.log &

Broker-B:115从

yum -y install java-1.8.0-openjdk-devel.x86_64
sudo cat >> /etc/profile <<-'EOF'
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
EOF
source /etc/profile
echo $JAVA_HOME

cd /usr/local
# 官网下的太慢,用我提供的OSS加速下载
# wget --no-check-certificate https://dlcdn.apache.org/rocketmq/4.9.2/rocketmqall-4.9.2-bin-release.zip
wget --no-check-certificate https://manongbiji.oss-cnbeijing.aliyuncs.com/ittailkshow/rocketmq/download/rocketmq-all-4.9.2-binrelease.zip
unzip rocketmq-all-4.9.2-bin-release.zip
cd /usr/local/rocketmq-4.9.2
sed -i 's/-Xms8g -Xmx8g/-Xms1g -Xmx1g/g' ./bin/runbroker.sh

cat > slave-b.properties <<-'EOF'
#集群名称,同一个集群下的broker要求统一
brokerClusterName=

#broker名称
brokerName=broker-b

#brokerId=0代表主节点,大于零代表从节点
brokerId=1

#删除日志文件时间点,默认凌晨 4 点
deleteWhen=04

#日志文件保留时间,默认 48 小时
fileReservedTime=48

#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
brokerRole=SLAVE

#刷盘方式
#- ASYNC_FLUSH 异步刷盘,性能好宕机会丢数
#- SYNC_FLUSH 同步刷盘,性能较差不会丢数
flushDiskType=SYNC_FLUSH

#末尾追加,NameServer节点列表,使用分号分割
namesrvAddr=192.168.31.103:9876;192.168.31.113:9876

autoCreateTopicEnable=false
EOF

firewall-cmd --zone=public --add-port=10911/tcp --permanent
firewall-cmd --reload

# sh ./bin/mqbroker -c ./slave-b.properties
nohup sh ./bin/mqbroker -c ./slave-b.properties > broker.log &

验证集群有效

cd /usr/local/rocketmq-4.9.2/bin
sh mqadmin clusterList -n 192.168.31.113:9876

标签:Slave,x86,sudo,1.8,192.168,Master,java,RocketMQ,log
来源: https://www.cnblogs.com/JamKing/p/16693664.html