集群使用的模式是 2m-2s-sync,采用同步复制、异步刷盘方式。
ip地址 | 主机名 | 操作系统版本 | RocketMQ版本 | JDK版本 | maven版本 | 备注 |
---|---|---|---|---|---|---|
172.16.7.91 | nameserver01 | centos 7.6 | 4.8.0 | 1.8.0_291 | 3.6 | Name Server集群 |
172.16.7.92 | nameserver03 | centos 7.6 | 4.8.0 | 1.8.0_291 | 3.6 | Name Server集群 |
172.16.7.93 | master01 | centos 7.6 | 4.8.0 | 1.8.0_291 | 3.6 | Broker集群 |
172.16.7.94 | slave01 | centos 7.6 | 4.8.0 | 1.8.0_291 | 3.6 | Broker集群 |
172.16.7.95 | master02 | centos 7.6 | 4.8.0 | 1.8.0_291 | 3.6 | Broker集群 |
172.16.7.96 | slave02 | centos 7.6 | 4.8.0 | 1.8.0_291 | 3.6 | Broker集群 |
[root@rabbitmq01 network-scripts]# hostnamectl set-hostname nameserver01
[root@rabbitmq01 network-scripts]# hostname
nameserver01
6台服务器均设置主机名,详见环境说明。
[root@nameserver01 ~]# cat >> /etc/hosts <<EOF
> 172.16.7.91 nameserver01
> 172.16.7.92 nameserver02
> 172.16.7.93 master01
> 172.16.7.94 slave01
> 172.16.7.95 master02
> 172.16.7.96 slave02
> EOF
6台服务器都执行以上操作
下载地址:https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
新建目录/opt/java并将下载的包jdk-8u291-linux-x64.rpm 上传
[root@nameserver01 ~]# mkdir /opt/java
[root@nameserver01 ~]# cd /opt/java
[root@nameserver01 java]# rpm -ivh jdk-8u291-linux-x64.rpm
6台都执行java安装
6台服务器都执行如下操作
[root@nameserver01 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
也可以到官网下载,下载地址:http://maven.apache.org/download.cgi
[root@nameserver01 ~]# tar -zxvf apache-maven-3.6.3-bin.tar.gz -C /usr/local/
[root@nameserver01 ~]# mv /usr/local/apache-maven-3.6.3/ /usr/local/maven3.6
[root@nameserver01 ~]# sed -i '$a export PATH=$PATH:/usr/local/maven3.6/bin' /etc/profile && source /etc/profile
[root@nameserver01 ~]# mvn -v
[root@rabbitmq01 ~]# cd /usr/local/maven3.6/conf/
[root@rabbitmq01 conf]# view settings.xml
修改前:
<url>http://my.repository.com/repo/path</url>
修改后:
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
修改前:
<localRepository>/path/to/local/repo</localRepository>
修改后:
<localRepository>/usr/local/maven3.6/repository</localRepository>
将默认的1.4替换为实际的1.8
修改前:
修改后:
下载地址:https://github.com/apache/rocketmq/tags
本次选择的版本为最新的4.8.0
[root@nameserver01 ~]# wget https://github.com/apache/rocketmq/archive/refs/tags/rocketmq-all-4.8.0.tar.gz
[root@nameserver01 ~]# mkdir /rocketmq
[root@nameserver01 ~]# tar -zxvf rocketmq-all-4.8.0.tar.gz -C /rocketmq
[root@nameserver01 ~]# mv /rocketmq/rocketmq-rocketmq-all-4.8.0/* /rocketmq/ && rm -rf /rocketmq/rocketmq-rocketmq-all-4.8.0/
[root@nameserver01 ~]# cd /rocketmq/
[root@nameserver01 rocketmq]# mvn -Prelease-all -DskipTests clean install -U
中间省略了些步骤
除了使用maven编译安装方式外,还可以直接下载带bin的安装包,免编译安装,步骤3和步骤4执行一个就行。
本文后面章节基于免编译安装。
下载地址:https://apache.claz.org/rocketmq/4.8.0/rocketmq-all-4.8.0-bin-release.zip
[root@nameserver01 ~]# cd /rocketmq/
[root@nameserver01 rocketmq]# wget https://apache.claz.org/rocketmq/4.8.0/rocketmq-all-4.8.0-bin-release.zip
[root@nameserver01 rocketmq]# unzip rocketmq-all-4.8.0-bin-release.zip
[root@nameserver01 rocketmq]# cd rocketmq-all-4.8.0-bin-release && mv * /rocketmq/ && rm -rf /rocketmq/rocketmq-all-4.8.0-bin-release*
[root@nameserver01 rocketmq]# pwd
/rocketmq
[root@nameserver01 rocketmq]# ll
总用量 40
drwxr-xr-x 2 root root 102 12月 9 19:46 benchmark
drwxr-xr-x 3 root root 4096 12月 4 14:26 bin
drwxr-xr-x 6 root root 211 12月 4 14:26 conf
drwxr-xr-x 2 root root 4096 12月 9 19:46 lib
-rw-r--r-- 1 root root 17336 10月 23 2020 LICENSE
-rw-r--r-- 1 root root 1338 12月 4 14:26 NOTICE
-rw-r--r-- 1 root root 5132 12月 4 14:26 README.md
rocketmq-all-4.8.0-bin-release.zip带bin版本的介质无需maven编译,解压后即可使用。
[root@nameserver01 ~]# sed -i '$a export ROCKETMQ_HOME=/rocketmq' /etc/profile
[root@nameserver01 ~]# sed -i '$a export PATH=$PATH:$ROCKETMQ_HOME/bin' /etc/profile && source /etc/profile
本节操作在nameserver集群nameserver01和nameserver02都执行。
[root@nameserver01 ~]# cd /rocketmq/bin/
[root@nameserver01 bin]# view runserver.sh
调整前:
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
调整后:
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
由于默认启动的最大内存比较大,在虚机测试时需要修改小点保证服务能正常启动。
[root@nameserver01 bin]# nohup sh mqnamesrv &
NameServer启动成功,同样的nameserver02也执行相同启动命令。
本节操作在Broker集群master01、slave01、master02、slave02分别执行。
[root@master01 ~]# cd /rocketmq/bin
[root@master01 bin]# view runbroker.sh
调整前:
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
调整后:
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"
由于默认启动的最大内存比较大,在虚机测试时需要修改小点保证服务能正常启动。
由于本文采用的是2主2从同步方式,对应的目录为2m-2s-sync
[root@master01 2m-2s-sync]# pwd
/rocketmq/conf/2m-2s-sync
[root@master01 2m-2s-sync]# ll
总用量 16
-rw-r--r-- 1 root root 928 10月 23 2020 broker-a.properties
-rw-r--r-- 1 root root 922 10月 23 2020 broker-a-s.properties
-rw-r--r-- 1 root root 928 10月 23 2020 broker-b.properties
-rw-r--r-- 1 root root 922 10月 23 2020 broker-b-s.properties
[root@master01 2m-2s-sync]# pwd
/rocketmq/conf/2m-2s-sync
[root@master01 2m-2s-sync]# more broker-a.properties
namesrvAddr=172.16.7.91:9876;172.16.7.92:9876
brokerClusterName=MyRocketmq
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
新增了namesrvAddr,指定对应的ip和端口;修改了brokerClusterName,自定义集群名为MyRocketmq;刷盘方式为默认的ASYNC_MASTER即异步方式。
[root@slave01 2m-2s-sync]# more broker-a-s.properties
namesrvAddr=172.16.7.91:9876;172.16.7.92:9876
brokerClusterName=MyRocketmq
brokerName=broker-a
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
[root@master02 2m-2s-sync]# more broker-b.properties
namesrvAddr=172.16.7.91:9876;172.16.7.92:9876
brokerClusterName=MyRocketmq
brokerName=broker-b
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
[root@slave02 2m-2s-sync]# more broker-b-s.properties
namesrvAddr=172.16.7.91:9876;172.16.7.92:9876
brokerClusterName=MyRocketmq
brokerName=broker-b
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
[root@master01 rocketmq]# pwd
/rocketmq
[root@master01 rocketmq]# nohup sh bin/mqbroker -c conf/2m-2s-sync/broker-a.properties &
master01节点启动成功
[root@slave01 rocketmq]# pwd
/rocketmq
[root@slave01 rocketmq]# nohup sh bin/mqbroker -c conf/2m-2s-sync/broker-a-s.properties &
slave01启动成功
[root@master02 rocketmq]# pwd
/rocketmq
[root@master02 rocketmq]# nohup sh bin/mqbroker -c conf/2m-2s-sync/broker-b.properties &
master02启动成功
[root@slave02 rocketmq]# pwd
/rocketmq
[root@slave02 rocketmq]# nohup sh bin/mqbroker -c conf/2m-2s-sync/broker-b-s.properties &
slave02启动成功
本节在nameserver01上执行
git下载介质
[root@nameserver01 ~]# yum -y install git
[root@nameserver01 ~]# git clone https://github.com/apache/rocketmq-externals.git
或者下载到本地再上传,下载地址:https://github.com/apache/rocketmq-externals/archive/refs/heads/master.zip
这里选择先下载再上传方式
[root@nameserver01 ~]# unzip rocketmq-externals-master--console.zip
[root@nameserver01 ~]# cd rocketmq-externals-master
[root@nameserver01 resources]# pwd
/root/rocketmq-externals-master/rocketmq-console/src/main/resources
[root@nameserver01 resources]# view application.properties
自定义应用端口和nameserver服务器
[root@nameserver01 rocketmq-console]# pwd
/root/rocketmq-externals-master/rocketmq-console
[root@nameserver01 rocketmq-console]# mvn clean package -Dmaven.test.skip=true
[INFO] Scanning for projects...
编译过程如图,中间过程省略
编译成功,console目录下会生成target目录
[root@nameserver01 rocketmq-console]# pwd
/root/rocketmq-externals-master/rocketmq-console
[root@nameserver01 rocketmq-console]# cd target/
[root@nameserver01 target]# java -jar rocketmq-console-ng-1.0.1.jar
nameserver01上执行生产者测试
[root@nameserver01 rocketmq]# export NAMESRV_ADDR='172.16.7.91:9876;172.16.7.92:9876'
[root@nameserver01 rocketmq]# sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
nameserve02上执行消费者测试
[root@nameserver02 rocketmq]# export NAMESRV_ADDR='172.16.7.91:9876;172.16.7.92:9876'
[root@nameserver02 rocketmq]# sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer