Centos6.9下RocketMQ3.4.6高可用集群部署记录(双主双从+Nameserver+Console)

之前的文章已对RocketMQ做了详细介绍,这里就不再赘述了,下面是本人在测试和生产环境下RocketMQ3.4.6高可用集群的部署手册,在此分享下:

1) 基础环境

ip地址                 主机名                    角色
192.168.10.200         mq-master01               broker-a
192.168.10.201         mq-master02               broker-b
192.168.10.202         mq-slave01                broker-a-s
192.168.10.203         mq-slave02                broker-b-s
192.168.10.205         mq-console-nameserver     nameserver、console

生产环境准备5台虚拟机,如上,其中4台服务器为broker节点,2主2从;1台服务器作为nameserver和console节点.
测试环境的话,可以只用两台,分别为broker的一主一从节点,nameserver和console服务一同部署到master节点上.

关闭5台机器的iptables和selinux(所有节点机器上都要操作)
[root@mq-master01 ~]# /etc/init.d/iptables stop
[root@mq-master01 ~]# vim /etc/sysconfig/selinux
......
SELINUX=disabled
[root@mq-master01 ~]# setenforce 0
[root@mq-master01 ~]# getenforce
Permissive
 
5台机器都要安装统一的java环境(这里安装jdk1.8,参考:http://www.cnblogs.com/kevingrace/p/7607442.html)
将jdk-8u131-linux-x64.rpm下载到/opt目录下
下载地址:https://pan.baidu.com/s/1pLaAjPp
提取密码:x27s
 
[root@mq-master01 ~]# java -version
-bash: java: command not found
 
如果自带了java环境,就卸载掉
yum list installed |grep java
yum -y remove java-1.7.0-openjdk*
yum -y remove tzdata-java.noarch
 
[root@mq-master01 ~]# cd /usr/local/src/
[root@mq-master01 src]# ll jdk-8u131-linux-x64_.rpm
-rw-r--r-- 1 root root 169983496 Nov 19  2017 jdk-8u131-linux-x64_.rpm
[root@mq-master01 src]# rpm -ivh jdk-8u131-linux-x64_.rpm --force
 
[root@mq-master01 src]# vim /etc/profile
......
JAVA_HOME=/usr/java/jdk1.8.0_131
JAVA_BIN=/usr/java/jdk1.8.0_131/bin
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/bin:/sbin/
CLASSPATH=.:/lib/dt.jar:/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
 
[root@mq-master01 src]# source /etc/profile
[root@mq-master01 src]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)


5台机器最好前做hosts绑定,否则后续启动broker的时候,会报错诸如:
java.net.UnknownHostException: mq-master01: mq-master01: Name or service not known
 
[root@mq-master01 ~]# cat /etc/hosts
......
192.168.10.200         mq-master01
192.168.10.201         mq-master02
192.168.10.202         mq-slave01
192.168.10.203         mq-slave02
192.168.10.205         mq-console-nameserver


本案例rocketmq3.4.6的相关软件包下载地址: https://pan.baidu.com/s/1VOYA60vIobtSxo9-9rTI6w
提取密码: bxhr

软件包分别是:rocketmq_admin.zip, rocketmq_namesrv.zip, rocketmq.zip
下载后放到/usr/local/src目录下
服务安装目录都在/data下

2) RocektMQ Broker双主双从环境部署(mq-master01,mq-master02,mq-slave01,mq-slave02四节点上操作)

1)安装rocketmq(四台broker节点机器操作一样)
[root@mq-master01 ~]# cd /usr/local/src/
[root@mq-master01 src]# ll rocketmq.zip 
-rw-rw-r--. 1 1000 1000 16048060 May 22 10:33 rocketmq.zip
[root@mq-master01 src]# unzip rocketmq.zip
[root@mq-master01 src]# mv rocketmq /data/

2) 配置rocektmq broker (四个节点机器都要操作)
其实下载的软件包里的对应配置已经配置好了,内容如下(brokerClusterName可以根据自己的业务名称进行修改):

