前言
集群使用的模式是 2m-2s-sync,采用同步复制、异步刷盘方式。
环境说明
ip地址主机名操作系统版本RocketMQ版本JDK版本maven版本备注172.16.7.91nameserver01centos 7.64.8.01.8.0_2913.6Name Server集群172.16.7.92nameserver03centos 7.64.8.01.8.0_2913.6Name Server集群172.16.7.93master01centos 7.64.8.01.8.0_2913.6Broker集群broker-a172.16.7.94slave01centos 7.64.8.01.8.0_2913.6Broker集群broker-a172.16.7.95master02centos 7.64.8.01.8.0_2913.6Broker集群broker-b172.16.7.96slave02centos 7.64.8.01.8.0_2913.6Broker集群broker-b
部署概况
一、准备工作
1.设置hostname [root@rabbitmq01 network-scripts]# hostnamectl set-hostname nameserver01[root@rabbitmq01 network-scripts]# hostnamenameserver01
6台服务器均设置主机名,详见环境说明。
2.设置hosts [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台服务器都执行以上操作
3.关闭防火墙和selinux
详见Centos7.6操作系统安装及优化全纪录
二、安装jdk
1.下载jdk
下载地址:https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
2.安装jdk
新建目录/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安装
三、安装maven
6台服务器都执行如下操作
1.下载安装包 [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
2.解压并配置环境变量 [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
3.maven优化
3.1配置阿里源 [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>
3.2指定资源下载路径
修改前: <localRepository>/path/to/local/repo</localRepository>
修改后: <localRepository>/usr/local/maven3.6/repository</localRepository>
3.3指定JDK版本
将默认的1.4替换为实际的1.8
修改前:
修改后:
四、RocketMQ安装
1.版本选取
下载地址:https://github.com/apache/rocketmq/tags
本次选择的版本为最新的4.8.0
2.下载安装包 [root@nameserver01 ~]# wget https://github.com/apache/rocketmq/archive/refs/tags/rocketmq-all-4.8.0.tar.gz
3.解压并编译 [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
中间省略了些步骤
4.免编译安装
除了使用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总用量 40drwxr-xr-x 2 root root 102 12月 9 19:46 benchmarkdrwxr-xr-x 3 root root 4096 12月 4 14:26 bindrwxr-xr-x 6 root root 211 12月 4 14:26 confdrwxr-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编译,解压后即可使用。
5.配置环境变量 [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
五、Name Server集群安装
本节操作在nameserver集群nameserver01和nameserver02都执行。
1.调整runserver.sh参数 [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"
由于默认启动的最大内存比较大,在虚机测试时需要修改小点保证服务能正常启动。
2.启动NameServer [root@nameserver01 bin]# nohup sh mqnamesrv &
NameServer启动成功,同样的nameserver02也执行相同启动命令。
六、Broker集群安装
本节操作在Broker集群master01、slave01、master02、slave02分别执行。
1.调整runbroker.sh参数 [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.配置broker
由于本文采用的是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
2.1修改master01配置broker-a.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:9876brokerClusterName=MyRocketmqbrokerName=broker-abrokerId=0deleteWhen=04fileReservedTime=48brokerRole=SYNC_MASTERflushDiskType=ASYNC_FLUSH
新增了namesrvAddr,指定对应的ip和端口;修改了brokerClusterName,自定义集群名为MyRocketmq;刷盘方式为默认的ASYNC_MASTER即异步方式。
2.2修改slave01配置broker-a-s.properties [root@slave01 2m-2s-sync]# more broker-a-s.propertiesnamesrvAddr=172.16.7.91:9876;172.16.7.92:9876brokerClusterName=MyRocketmqbrokerName=broker-abrokerId=1deleteWhen=04fileReservedTime=48brokerRole=SLAVEflushDiskType=ASYNC_FLUSH
2.3修改master02配置broker-b.properties [root@master02 2m-2s-sync]# more broker-b.propertiesnamesrvAddr=172.16.7.91:9876;172.16.7.92:9876brokerClusterName=MyRocketmqbrokerName=broker-bbrokerId=0deleteWhen=04fileReservedTime=48brokerRole=SYNC_MASTERflushDiskType=ASYNC_FLUSH
2.4修改slave02配置broker-b-s.properties [root@slave02 2m-2s-sync]# more broker-b-s.propertiesnamesrvAddr=172.16.7.91:9876;172.16.7.92:9876brokerClusterName=MyRocketmqbrokerName=broker-bbrokerId=1deleteWhen=04fileReservedTime=48brokerRole=SLAVEflushDiskType=ASYNC_FLUSH
3.启动broker
3.1启动master01 [root@master01 rocketmq]# pwd/rocketmq[root@master01 rocketmq]# nohup sh bin/mqbroker -c conf/2m-2s-sync/broker-a.properties &
master01节点启动成功
3.2启动slave01 [root@slave01 rocketmq]# pwd/rocketmq[root@slave01 rocketmq]# nohup sh bin/mqbroker -c conf/2m-2s-sync/broker-a-s.properties &
slave01启动成功
3.3启动master02 [root@master02 rocketmq]# pwd/rocketmq[root@master02 rocketmq]# nohup sh bin/mqbroker -c conf/2m-2s-sync/broker-b.properties &
master02启动成功
3.4启动slave02 [root@slave02 rocketmq]# pwd/rocketmq[root@slave02 rocketmq]# nohup sh bin/mqbroker -c conf/2m-2s-sync/broker-b-s.properties &
slave02启动成功
七、安装管理面板
本节在nameserver01上执行
1.介质下载
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
这里选择先下载再上传方式
2.解压 [root@nameserver01 ~]# unzip rocketmq-externals-master--console.zip [root@nameserver01 ~]# cd rocketmq-externals-master
3.修改配置文件 [root@nameserver01 resources]# pwd/root/rocketmq-externals-master/rocketmq-console/src/main/resources[root@nameserver01 resources]# view application.properties
自定义应用端口和nameserver服务器
4.编译 [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目录
5.运行 [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
6.访问console
访问地址:http://172.16.7.91:57690
八、集群测试
1.生产者
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
2.消费者
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
3.console查看
本文所有配置文件和安装包已上传github:RocketMQ集群搭建
单机版详见:Centos7.6搭建RocketMQ4.8全纪录