Centos7安装RocketMQ

单机版本

1、环境要求

  1、Linux64位
  2、JDK1.8(64位)

2、下载安装包并解压

[root@localhost rocketmq-singleton]# ll
总用量 0
drwxr-xr-x 6 root root 103 1月  22 2019 rocketmq-all-4.4.0-bin-release

3、编辑runbroker.sh和runserver.sh修改JVM内存大小

[root@localhost bin]# vi runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128"
[root@localhost bin]# vi runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

4、启动RocketMQ

# 启动NameServer
nohup sh bin/mqnamesrv &
# 查看启动日志
tail ‐f ~/logs/rocketmqlogs/namesrv.log
# 启动Broker
nohup sh bin/mqbroker ‐n localhost:9876 &
# 查看启动日志
tail ‐f ~/logs/rocketmqlogs/broker.log

5、关闭RocketMQ

# 关闭NameServer
sh bin/mqshutdown namesrv
# 关闭Broker
sh bin/mqshutdown broker

集群版本

1、服务器环境

  192.168.171.128  (Master1、Slave2)
  192.168.171.129 (Master2、Slave1)

2、配置HOST信息

# nameserver
192.168.171.128 rocketmq-nameserver1
192.168.171.129 rocketmq-nameserver2
# broker
192.168.171.128 rocketmq-master1
192.168.171.128 rocketmq-slave2
192.168.171.129 rocketmq-master2
192.168.171.129 rockermq-slave2
# 重启网卡
[root@localhost bin]# systemctl restart network

3、环境变量配置

[root@localhost rocketmq-all-4.4.0-bin-release]# vim /etc/profile
  # rocketmq enviroment
  ROCKETMQ_HOME=/usr/local/software/rocketmq-cluster/rocketmq-all-4.4.0-bin-release
  PATH=$PATH:$ROCKETMQ_HOME/bin
  export ROCKETMQ_HOME PATH
# 使配置生效
[root@localhost rocketmq-all-4.4.0-bin-release]# source /etc/profile

4、创建消息存储路径

[root@localhost rocketmq-cluster]# mkdir /usr/local/software/rocketmq-cluster/store
[root@localhost rocketmq-cluster]# mkdir /usr/local/software/rocketmq-cluster/store/commitlog
[root@localhost rocketmq-cluster]# mkdir /usr/local/software/rocketmq-cluster/store/consumequeue
[root@localhost rocketmq-cluster]# mkdir /usr/local/software/rocketmq-cluster/store/index

5、 broker配置文件

# 服务器:192.168.171.128(master1)
# vim conf/2m-2s-sync/broker-a.properties

# 所属集群名字
brokerClusterName=rocketmq-cluster
# broker名字,不同的配置文件填写的不一样
brokerName=broker-a
# 0表示master,大于0表示slave
brokerId=0
# nameServer地址,分号分割
namesrvAddr=192.168.171.128:9876;192.168.171.129:9876
# 在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
# 是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
# 是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
# Broker 对外服务的监听端口
listenPort=10911
# 删除文件时间点,默认凌晨 4点
deleteWhen=04
# 重试删除文件间隔,配合destroyMapedFileIntervalForcibly,默认120s
# redeleteHangedFileInterval=120000
# 存储路径
storePathRootDir=/usr/local/software/rocketmq-cluster/store
# 消费队列存储路径
storePathConsumeQueue=/usr/local/software/rocketmq-cluster/store/consumequeue
# 消息索引存储路径
storePathIndex=/usr/local/software/rocketmq-cluster/store/index
# checkpoint 文件存储路径
storeCheckpoint=/usr/local/software/rocketmq-cluster/store/checkpoint
# abort 文件存储路径
abortFile=/usr/local/software/rocketmq-cluster/store/abort
# 限制的消息大小
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
# 发消息线程池数量
# sendMessageThreadPoolNums=128
# 拉消息线程池数量
# pullMessageThreadPoolNums=128
# 服务器:192.168.171.128(slave2)
# vim conf/2m-2s-sync/broker-b-s.properties

# 所属集群名字
brokerClusterName=rocketmq-cluster
# broker名字,注意此处不同的配置文件填写的不一样
brokerName=broker-b
#0 表示 Master,>0 表示 Slave
brokerId=1
# nameServer地址,分号分割
namesrvAddr=192.168.171.128:9876;192.168.171.129:9876
# 在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
# 是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
# 是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
# Broker 对外服务的监听端口
listenPort=11011
# 删除文件时间点,默认凌晨 4点
deleteWhen=04
# 文件保留时间,默认 48 小时
fileReservedTime=120
# commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
# ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
# 销毁MappedFile被拒绝的最大存活时间,默认120s
# destroyMapedFileIntervalForcibly=120000
# 重试删除文件间隔,配合destroyMapedFileIntervalForcibly,默认120s
# redeleteHangedFileInterval=120000
# 检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
# 存储路径
storePathRootDir=/usr/local/software/rocketmq-cluster/store2
# commitLog 存储路径
storePathCommitLog=/usr/local/software/rocketmq-cluster/store2/commitlog
# 消费队列存储路径
storePathConsumeQueue=/usr/local/software/rocketmq-cluster/store2/consumequeue
# 消息索引存储路径
storePathIndex=/usr/local/software/rocketmq-cluster/store2/index
# checkpoint 文件存储路径
storeCheckpoint=/usr/local/software/rocketmq-cluster/store2/checkpoint
# abort 文件存储路径
abortFile=/usr/local/software/rocketmq-cluster/store2/abort
# 限制的消息大小
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=ASYNC_FLUSH
# checkTransactionMessageEnable=false
# 发消息线程池数量
# sendMessageThreadPoolNums=128
# 拉消息线程池数量
# pullMessageThreadPoolNums=128
# 服务器:192.168.171.129(master2)
# vim conf/2m-2s-sync/broker-b.properties