[root@mq-master01 src]# cd /data/rocketmq/conf/2m-2s-sync/
[root@mq-master01 2m-2s-sync]# vim broker-a.properties
brokerClusterName=QCZLCluster
brokerName=broker-a
brokerId=0
autoCreateTopicEnable=false
clusterTopicEnable=false
brokerTopicEnable=false
autoCreateSubscriptionGroup=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
fetchNamesrvAddrByAddressServer=true
filterServerNums=1
serverWorkerThreads=32
deleteWhen=04
fileReservedTime=168
brokerRole=SYNC_MASTER
flushDiskType=SYNC_FLUSH
#netty监听端口
listenPort=20911

====================================================================
mq-master02节点配置
[root@mq-master02 src]# cat /data/rocketmq/conf/2m-2s-sync/broker-a-s.properties
brokerClusterName=QCZLCluster
brokerName=broker-a
brokerId=1
autoCreateTopicEnable=false
clusterTopicEnable=false
brokerTopicEnable=false
autoCreateSubscriptionGroup=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
fetchNamesrvAddrByAddressServer=true
filterServerNums=1
serverWorkerThreads=32
deleteWhen=04
fileReservedTime=168
brokerRole=SLAVE
flushDiskType=SYNC_FLUSH
listenPort=20911

====================================================================
mq-slave01节点配置
[root@mq-slave01 ~]# cat /data/rocketmq/conf/2m-2s-sync/broker-b.properties 
brokerClusterName=QCZLCluster
brokerName=broker-b
brokerId=0
autoCreateTopicEnable=false
clusterTopicEnable=false
brokerTopicEnable=false
autoCreateSubscriptionGroup=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
fetchNamesrvAddrByAddressServer=true
filterServerNums=1
serverWorkerThreads=32
deleteWhen=04
fileReservedTime=168
brokerRole=SYNC_MASTER
flushDiskType=SYNC_FLUSH
#netty监听端口
listenPort=20911

====================================================================
mq-slave02节点配置
[root@mq-slave02 ~]# cat /data/rocketmq/conf/2m-2s-sync/broker-b-s.properties
brokerClusterName=QCZLCluster
brokerName=broker-b
brokerId=1
autoCreateTopicEnable=false
clusterTopicEnable=false
brokerTopicEnable=false
autoCreateSubscriptionGroup=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
fetchNamesrvAddrByAddressServer=true
filterServerNums=1
serverWorkerThreads=32
deleteWhen=04
fileReservedTime=168
brokerRole=SLAVE
flushDiskType=SYNC_FLUSH
listenPort=20911

3) 启动NameServer (四台broker节点机器操作一样)
只需要将/data/rocketmq/startBrokerAM.sh中的JAVA_HOME改成自己服务的java路径就行了.
本案例的java家目录路径是/usr/java/jdk1.8.0_131

[root@mq-master01 ~]# cat /data/rocketmq/startBrokerAM.sh |grep JAVA_HOME
export JAVA_HOME=/data/software/jdk1.7.0_80
[root@mq-master01 ~]# sed -i 's#/data/software/jdk1.7.0_80#/usr/java/jdk1.8.0_131#g' /data/rocketmq/startBrokerAM.sh   
[root@mq-master01 ~]# cat /data/rocketmq/startBrokerAM.sh |grep JAVA_HOME                                           
export JAVA_HOME=/usr/java/jdk1.8.0_131

四台节点的启动脚本分别为:
[root@mq-master01 ~]# cat /data/rocketmq/startBrokerAM.sh
export JAVA_HOME=/usr/java/jdk1.8.0_131
nohup sh ./alibaba-rocketmq/bin/mqbroker -c ./conf/2m-2s-sync/broker-a.properties > ./nohup.out 2>&1 &

[root@mq-master02 ~]# cat /data/rocketmq/startBrokerAM.sh
export JAVA_HOME=/usr/java/jdk1.8.0_131
nohup sh ./alibaba-rocketmq/bin/mqbroker -c ./conf/2m-2s-sync/broker-a-s.properties > ./nohup.out 2>&1 &

