RocketMQ的安装配置:配置jdk环境,配置RocketMQ环境,配置集群环境,配置rocketmq-console


RocketMQ的安装配置

演示虚拟机环境:Centos64-1 (D:\linuxMore\centos6_64)

root / itcast : 固定IP 192.168.52.128

一,配置JDK环境

1,解压jdk到指定的目录

tar -xvf jdk-8u171-linux-x64.tar.gz -C /usr/local
cd /usr/local
mv jdk1.8.0_171 jdk1.8

2,配置环境变量

  • vi /etc/profile

  • 在末尾行添加

 #set java environment
?
  export JAVA_HOME=/usr/local/jdk1.8
  export PATH=$PATH:${JAVA_HOME}/bin
  • source /etc/profile 使用刚才的配置生效,如果不起作用,重启服务器 reboot

 

二,配置RocketMQ环境

上传 文件到/usr/local/src下

解压:

unzip rocketmq-all-4.5.2-bin-release.zip -C /opt
cd /opt
mv  rocketmq-all-4.5.2-bin-release rocketmq

?

启动nameserver

./mqnamesrv
[root@localhost bin]# ./mqnamesrv
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

启动broker

./mqbroker -n 192.168.52.128:9876
[root@localhost bin]# ./mqbroker
The broker[localhost.localdomain, 192.168.52.128:10911] boot success. serializeType=JSON

如果broker启动报错:修改 runbroker.sh文件中的内存参数即可

JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"

 

如果和docker 一起 需要修改配置文件:

conf/broker.conf

brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUS
# 解决和docker 冲突的
brokerIP1=192.168.52.128
namesrvAddr=192.168.52.128:9876

 

三,配置集群环境

1) 配置主机名称(未来就可以根据主机名找到对应的服务器了)

vim /etc/hosts

# nameserver
192.168.52.128 rocketmq-nameserver1
192.168.52.128 rocketmq-nameserver2
# broker
192.168.52.128 rocketmq-master1
192.168.52.128 rocketmq-slave2
192.168.52.128 rocketmq-master2
192.168.52.128 rocketmq-slave1

配置完毕后重启网卡,应用配置(centos6和7的命令不太一样,如果是7参考原笔记)

#CENTOS6
service network restart
?
#CENTOS7
systemctl retsart network

2) 关闭防火墙

#CENTOS6
# 关闭防火墙
service iptables stop firewalld.service 
# 查看防火墙的状态
service iptables status
# 禁止firewall开机启动
chkconfig iptables off
?
#CENTOS7
systemctl stop firewalld

3) 配置jdk

详见Linux安装jdk

4) 配置服务器环境

在同一个虚拟机上配置集群环境:
?rocketmq: 配置broker-a的主和broker-b-s从
?
?rocketmq2:配置broker-b的主和broker-a-s从

将rocketmq 解压至跟目录 /opt/rocketmq-cluster

# 解压
unzip rocketmq-all-4.5.2-bin-release.zip -d /opt/rocketmq-cluster
# 修改目录名称
mv rocketmq-all-4.5.2-bin-release rocketmq
?
#复制一个出来
cp rocketmq/ -R rocketmq2

5) 创建集群服务器的数据存储目录

主节点创建四个目录/ 从节点四个目录

#配置rocetmq
#a主
mkdir /opt/rocketmq-cluster/rocketmq/store
mkdir /opt/rocketmq-cluster/rocketmq/store/commitlog
mkdir /opt/rocketmq-cluster/rocketmq/store/consumequeue
mkdir /opt/rocketmq-cluster/rocketmq/store/index
mkdir /opt/rocketmq-cluster/rocketmq/store/abortfile
#b从
mkdir /opt/rocketmq-cluster/rocketmq/store-slave
mkdir /opt/rocketmq-cluster/rocketmq/store-slave/commitlog
mkdir /opt/rocketmq-cluster/rocketmq/store-slave/consumequeue
mkdir /opt/rocketmq-cluster/rocketmq/store-slave/index
mkdir /opt/rocketmq-cluster/rocketmq/store-slave/abortfile
?
#配置rocetmq2
#b主
mkdir /opt/rocketmq-cluster/rocketmq2/store
mkdir /opt/rocketmq-cluster/rocketmq2/store/commitlog
mkdir /opt/rocketmq-cluster/rocketmq2/store/consumequeue
mkdir /opt/rocketmq-cluster/rocketmq2/store/index
mkdir /opt/rocketmq-cluster/rocketmq2/store/abortfile
#a从
mkdir /opt/rocketmq-cluster/rocketmq2/store-slave
mkdir /opt/rocketmq-cluster/rocketmq2/store-slave/commitlog
mkdir /opt/rocketmq-cluster/rocketmq2/store-slave/consumequeue
mkdir /opt/rocketmq-cluster/rocketmq2/store-slave/index
mkdir /opt/rocketmq-cluster/rocketmq2/store-slave/abortfile
注意master与slave如果在同一个虚拟机中部署,需要将存储目录区分开

