本文主要讲述:
生产级的rocketmq消息集群的部署。
(1).集群形式
(2).源码编译
(3).生产级硬件资源与节点拓扑
(4).namersrv节点部署
(5).broker节点部署
(6).rocketmq-console后台部署
(7).rocketmq相关文章
(1).集群形式
集群形式:2m-2s-2namesrv;2个master,2个slave,2个namesrv。
主从方式:async
刷盘方式:异步。
(2).源码编译
下载地址:https://github.com/apache/rocketmq/releases
wget https://github.com/apache/rocketmq/archive/rocketmq-all-4.3.2.tar.gz
官方github提供的是源码需要下载后进行编译;
tar -xzvf rocketmq-all-4.3.2-source-release.tar.gz
cd rocketmq-all-4.3.2
mvn -Prelease-all -DskipTests clean install -U
cd distribution/target/apache-rocketmq
apache-rocketmq.tar.gz就是编译后的rocketmq包,将这个包传到要部署的各个机器。
使用python开一个web服务同步文件:
python -m SimpleHTTPServer 8077
(3).生产级硬件资源与节点拓扑
硬件资源&部署拓扑:
4台4核8G的机器,阿里云型号是ecs.sn1ne.xlarge。
rocketmq-c1-broker000:
开6G部署master-0
/app/3rd/apache-rocketmq-broker-master-0
rocketmq-c1-broker001:
开4G部署slave-0, 开2G部署namesrv
/app/3rd/apache-rocketmq-broker-slave-0
/app/3rd/apache-rocketmq-namesrv-0
rocketmq-c1-broker002:
开6G部署master-1
/app/3rd/apache-rocketmq-broker-master-1
rocketmq-c1-broker003:
开4G部署slave-1, 开2G部署namesrv
/app/3rd/apache-rocketmq-broker-slave-1
/app/3rd/apache-rocketmq-namesrv-1
修改JDK,使用JDK1.8。
修改消息罗盘位置,注意要保证这个目录位于SSD盘:
mkdir -p /data/inc/rocketmq-c1-store/data
修改消息罗盘位置,注意要保证这个目录位于SSD盘:
mkdir -p /data/inc/logs/rocketmq-broker/
mkdir -p /data/inc/logs/rocketmq-namesrv/
vi /app/3rd/apache-rocketmq/conf/2m-2s-async/broker-a.properties
(4).namersrv节点部署
1.JDK改为1.8
2.修改JVM参数:
/app/3rd/apache-rocketmq/bin/runserver.sh
原值:
-Xloggc:/dev/shm/rmq_srv_gc.log
-Xms4g -Xmx4g -Xmn2g
改为:
-Xloggc:/data/inc/logs/rocketmq-namesrv/rmq_srv_gc.log
-Xms2g -Xmx2g -Xmn1g
3.替换日志路径:
/app/3rd/apache-rocketmq/conf/logback_namesrv.xml
替换命令:注意要建立新目录:/data/inc/logs/rocketmq-namesrv
%s/\${user\.home}\/logs\/rocketmqlogs/\/data\/inc\/logs\/rocketmq-namesrv/g
4.启动:
nohup /app/3rd/apache-rocketmq-namesrv-0/bin/mqnamesrv > /data/inc/logs/rocketmq-namesrv/nohup-namesrv.out &
nohup /app/3rd/apache-rocketmq-namesrv-1/bin/mqnamesrv > /data/inc/logs/rocketmq-namesrv/nohup-namesrv.out &
(5).broker节点部署
1.JDK改为1.8
2.修改broker的JVM的内存,原值太大。
/app/3rd/apache-rocketmq/bin/runbroker.sh
原值:
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
-XX:MaxDirectMemorySize=15g
-Xloggc:/dev/shm/mq_gc_%p.log
改为:
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g"
-XX:MaxDirectMemorySize=2g
-Xloggc:/data/inc/logs/rocketmq-broker/mq_gc_%p.log
3.替换日志路径:
/app/3rd/apache-rocketmq/conf/logback_broker.xml
%s/\${user\.home}\/logs\/rocketmqlogs/\/data\/inc\/logs\/rocketmq-broker/g
4.2m-2s-async/*.properties需要增加的配置:
#nameServer地址,分号分割
namesrvAddr=rocketmq-c1-namesrv001.inc-inc.com:9876;rocketmq-c1-namesrv002.inc-inc.com:9876
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=false
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=false
#存储路径
storePathRootDir=/data/inc/rocketmq-c1-store/data
#commitLog 存储路径
storePathCommitLog=/data/inc/rocketmq-c1-store/data/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/data/inc/rocketmq-c1-store/data/consumequeue
#消息索引存储路径
storePathIndex=/data/inc/rocketmq-c1-store/data/index
#checkpoint 文件存储路径
storeCheckpoint=/data/inc/rocketmq-c1-store/data/checkpoint
#abort 文件存储路径
abortFile=/data/inc/rocketmq-c1-store/data/abort
数据保存在目录${rootpath}/consumequeue下面,rootpath 通过配置项storePathRootDir指定,默认的是${user.home}/store。
启动命令:
nohup /app/3rd/apache-rocketmq-broker-master-0/bin/mqbroker -n 'rocketmq-c1-namesrv001.inc-inc.com:9876;rocketmq-c1-namesrv002.inc-inc.com:9876' -c /app/3rd/apache-rocketmq-broker-master-0/conf/2m-2s-async/broker-a.properties > /data/inc/logs/rocketmq-broker/nohup-broker.out &
nohup /app/3rd/apache-rocketmq-broker-slave-0/bin/mqbroker -n 'rocketmq-c1-namesrv001.inc-inc.com:9876;rocketmq-c1-namesrv002.inc-inc.com:9876' -c /app/3rd/apache-rocketmq-broker-slave-0/conf/2m-2s-async/broker-a-s.properties > /data/inc/logs/rocketmq-broker/nohup-broker.out &
nohup /app/3rd/apache-rocketmq-broker-master-1/bin/mqbroker -n 'rocketmq-c1-namesrv001.inc-inc.com:9876;rocketmq-c1-namesrv002.inc-inc.com:9876' -c /app/3rd/apache-rocketmq-broker-master-1/conf/2m-2s-async/broker-b.properties > /data/inc/logs/rocketmq-broker/nohup-broker.out &
nohup /app/3rd/apache-rocketmq-broker-slave-1/bin/mqbroker -n 'rocketmq-c1-namesrv001.inc-inc.com:9876;rocketmq-c1-namesrv002.inc-inc.com:9876' -c /app/3rd/apache-rocketmq-broker-slave-1/conf/2m-2s-async/broker-b-s.properties > /data/inc/logs/rocketmq-broker/nohup-broker.out &
如果不能启动,还没有任何日志,请check store目录是否有权限。
(6).rocketmq-console后台部署
下载:
git clone -b release-rocketmq-console-1.0.0 https://github.com/apache/rocketmq-externals.git
进入项目文件夹并修改配置文件(中文注释是我添加,为方便解释,请删除,不然打包报错)。
$ cd rocketmq-externals/rocketmq-console/
$ vi src/main/resources/application.properties
Name Server地址默认为空,注释说可以在启动项目后在后台配置,经测试,后台配置切换失败,有报错,所以打包前需修改配置文件明确给出Name Server地址,或者启动服务的时候给出rocketmq.config.namesrvAddr参数值。
修改4处
#管理后台访问上下文路径,默认为空,如果填写,一定要前面加“/”,后面不要加,否则启动报错
server.contextPath=/rocketmq-console修改
server.port=7000修改
#spring.application.index=true
spring.application.name=rocketmq-console
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
logging.config=classpath:logback.xml
#if this value is empty,use env value rocketmq.config.namesrvAddr NAMESRV_ADDR | now, you can set it in ops page.default localhost:9876
#Name Server地址,修改成你自己的服务地址
rocketmq.config.namesrvAddr=127.0.0.1:9870;127.0.0.1:9871;127.0.0.1:9872修改
#if you use rocketmq version < 3.5.8, rocketmq.config.isVIPChannel should be false.default true
rocketmq.config.isVIPChannel=
#rocketmq-console's data path:dashboard/monitor
#rocketmq-console's data path:dashboard/monitor
rocketmq.config.dataPath=/data/inc/rocketmq-console修改
#set it false if you don't want use dashboard.default true
rocketmq.config.enableDashBoardCollect=true
$ vi src/main/resources/logback.xml
替换
%s/\${user\.home}\/logs\/consolelogs/\/data\/inc\/logs\/rocketmq-console/g
将项目打成jar包,并运行jar文件。
mvn clean package -Dmaven.test.skip=true -U
java -jar target/rocketmq-console-ng-1.0.0.jar
#如果配置文件没有填写Name Server
java -jar target/rocketmq-console-ng-1.0.0.jar --rocketmq.config.namesrvAddr='10.0.74.198:9876;10.0.74.199:9876'
启动命令:
nohup java -jar target/rocketmq-console-ng-1.0.0.jar --rocketmq.config.namesrvAddr='10.0.74.198:9876;10.0.74.199:9876' > /data/logs/rocketmq-console/nohup.out &
nohup java -jar /app/3rd/rocketmq-console/rocketmq-console-ng-1.0.0.jar > /data/inc/logs/rocketmq-console/nohup-rocketmq-console.out &
访问地址:
本地ip和端口访问:/rocketmq-console/
(7).rocketmq相关文章