[root@mq-slave01 ~]# cat /data/rocketmq/startBrokerAM.sh
export JAVA_HOME=/usr/java/jdk1.8.0_131
nohup sh ./alibaba-rocketmq/bin/mqbroker -c ./conf/2m-2s-sync/broker-b.properties > ./nohup.out 2>&1 &

[root@mq-slave02 ~]# cat /data/rocketmq/startBrokerAM.sh
export JAVA_HOME=/usr/java/jdk1.8.0_131
nohup sh ./alibaba-rocketmq/bin/mqbroker -c ./conf/2m-2s-sync/broker-b-s.properties > ./nohup.out 2>&1 &

启动NameServer(四台broker节点机器操作一样)
[root@mq-master01 ~]# cd /data/rocketmq/         #一定要先切换到该路径下
[root@mq-master01 rocketmq]# /bin/bash /data/rocketmq/startBrokerAM.sh
[root@mq-master01 rocketmq]# ps -ef|grep rocketmq                     
root     16783     1  0 09:13 pts/1    00:00:00 sh ./alibaba-rocketmq/bin/mqbroker -c ./conf/2m-2s-sync/broker-a.properties
root     16787 16783  0 09:13 pts/1    00:00:00 sh /data/rocketmq/alibaba-rocketmq/bin/runbroker.sh com.alibaba.rocketmq.broker.BrokerStartup -c ./conf/2m-2s-sync/broker-a.properties
root     16790 16787 48 09:13 pts/1    00:00:01 /usr/java/jdk1.8.0_131/bin/java -Drocketmq.home.dir=/data/rocketmq/alibaba-rocketmq -Duser.home=/data/rocketmq -Xms2048M -Xmx2048M -XX:PermSize=512M -XX:MaxPermSize=512M -XX:NewSize=768M -XX:MaxNewSize=768M -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:+DisableExplicitGC -verbose:gc -Xloggc:/data/rocketmq/logs/gclog/rmq_bk_gc.16787.log -XX:+PrintGCDetails -XX:-OmitStackTraceInFastThrow -Djava.ext.dirs=/data/rocketmq/alibaba-rocketmq/bin/../lib -cp .:/data/rocketmq/alibaba-rocketmq/bin/../conf: -Drocketmq.namesrv.domain=172.16.50.144 -Drocketmq.namesrv.domain.port=48080 -Drocketmq.namesrv.domain.subgroup=namesrv/getNSAddr.do com.alibaba.rocketmq.broker.BrokerStartup -c ./conf/2m-2s-sync/broker-a.properties
root     16835 16088  0 09:13 pts/1    00:00:00 grep rocketmq
[root@mq-master01 ~]# lsof -i:20911
COMMAND   PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
java    16790 root   79u  IPv6 19963764      0t0  TCP *:20911 (LISTEN)
java    16790 root   89u  IPv6 19965178      0t0  TCP mq-master01:20911->172.16.50.141:41400 (ESTABLISHED)

3) NameServer和Console部署(mq-console-nameserver节点上操作)

安装配置NameServer

[root@mq-console-nameserver src]# cd 
[root@mq-console-nameserver ~]# cd /usr/local/src/
[root@mq-console-nameserver src]# ll rocketmq_namesrv.zip 
-rw-rw-r-- 1 1000 1000 11802959 May 22 11:03 rocketmq_namesrv.zip
[root@mq-console-nameserver src]# unzip rocketmq_namesrv.zip
[root@mq-console-nameserver src]# mv rocketmq_namesrv /data/
[root@mq-console-nameserver src]# vim /data/rocketmq_namesrv/conf/namesrv.properties 
listenPort=20901

修改JAVA_HOME
[root@mq-console-nameserver src]# sed -i 's#/data/software/jdk1.7.0_80#/usr/java/jdk1.8.0_131#g' /data/rocketmq_namesrv/startNameServer.sh 
[root@mq-console-nameserver src]# cat /data/rocketmq_namesrv/startNameServer.sh
export JAVA_HOME=/usr/java/jdk1.8.0_131
nohup sh ./alibaba-rocketmq/bin/mqnamesrv -c ./conf/namesrv.properties > ./nohup.out 2>&1 &