6) 修改配置

(不同的节点,应该修改不同的配置,文件夹也应该不一样)

两个命名服务器:
192.168.52.128:9876
192.168.52.128:5432
broker集群:
    192.168.52.128:11011    a主
    192.168.52.128:11111    a从
    192.168.52.128:10811    b主
    192.168.52.128:10911    b从

修改rocketmq的相关配置

6.1 修改a的master

>cd /opt/rocketmq-cluster/rocketmq/conf/2m-2s-sync
>vim  broker-a.proerties  

此时broker-a的端口为:11011

#所属集群名字
brokerClusterName=rocketmq-cluster
#broker名字,注意此处不同的配置文件填写的不一样
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:5432
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口
listenPort=11011
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=48
?
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/opt/rocketmq-cluster/rocketmq/store
#commitLog 存储路径
storePathCommitLog=/opt/rocketmq-cluster/rocketmq/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/opt/rocketmq-cluster/rocketmq/store/consumequeue
#消息索引存储路径
storePathIndex=/opt/rocketmq-cluster/rocketmq/store/index
#checkpoint 文件存储路径
storeCheckpoint=/opt/rocketmq-cluster/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/opt/rocketmq-cluster/rocketmq/store/abortfile
?
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=SYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

6.2 修改b的slave

>cd /opt/rocketmq-cluster/rocketmq/conf/2m-2s-sync
>vim  broker-b-s.proerties  

此时broker-b-s从的端口为:10911

#所属集群名字
brokerClusterName=rocketmq-cluster
#broker名字,注意此处不同的配置文件填写的不一样
brokerName=broker-b
#0 表示 Master,>0 表示 Slave
brokerId=1
#nameServer地址,分号分割
namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:5432
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口
listenPort=10911
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=48
?
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/opt/rocketmq-cluster/rocketmq/store-slave
#commitLog 存储路径
storePathCommitLog=/opt/rocketmq-cluster/rocketmq/store-slave/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/opt/rocketmq-cluster/rocketmq/store-slave/consumequeue
#消息索引存储路径
storePathIndex=/opt/rocketmq-cluster/rocketmq/store-slave/index
#checkpoint 文件存储路径
storeCheckpoint=/opt/rocketmq-cluster/rocketmq/store-slave/checkpoint
#abort 文件存储路径
abortFile=/opt/rocketmq-cluster/rocketmq/store-slave/abortfile
?
?
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=SLAVE
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

检查启动内存 (nameserver 和broker 均需要修改)

vim /opt/rocketmq-cluster/rocketmq/bin/runbroker.sh
vim /opt/rocketmq-cluster/rocketmq/bin/runserver.sh
?
# 开发环境配置 JVM Configuration
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"
?

rocketmq的nameserver默认端口为9876,不用修改。

#

 

修改rocketmq2的相关配置

6.3 修改b的master

>cd /opt/rocketmq-cluster/rocketmq2/conf/2m-2s-sync
>vim  broker-b.proerties  

此时broker-b的端口为:10811

#所属集群名字
brokerClusterName=rocketmq-cluster
#broker名字,注意此处不同的配置文件填写的不一样
brokerName=broker-b
#0 表示 Master,>0 表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:5432
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口
listenPort=10811
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=48
?
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/opt/rocketmq-cluster/rocketmq2/store
#commitLog 存储路径
storePathCommitLog=/opt/rocketmq-cluster/rocketmq2/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/opt/rocketmq-cluster/rocketmq2/store/consumequeue
#消息索引存储路径
storePathIndex=/opt/rocketmq-cluster/rocketmq2/store/index
#checkpoint 文件存储路径
storeCheckpoint=/opt/rocketmq-cluster/rocketmq2/store/checkpoint
#abort 文件存储路径
abortFile=/opt/rocketmq-cluster/rocketmq2/store/abortfile
?
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=SYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

6.4 修改b的slave

>cd /opt/rocketmq-cluster/rocketmq2/conf/2m-2s-sync
>vim  broker-a-s.proerties  

