RocketMQ 4.5.1 双主双从异步复制环境搭建

原文链接: http://www.cnblogs.com/LUA123/p/10926488.html

基础环境

操作系统: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

先把系统里面自带的卸载掉

 

[root@localhost 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
[root@localhost soft]# rpm -e java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64 --nodeps
[root@localhost soft]# rpm -e java-1.8.0-openjdk-headless-1.8.0.181-7.b13.el7.x86_64 --nodeps
[root@localhost soft]# 

进入你JDK安装包所在的目录,然后安装JDK

# 创建一个目录存放
[root@localhost soft]# mkdir /usr/local/java
# 解压缩到这个目录
[root@localhost soft]# tar -xvf jdk-8u191-linux-x64.tar.gz -C /usr/local/java/

 

解压之后进入该目录可以看到

下面配置环境变量

[root@localhost 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

 如下所示

RocketMQ 4.5.1 双主双从异步复制环境搭建_第1张图片

刷新并验证

[root@localhost java]# source /etc/profile
[root@localhost 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)
[root@localhost java]# 

 

安装RocketMQ

RocketMQ 4.5.1 双主双从异步复制环境搭建_第2张图片

去下载  http://rocketmq.apache.org/

然后上传到服务器,我上传到 /soft文件夹下面。然后解压

# 解压
[root@localhost soft]# unzip rocketmq-all-4.5.1-bin-release.zip -d /usr/local/
# 进入解压目录
[root@localhost soft]# cd /usr/local/
[root@localhost 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.1-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
# 改个名字 [root@localhost local]#
mv rocketmq-all-4.5.1-bin-release/ rocketmq [root@localhost 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

 

进入配置文件目录,修改配置文件(四台机器修改的配置文件不一样,注意名称)

[root@localhost local]# cd rocketmq/conf/2m-2s-async/
# 129节点
[root@localhost 2m-2s-async]# vim broker-a.properties
# 130节点
[root@localhost 2m-2s-async]# vim broker-a-s.properties
# 131节点
[root@localhost 2m-2s-async]# vim broker-b.properties
# 132节点
[root@localhost 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

 

如图:

RocketMQ 4.5.1 双主双从异步复制环境搭建_第3张图片

然后新建store相关目录(四台机器一样)

[root@localhost 2m-2s-async]# mkdir /usr/local/rocketmq/store
[root@localhost 2m-2s-async]# mkdir /usr/local/rocketmq/store/commitlog
[root@localhost 2m-2s-async]# mkdir /usr/local/rocketmq/store/consumequeue
[root@localhost 2m-2s-async]# mkdir /usr/local/rocketmq/store/index

 

开启防火墙端口

[root@localhost 2m-2s-async]# firewall-cmd --zone=public --add-port=10911/tcp --permanent
success
[root@localhost 2m-2s-async]# firewall-cmd --zone=public --add-port=9876/tcp --permanent
success
[root@localhost 2m-2s-async]# systemctl restart firewalld

 

进入bin目录,准备启动nameserver,启动成功。

[root@localhost 2m-2s-async]# cd /usr/local/rocketmq/bin/
[root@localhost bin]# ./mqnamesrv &
[1] 59673
[root@localhost 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

[root@localhost bin]# 

 

下面启动broker

[root@localhost bin]# ./mqbroker -c /usr/local/rocketmq/conf/2m-2s-async/broker-a.properties &
[2] 59731
[root@localhost 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

[root@localhost bin]# vim runbroker.sh

修改这里

RocketMQ 4.5.1 双主双从异步复制环境搭建_第4张图片

改为 -Xms256m -Xmx256m -Xmn128m

保存关闭,重启。

 RocketMQ 4.5.1 双主双从异步复制环境搭建_第5张图片

# 129
[root@localhost bin]# ./mqbroker -c /usr/local/rocketmq/conf/2m-2s-async/broker-a.properties &
[3] 61454
[2]   Exit 143                ./mqbroker
[root@localhost 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
[root@localhost bin]# ./mqbroker -c /usr/local/rocketmq/conf/2m-2s-async/broker-a-s.properties &
[3] 60359
[2]   Exit 143                ./mqbroker
[root@localhost 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
[root@localhost bin]# ./mqbroker -c /usr/local/rocketmq/conf/2m-2s-async/broker-b.properties &
[3] 60224
[2]   Exit 143                ./mqbroker
[root@localhost 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
[root@localhost bin]# ./mqbroker -c /usr/local/rocketmq/conf/2m-2s-async/broker-b-s.properties &
[3] 60310
[2]   Exit 143                ./mqbroker
[root@localhost 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端口。

[root@localhost bin]# firewall-cmd --zone=public --add-port=10909/tcp --permanent
success
[root@localhost bin]# systemctl restart firewalld

=====

https://github.com/apache/rocketmq-externals

下载好后,进入rocketmq-console目录执行打包命令

mvn clean package -Dmaven.test.skip=true

 

RocketMQ 4.5.1 双主双从异步复制环境搭建_第6张图片

 

进入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

 RocketMQ 4.5.1 双主双从异步复制环境搭建_第7张图片

 

关闭NameServer和Broker

[root@localhost bin]# ./mqshutdown namesrv
The mqnamesrv(59705) is running...
Send shutdown request to mqnamesrv(59705) OK
[root@localhost bin]# ./mqshutdown broker
The mqbroker(60366) is running...
Send shutdown request to mqbroker(60366) OK
[1]-  Exit 143                ./mqnamesrv

 

转载于:https://www.cnblogs.com/LUA123/p/10926488.html

你可能感兴趣的:(RocketMQ 4.5.1 双主双从异步复制环境搭建)