RocketMQ 4.5.1 双主双从异步复制环境搭建
Posted lua123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RocketMQ 4.5.1 双主双从异步复制环境搭建相关的知识,希望对你有一定的参考价值。
基础环境
操作系统:CentOS7
实例:192.168.63.129,192.168.63.130,192.168.63.131,192.168.63.132
Java:jdk-8u191-linux-x64.tar.gz
安装JDK
先把系统里面自带的卸载掉
[[email protected] soft]# rpm -qa|grep java python-javapackages-3.4.1-11.el7.noarch java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64 java-1.8.0-openjdk-headless-1.8.0.181-7.b13.el7.x86_64 tzdata-java-2018e-3.el7.noarch javapackages-tools-3.4.1-11.el7.noarch [[email protected] soft]# rpm -e java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64 --nodeps [[email protected] soft]# rpm -e java-1.8.0-openjdk-headless-1.8.0.181-7.b13.el7.x86_64 --nodeps [[email protected] soft]#
进入你JDK安装包所在的目录,然后安装JDK
# 创建一个目录存放 [[email protected] soft]# mkdir /usr/local/java # 解压缩到这个目录 [[email protected] soft]# tar -xvf jdk-8u191-linux-x64.tar.gz -C /usr/local/java/
解压之后进入该目录可以看到
下面配置环境变量
[[email protected] java]# vim /etc/profile
加入以下内容
# java export JAVA_HOME=/usr/local/java/jdk1.8.0_191 export JRE_HOME=/usr/local/java/jdk1.8.0_191/jre export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
如下所示
刷新并验证
[[email protected] java]# source /etc/profile [[email protected] java]# java -version java version "1.8.0_191" Java(TM) SE Runtime Environment (build 1.8.0_191-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode) [[email protected] java]#
安装RocketMQ
首先上传到服务器,我上传到 /soft文件夹下面。然后解压
# 解压 [[email protected] soft]# unzip rocketmq-all-4.5.1-bin-release.zip -d /usr/local/ # 进入解压目录 [[email protected] soft]# cd /usr/local/ [[email protected] local]# ll total 0 drwxr-xr-x. 2 root root 6 Apr 11 2018 bin drwxr-xr-x. 2 root root 6 Apr 11 2018 etc drwxr-xr-x. 2 root root 6 Apr 11 2018 games drwxr-xr-x. 2 root root 6 Apr 11 2018 include drwxr-xr-x. 3 root root 26 May 26 18:39 java drwxr-xr-x. 2 root root 6 Apr 11 2018 lib drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64 drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec drwx------. 6 root root 103 Mar 29 17:37 rocketmq-all-4.5.0-bin-release drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin drwxr-xr-x. 5 root root 49 May 10 07:44 share drwxr-xr-x. 2 root root 6 Apr 11 2018 src
# 改个名字 [[email protected] local]# mv rocketmq-all-4.5.1-bin-release/ rocketmq [[email protected] local]# ll total 0 drwxr-xr-x. 2 root root 6 Apr 11 2018 bin drwxr-xr-x. 2 root root 6 Apr 11 2018 etc drwxr-xr-x. 2 root root 6 Apr 11 2018 games drwxr-xr-x. 2 root root 6 Apr 11 2018 include drwxr-xr-x. 3 root root 26 May 26 18:39 java drwxr-xr-x. 2 root root 6 Apr 11 2018 lib drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64 drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec drwx------. 6 root root 103 Mar 29 17:37 rocketmq drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin drwxr-xr-x. 5 root root 49 May 10 07:44 share drwxr-xr-x. 2 root root 6 Apr 11 2018 src
进入配置文件目录,修改配置文件(四台机器修改的配置文件不一样,注意名称)
[[email protected] local]# cd rocketmq/conf/2m-2s-async/
# 129节点 [[email protected] 2m-2s-async]# vim broker-a.properties # 130节点 [[email protected] 2m-2s-async]# vim broker-a-s.properties # 131节点 [[email protected] 2m-2s-async]# vim broker-b.properties # 132节点 [[email protected] 2m-2s-async]# vim broker-b-s.properties
加入如下内容(四台机器加入内容一样,但是修改的文件不一样)
listenPort=10911 namesrvAddr=192.168.63.129:9876;192.168.63.130:9876;192.168.63.131:9876;192.168.63.132:9876 mapedFileSizeCommitLog=1073741824 storePathRootDir=/usr/local/rocketmq/store storePathCommitLog=/usr/local/rocketmq/store/commitlog storePathConsumerQueue=/usr/local/rocketmq/store/consumequeue storePathIndex=/usr/local/rocketmq/store/index
如图:
然后新建store相关目录(四台机器一样)
[[email protected] 2m-2s-async]# mkdir /usr/local/rocketmq/store [[email protected] 2m-2s-async]# mkdir /usr/local/rocketmq/store/commitlog [[email protected] 2m-2s-async]# mkdir /usr/local/rocketmq/store/consumequeue [[email protected] 2m-2s-async]# mkdir /usr/local/rocketmq/store/index
开启防火墙端口
[[email protected] 2m-2s-async]# firewall-cmd --zone=public --add-port=10911/tcp --permanent success [[email protected] 2m-2s-async]# firewall-cmd --zone=public --add-port=9876/tcp --permanent success [[email protected] 2m-2s-async]# systemctl restart firewalld
进入bin目录,准备启动nameserver,启动成功。
[[email protected] 2m-2s-async]# cd /usr/local/rocketmq/bin/ [[email protected] bin]# ./mqnamesrv & [1] 59673 [[email protected] bin]# Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release. The Name Server boot success. serializeType=JSON [[email protected] bin]#
下面启动broker
[[email protected] bin]# ./mqbroker -c /usr/local/rocketmq/conf/2m-2s-async/broker-a.properties & [2] 59731 [[email protected] bin]# Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, 8589934592, 0) failed; error=‘Cannot allocate memory‘ (errno=12) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (mmap) failed to map 8589934592 bytes for committing reserved memory. # An error report file with more information is saved as: # /usr/local/rocketmq/bin/hs_err_pid59738.log [2]+ Exit 1 ./mqbroker
报错了,内存不足。毕竟测试搭建,只有1G内存。修改runbroker.sh
[[email protected] bin]# vim runbroker.sh
修改这里
改为 -Xms256m -Xmx256m -Xmn128m
保存关闭,重启。
# 129 [[email protected] bin]# ./mqbroker -c /usr/local/rocketmq/conf/2m-2s-async/broker-a.properties & [3] 61454 [2] Exit 143 ./mqbroker [[email protected] bin]# The broker[broker-a, 192.168.63.129:10911] boot success. serializeType=JSON and name server is 192.168.63.129:9876;192.168.63.130:9876;192.168.63.131:9876;192.168.63.132:9876 # 130 [[email protected] bin]# ./mqbroker -c /usr/local/rocketmq/conf/2m-2s-async/broker-a-s.properties & [3] 60359 [2] Exit 143 ./mqbroker [[email protected] bin]# The broker[broker-a, 192.168.63.130:10911] boot success. serializeType=JSON and name server is 192.168.63.129:9876;192.168.63.130:9876;192.168.63.131:9876;192.168.63.132:9876 # 131 [[email protected] bin]# ./mqbroker -c /usr/local/rocketmq/conf/2m-2s-async/broker-b.properties & [3] 60224 [2] Exit 143 ./mqbroker [[email protected] bin]# The broker[broker-b, 192.168.63.131:10911] boot success. serializeType=JSON and name server is 192.168.63.129:9876;192.168.63.130:9876;192.168.63.131:9876;192.168.63.132:9876 # 132 [[email protected] bin]# ./mqbroker -c /usr/local/rocketmq/conf/2m-2s-async/broker-b-s.properties & [3] 60310 [2] Exit 143 ./mqbroker [[email protected] bin]# The broker[broker-b, 192.168.63.132:10911] boot success. serializeType=JSON and name server is 192.168.63.129:9876;192.168.63.130:9876;192.168.63.131:9876;192.168.63.132:9876
全部启动成功后,安装个管控台。
管控台
这里需要四台服务器开启10909端口。
[[email protected] bin]# firewall-cmd --zone=public --add-port=10909/tcp --permanent success [[email protected] bin]# systemctl restart firewalld
=====
https://github.com/apache/rocketmq-externals
下载好后,进入rocketmq-console目录执行打包命令
mvn clean package -Dmaven.test.skip=true
进入target目录,执行命令启动。
java -jar rocketmq-console-ng-1.0.1.jar --rocketmq.config.namesrvAddr=‘192.168.63.129:9876;192.168.63.130:9876;192.168.63.131:9876;192.168.63.132:9876‘
访问http://localhost:8080/#/cluster
关闭NameServer和Broker
[[email protected] bin]# ./mqshutdown namesrv The mqnamesrv(59705) is running... Send shutdown request to mqnamesrv(59705) OK [[email protected] bin]# ./mqshutdown broker The mqbroker(60366) is running... Send shutdown request to mqbroker(60366) OK [1]- Exit 143 ./mqnamesrv
以上是关于RocketMQ 4.5.1 双主双从异步复制环境搭建的主要内容,如果未能解决你的问题,请参考以下文章