# 所属集群名字
brokerClusterName=rocketmq-cluster
# broker名字,注意此处不同的配置文件填写的不一样
brokerName=broker-b
#0 表示 Master,>0 表示 Slave
brokerId=0
# nameServer地址,分号分割
namesrvAddr=192.168.171.128:9876;192.168.171.129:9876
# 在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
# 是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
# 是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
# Broker 对外服务的监听端口
listenPort=10911
# 删除文件时间点,默认凌晨 4点
deleteWhen=04
# 文件保留时间,默认 48 小时
fileReservedTime=120
# commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
# ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
# 销毁MappedFile被拒绝的最大存活时间,默认120s
# destroyMapedFileIntervalForcibly=120000
# 重试删除文件间隔,配合destroyMapedFileIntervalForcibly,默认120s
# redeleteHangedFileInterval=120000
# 检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
# 存储路径
storePathRootDir=/usr/local/software/rocketmq-cluster/store
# commitLog 存储路径
storePathCommitLog=/usr/local/software/rocketmq-cluster/store/commitlog
# 消费队列存储路径
storePathConsumeQueue=/usr/local/software/rocketmq-cluster/store/consumequeue
# 消息索引存储路径
storePathIndex=/usr/local/software/rocketmq-cluster/store/index
# checkpoint 文件存储路径
storeCheckpoint=/usr/local/software/rocketmq-cluster/store/checkpoint
# abort 文件存储路径
abortFile=/usr/local/software/rocketmq-cluster/store/abort
# 限制的消息大小
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
# 服务器:192.168.171.129(slave1)
# vim conf/2m-2s-sync/broker-a-s.properties 

# 所属集群名字
brokerClusterName=rocketmq-cluster
# broker名字,注意此处不同的配置文件填写的不一样
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=1
# nameServer地址,分号分割
namesrvAddr=192.168.171.128:9876;192.168.171.129:9876
# 在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
# 是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
# 是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
# Broker 对外服务的监听端口
listenPort=11011
# 删除文件时间点,默认凌晨 4点
deleteWhen=04
# 文件保留时间,默认 48 小时
fileReservedTime=120
# commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
# ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
# 销毁MappedFile被拒绝的最大存活时间,默认120s
# destroyMapedFileIntervalForcibly=120000
# 重试删除文件间隔,配合destroyMapedFileIntervalForcibly,默认120s
# redeleteHangedFileInterval=120000
# 检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
# 存储路径
storePathRootDir=/usr/local/software/rocketmq-cluster/store2
# commitLog 存储路径
storePathCommitLog=/usr/local/software/rocketmq-cluster/store2/commitlog
# 消费队列存储路径
storePathConsumeQueue=/usr/local/software/rocketmq-cluster/store2/consumequeue
# 消息索引存储路径
storePathIndex=/usr/local/software/rocketmq-cluster/store2/index
# checkpoint 文件存储路径
storeCheckpoint=/usr/local/software/rocketmq-cluster/store2/checkpoint
# abort 文件存储路径
abortFile=/usr/local/software/rocketmq-cluster/store2/abort
# 限制的消息大小
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=ASYNC_FLUSH
# checkTransactionMessageEnable=false
# 发消息线程池数量
# sendMessageThreadPoolNums=128
# 拉消息线程池数量
# pullMessageThreadPoolNums=128

6、修改启动脚本文件

[root@localhost bin]# vi runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128"
[root@localhost bin]# vi runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

7、服务器启动

# 启动NameServe集群
分别在192.168.171.128和192.168.171.129启动NameServer
[root@rocketmq-nameserver2 bin]# nohup sh mqnamesrv &
# 启动Broker集群
# 在192.168.171.128上启动master1和slave2
# master1:
[root@rocketmq-nameserver1 bin]# nohup sh mqbroker -c /usr/local/software/rocketmq-cluster/rocketmq-all-4.4.0-bin-release/conf/2m-2s-sync/broker-a.properties &
# slave2:
[root@rocketmq-nameserver1 bin]# nohup sh mqbroker -c /usr/local/software/rocketmq-cluster/rocketmq-all-4.4.0-bin-release/conf/2m-2s-sync/broker-b-s.properties &
# 在192.168.171.129上启动master2和slave1
# master2:
[root@rocketmq-nameserver2 bin]# nohup sh mqbroker -c /usr/local/software/rocketmq-cluster/rocketmq-all-4.4.0-bin-release/conf/2m-2s-sync/broker-b.properties &
# slave1:
[root@rocketmq-nameserver2 bin]# nohup sh mqbroker -c /usr/local/software/rocketmq-cluster/rocketmq-all-4.4.0-bin-release/conf/2m-2s-sync/broker-a-s.properties &

8、查看进程状态

[root@rocketmq-nameserver2 bin]# jps
3013 BrokerStartup
2873 BrokerStartup
3020 Jps
2719 NamesrvStartup

9、查看日志

# 查看nameServer日志
tail ‐500f ~/logs/rocketmqlogs/namesrv.log
# 查看broker日志
tail ‐500f ~/logs/rocketmqlogs/broker.log

10、搭建集群监控

# 下载并编译rocketmq‐console (https://github.com/apache/rocketmq-externals)
mvn clean package -Dmaven.test.skip=true
# 启动rocketmq-console
[root@rocketmq-nameserver1 rocketmq-console]# java -jar rocketmq-console-ng-1.0.1.jar
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容