此时broker-a-s从的端口为:11111

#所属集群名字
brokerClusterName=rocketmq-cluster
#broker名字,注意此处不同的配置文件填写的不一样
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=1
#nameServer地址,分号分割
namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:5432
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口
listenPort=11111
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=48
?
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/opt/rocketmq-cluster/rocketmq2/store-slave
#commitLog 存储路径
storePathCommitLog=/opt/rocketmq-cluster/rocketmq2/store-slave/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/opt/rocketmq-cluster/rocketmq2/store-slave/consumequeue
#消息索引存储路径
storePathIndex=/opt/rocketmq-cluster/rocketmq2/store-slave/index
#checkpoint 文件存储路径
storeCheckpoint=/opt/rocketmq-cluster/rocketmq2/store-slave/checkpoint
#abort 文件存储路径
abortFile=/opt/rocketmq-cluster/rocketmq2/store-slave/abortfile
?
?
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=SLAVE
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

检查启动内存 (nameserver 和broker 均需要修改)

vim /opt/rocketmq-cluster/rocketmq2/bin/runbroker.sh
vim /opt/rocketmq-cluster/rocketmq2/bin/runserver.sh
?
# 开发环境配置 JVM Configuration
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"

?

 

修改rocketmq2的nameserver 的端口 为5432:

conf目录下新增:
vi namesrv.properties
添加内容为:
listenPort=5432
 

先启动nameserver:

# 进入/opt/rocketmq-cluster/rocketmq/bin目录
nohup ./mqnamesrv &
?
# 进入/opt/rocketmq-cluster/rocketmq2/bin目录
nohup ./mqnamesrv -c ../conf/namesrv.properties &
再启动brokerserver:

# 进入/opt/rocketmq-cluster/rocketmq/bin目录
nohup ./mqbroker -c ../conf/2m-2s-sync/broker-a.properties &
nohup ./mqbroker -c ../conf/2m-2s-sync/broker-b-s.properties &
?
# 进入/opt/rocketmq-cluster/rocketmq2/bin目录
nohup ./mqbroker -c ../conf/2m-2s-sync/broker-b.properties &
nohup ./mqbroker -c ../conf/2m-2s-sync/broker-a-s.properties &

 

nohup和&的区别
& : 指在后台运行
?
nohup : 不挂断的运行,注意并没有后台运行的功能,,就是指,用nohup运行命令可以使命令永久的执行下去,和用户终端没有关系,例如我们断开SSH连接都不会影响他的运行,注意了nohup没有后台运行的意思;&才是后台运行

 

集群启动脚本:rocketmq-cluster-start.sh

#!/bin/bash
#启动nameserver
sh /opt/rocketmq-cluster/rocketmq/bin/mqnamesrv &
sh /opt/rocketmq-cluster/rocketmq2/bin/mqnamesrv -c /opt/rocketmq-cluster/rocketmq2/conf/namesrv.properties &
?
#启动brokerserver
sh /opt/rocketmq-cluster/rocketmq/bin/mqbroker -c /opt/rocketmq-cluster/rocketmq/conf/2m-2s-sync/broker-a.properties &
sh /opt/rocketmq-cluster/rocketmq/bin/mqbroker -c /opt/rocketmq-cluster/rocketmq/conf/2m-2s-sync/broker-b-s.properties &
sh /opt/rocketmq-cluster/rocketmq2/bin/mqbroker -c /opt/rocketmq-cluster/rocketmq2/conf/2m-2s-sync/broker-b.properties &
sh /opt/rocketmq-cluster/rocketmq2/bin/mqbroker -c /opt/rocketmq-cluster/rocketmq2/conf/2m-2s-sync/broker-a-s.properties &

集群启动脚本:rocketmq-cluster-stop.sh

#!/bin/bash
#关闭nameserver
sh /opt/rocketmq-cluster/rocketmq/bin/mqshutdown namesrv &
?
#关闭brokerserver
sh /opt/rocketmq-cluster/rocketmq/bin/mqshutdown broker &

 

四,配置rocketmq-console

进入/opt/rocketmq-cluster/rocketmq-console目录下:

rocketmq-console-2.0.0.jar  为打包好的 springboot应用程序
application.properties 为外部配置文件,根据自己的需求进行修改
执行如下命令启动即可:
java -jar rocketmq-console-2.0.0.jar --spring.config.location=application.properties

?
已做成脚本:直接启动./start.sh即可