启动NameServer
[root@mq-console-nameserver src]# cd /data/rocketmq_namesrv/
[root@mq-console-nameserver rocketmq_namesrv]# sh startNameServer.sh 

[root@mq-console-nameserver rocketmq_namesrv]# ps -ef|grep mqnamesrv
root     17455     1  0 09:23 pts/1    00:00:00 sh ./alibaba-rocketmq/bin/mqnamesrv -c ./conf/namesrv.properties
root     17555 24306  0 09:23 pts/1    00:00:00 grep mqnamesrv
[root@mq-console-nameserver rocketmq_namesrv]# lsof -i:20901
COMMAND   PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
java    17461 root   47u  IPv6 40870224      0t0  TCP *:20901 (LISTEN)

查看版本
[root@mq-console-nameserver rocketmq_namesrv]# ll /data/rocketmq_namesrv/alibaba-rocketmq/lib/
total 11836
-rw-rw-r-- 1 root root   16088 Nov 28  2016 annotation-indexer-1.4.jar
-rw-rw-r-- 1 root root    3159 Nov 28  2016 bridge-method-annotation-1.12.jar
-rw-rw-r-- 1 root root   41123 Nov 28  2016 commons-cli-1.2.jar
-rw-rw-r-- 1 root root  259600 Nov 28  2016 commons-codec-1.7.jar
-rw-rw-r-- 1 root root  185140 Nov 28  2016 commons-io-2.4.jar
-rw-rw-r-- 1 root root  284220 Nov 28  2016 commons-lang-2.6.jar
-rw-rw-r-- 1 root root 2838580 Nov 28  2016 derby-10.10.2.0.jar
-rw-rw-r-- 1 root root  409203 Nov 28  2016 fastjson-1.2.3.jar
-rw-rw-r-- 1 root root  154710 Nov 28  2016 github-api-1.59.jar
-rw-rw-r-- 1 root root   33483 Nov 28  2016 jackson-annotations-2.2.3.jar
-rw-rw-r-- 1 root root  192699 Nov 28  2016 jackson-core-2.2.3.jar
-rw-rw-r-- 1 root root  865838 Nov 28  2016 jackson-databind-2.2.3.jar
-rw-rw-r-- 1 root root  544021 Nov 28  2016 javassist-3.7.ga.jar
-rw-rw-r-- 1 root root  264600 Nov 28  2016 logback-classic-1.0.13.jar
-rw-rw-r-- 1 root root  418870 Nov 28  2016 logback-core-1.0.13.jar
-rw-rw-r-- 1 root root 1581066 Nov 28  2016 mockito-all-1.9.5.jar
-rw-rw-r-- 1 root root  964879 Nov 28  2016 mysql-connector-java-5.1.31.jar
-rw-rw-r-- 1 root root 1887979 Nov 28  2016 netty-all-4.0.25.Final.jar
-rw-rw-r-- 1 root root  160098 Nov 28  2016 rocketmq-broker-3.4.6-lo-20161026.115524-467.jar
-rw-rw-r-- 1 root root  241439 Nov 28  2016 rocketmq-client-3.4.6-lo-20160927.070341-319.jar
-rw-rw-r-- 1 root root  213219 Nov 28  2016 rocketmq-common-3.4.6-lo-20160927.070334-319.jar
-rw-rw-r-- 1 root root   38123 Nov 28  2016 rocketmq-filtersrv-3.4.6-lo-20160927.070417-318.jar
-rw-rw-r-- 1 root root   33525 Nov 28  2016 rocketmq-namesrv-3.4.6-lo-20160927.070407-319.jar
-rw-rw-r-- 1 root root   93612 Nov 28  2016 rocketmq-remoting-3.4.6-lo-20160927.070325-319.jar
-rw-rw-r-- 1 root root    4088 Nov 28  2016 rocketmq-srvutil-3.4.6-lo-20160927.070351-319.jar
-rw-rw-r-- 1 root root  157893 Nov 28  2016 rocketmq-store-3.4.6-lo-20160927.070348-319.jar
-rw-rw-r-- 1 root root  147117 Nov 28  2016 rocketmq-tools-3.4.6-lo-20160927.070403-319.jar
-rw-rw-r-- 1 root root   26084 Nov 28  2016 slf4j-api-1.7.5.jar

安装部署Console监控平台

[root@mq-console-nameserver ~]# cd /usr/local/src/
[root@mq-console-nameserver src]# ll rocketmq_admin.zip 
-rw-rw-r-- 1 1000 1000 41574127 May 22 11:03 rocketmq_admin.zip
[root@mq-console-nameserver src]# unzip rocketmq_admin.zip

服务端口(如下改成48080)
[root@mq-console-nameserver src]# vim /data/rocketmq_admin/apache-tomcat-8.0.32-rocketmq-console/conf/server.xml
......
    <Connector port="48080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="28443" />

[root@mq-console-nameserver src]# mv rocketmq_admin /data/
[root@mq-console-nameserver src]# cd /data/rocketmq_admin/
[root@mq-console-nameserver rocketmq_admin]# cd apache-tomcat-8.0.32-rocketmq-console/webapps/rocketmq/WEB-INF/classes/
[root@mq-console-nameserver classes]# vim config.properties 
rocketmq.namesrv.addr=192.168.10.205:20901
throwDone=true

启动console服务
[root@mq-console-nameserver classes]# /data/rocketmq_admin/apache-tomcat-8.0.32-rocketmq-console/bin/startup.sh 
[root@mq-console-nameserver classes]# lsof -i:48080
COMMAND   PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
java    19338 root   46u  IPv6 40883769      0t0  TCP *:48080 (LISTEN)

最后再重启四个Broker节点服务

http://192.168.10.205:48080/rocketmq/topic/list.do

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏IT笔记

SpringBoot开发案例之奇技淫巧

程序员都有着一种天生的好奇心,这种好奇心引导着我们的编程生涯。写几行代码,装载到计算机里,让它按照你的思路工作,这是非常有趣的事情。但随着开发的东西越来越多,我...

1K10
来自专栏程序猿DD

SpringBoot快速入门

简介 在您第1次接触和学习Spring框架的时候,是否因为其繁杂的配置而退却了?在你第n次使用Spring框架的时候,是否觉得一堆反复黏贴的配置有一些厌烦?那么...

1988
来自专栏jianhuicode

构建ReactJs项目node-sass编译出错

npm run dev本地项目出错 问题栈 verbose Please try running this command again as root/Adm...

22710
来自专栏Java技术栈

Spring Boot核心配置

启动类 在包根目录下添加启动类,必须包含main方法,再添加Spring Boot启动方法: SpringApplication.run(SampleContr...

3456
来自专栏Spring相关

第5章—构建Spring Web应用程序—SpringMVC详解

第二步:前端控制器请求HandlerMapping查找 Handler (可以根据xml配置、注解进行查找)

1484
来自专栏世界第一语言是java

springcloud微服务实战:Eureka+Zuul+Feign/Ribbon+Hystrix Turbine+SpringConfig+sleuth+zipkin

6023
来自专栏菩提树下的杨过

jenkins 入门教程(中)

接上回继续,本文以我托管在bitbucket上的一个开源项目spring-boot-rest-framework做为演示,讲解如何创建自动化部署。 一、创建it...

3026
来自专栏程序猿DD

【译】Spring 官方教程:使用 Restdocs 创建 API 文档

原文:Creating API Documentation with Restdocs 译者:HoldDie 校对:Jitianyu 本指南将引导你了解在 Sp...

1.7K5
来自专栏一个会写诗的程序员的博客

Springboot使用velocity模板引擎第五章 使用velocity模板引擎

最爽的Web组合开发就是Intellij IDEA + Maven + Spring Boot + Scala + Velocity + Boostrap + ...

2223
来自专栏Linyb极客之路

hazelcast初探

Hazelcast作为一个高度可扩展的数据分发和集群平台,提供了高效的、可扩展的分布式数据存储、数据缓存。Hazelcast是开源的,在分布式技术方面,Haze...

2146

扫码关注云+社区

领取腾讯云代金券