Linux安装RocketMQ

文章目录

  • Linux安装RocketMQ
    • 双Master模式
      • 1. 服务器环境
      • 2. hosts添加信息(两台机器都添加)
      • 3. 测试两个服务器刚刚配置的hosts
      • 4. 解压(两台机器)
      • 5. 创建软链接(两台机器)
      • 6. 创建存储路径(两台机器)
      • 7. RocketMQ配置文件(两台机器)
      • 8. 修改日志配置文件(两台机器)
      • 9. 修改启动脚本参数(两台机器)
      • 10. 启动NameServer(两台机器)
      • 11. 启动BrokerServer A(192.168.10.129)
      • 12. 启动BrokerServer B(192.168.10.196)
      • 13. 查看启动的服务(两台机器)
      • 14. 查看日志
    • 部署RocketMQ控制台
      • 创建rocketmq-console文件夹
      • 上传war包解压
      • 修改连接配置文件

Linux安装RocketMQ

版本介绍

  1. Linux: CentOS 7
  2. RocketMQ: alibaba-rocketmq-3.2.6.tar.gz
  3. 环境描述: 本次测试是在在本电脑中安装的VMware软件中的两台虚拟机, ip地址分别为192.168.10.129和192.168.10.196, 均已关闭防火墙
  4. alibaba-rocketmq-3.2.6.tar.gz 下载地址: https://pan.baidu.com/s/1Uj42USSt9Fx5FXqOiGFeyQ 提取码: ivck
  5. rocketmq-console-3.2.6.war 下载地址
    链接: https://pan.baidu.com/s/1I0LHpCQvbjqz80x5zAQ7Sg 提取码: ta9k

双Master模式

1. 服务器环境

序号 ip 角色 模式
1 192.168.10.129 nameServer1,brokerServer1 Master1
2 192.168.10.196 nameServer2,brokerServer2 Master2

2. hosts添加信息(两台机器都添加)

[root@masteryee-one ~]# vi /etc/hosts

hosts 如下

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6


192.168.10.129 rocketmq-nameserver1
192.168.10.129 rocketmq-master1
192.168.10.196 rocketmq-nameserver2
192.168.10.196 rocketmq-master2
IP NAME
192.168.10.129 rocketmq-nameserver1
192.168.10.129 rocketmq-master1
192.168.10.196 rocketmq-nameserver2
192.168.10.196 rocketmq-master2

重启网卡

[root@masteryee-one ~]# service network restart

3. 测试两个服务器刚刚配置的hosts

两个服务器之间互相ping通一下, 这一步没做好, 后期整个都没用了

[root@masteryee-one ~]# ping 192.168.10.129
[root@masteryee-one ~]# ping 192.168.10.196
[root@masteryee-one ~]# ping rocketmq-nameserver1
[root@masteryee-one ~]# ping rocketmq-master1
[root@masteryee-one ~]# ping rocketmq-nameserver2
[root@masteryee-one ~]# ping rocketmq-master2

4. 解压(两台机器)

上传 alibaba-rocketmq-3.2.6.tar.gz 文件到 /usr/local/ 下

[root@masteryee-one local]# tar -zxvf alibaba-rocketmq-3.2.6.tar.gz -C /usr/local/

5. 创建软链接(两台机器)

[root@masteryee-one local]# ln -s alibaba-rocketmq rocketmq

查看软链接是否创建成功

[root@masteryee-one local]# ll
total 4
drwxr-xr-x.  9 52583 users  114 Mar 28  2015 alibaba-rocketmq
drwxr-xr-x.  2 root  root     6 Nov  5  2016 bin
drwxr-xr-x.  2 root  root     6 Nov  5  2016 etc
drwxr-xr-x.  2 root  root     6 Nov  5  2016 games
drwxr-xr-x.  2 root  root     6 Nov  5  2016 include
drwxr-xr-x.  2 root  root     6 Nov  5  2016 lib
drwxr-xr-x.  2 root  root     6 Nov  5  2016 lib64
drwxr-xr-x.  2 root  root     6 Nov  5  2016 libexec
lrwxrwxrwx.  1 root  root    16 Mar  5 08:09 rocketmq -> alibaba-rocketmq
drwxr-xr-x.  2 root  root     6 Nov  5  2016 sbin
drwxr-xr-x.  5 root  root    49 Mar  1 19:46 share
drwxr-xr-x.  2 root  root   135 Mar  5 07:32 src

6. 创建存储路径(两台机器)

[root@masteryee-one local]# mkdir /usr/local/rocketmq/store
[root@masteryee-one local]# mkdir /usr/local/rocketmq/store/commitlog
[root@masteryee-one local]# mkdir /usr/local/rocketmq/store/consumequeue
[root@masteryee-one local]# mkdir /usr/local/rocketmq/store/index

7. RocketMQ配置文件(两台机器)

/usr/local/rocketmq/conf/2m-noslave/ 下有broker-a.properties 和 broker-b.properties 两个配置文件, 其实只需要改对应服务器上的配置文件即可, 即 Master1上改broker-a.properties, Master2上改broker-b.properties 就可以了, 我这里两台服务器的两个配置文件都改了

修改 broker-a.properties

[root@masteryee-one local]# vim /usr/local/rocketmq/conf/2m-noslave/broker-a.properties

broker-a.properties 的配置详情

#所属集群名字
brokerClusterName=rocketmq-cluster
#broker名字,注意此处不同的配置文件填写的不一样
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2: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
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/usr/local/rocketmq/store
#commitLog 存储路径
storePathCommitLog=/usr/local/rocketmq/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/usr/local/rocketmq/store/consumequeue
#消息索引存储路径
storePathIndex=/usr/local/rocketmq/store/index
#checkpoint 文件存储路径
storeCheckpoint=/usr/local/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/usr/local/rocketmq/store/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

修改 broker-b.properties

[root@masteryee-one local]# vim /usr/local/rocketmq/conf/2m-noslave/broker-b.properties

broker-b.properties 配置详情

#所属集群名字
brokerClusterName=rocketmq-cluster
#broker名字,注意此处不同的配置文件填写的不一样
brokerName=broker-b
#0 表示 Master,>0 表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2: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
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/usr/local/rocketmq/store
#commitLog 存储路径
storePathCommitLog=/usr/local/rocketmq/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/usr/local/rocketmq/store/consumequeue
#消息索引存储路径
storePathIndex=/usr/local/rocketmq/store/index
#checkpoint 文件存储路径
storeCheckpoint=/usr/local/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/usr/local/rocketmq/store/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

8. 修改日志配置文件(两台机器)

[root@masteryee-one local]# mkdir -p /usr/local/rocketmq/logs
[root@masteryee-one local]# cd /usr/local/rocketmq/conf && sed -i 's#${user.home}#/usr/local/rocketmq#g' *.xml

9. 修改启动脚本参数(两台机器)

broker和nameserver都有自己的jvm配置, 建议在生产服务器上使用默认即可, 因为本次是在虚拟机上安装,没有足够的内存, 所以需要修改一下配置

修改 runbroker.sh

vim /usr/local/rocketmq/bin/runbroker.sh


#===========================================================================================
# JVM Configuration
#===========================================================================================
JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -Xmn1g -XX:PermSize=128m -XX:MaxPermSize=320m"

修改 runserver.sh

vim /usr/local/rocketmq/bin/runserver.sh

#===========================================================================================
# JVM Configuration
#===========================================================================================
JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -Xmn1g -XX:PermSize=128m -XX:MaxPermSize=320m"

10. 启动NameServer(两台机器)

和ActiveMQ和Zookeeper一样, 在ActiveMQ集群环境中, 我们是先启动Zookeeper集群, 再启动ActiveMQ, 关机时, 是先关闭ActiveMQ, 再关闭Zookeeper

所以同样的, 在RocketMQ中, nameServer等同于Zookeeper的存在, 所以先启动NameServer, 再启动Broker, 关机时, 先关闭Broker, 再关闭NameServer

启动NameServer

[root@masteryee-one ~]# cd /usr/local/rocketmq/bin
[root@masteryee-one bin]# nohup sh mqnamesrv &

查看是否启动成功, 启动成功后有 NamesrvStartup 服务, 如下

// 主一
[root@masteryee-one bin]# jps
6530 Jps
6485 NamesrvStartup

// 主二
[root@masteryee-two bin]# jps
9573 NamesrvStartup
9631 Jps

查看NameServer启动日志

[root@masteryee-two bin]# tail -f -n 500 /usr/local/rocketmq/logs/rocketmqlogs/namesrv.log
2019-03-05 08:30:43 INFO main - rocketmqHome=/usr/local/rocketmq
2019-03-05 08:30:43 INFO main - kvConfigPath=/root/namesrv/kvConfig.json
2019-03-05 08:30:43 INFO main - listenPort=9876
2019-03-05 08:30:43 INFO main - serverWorkerThreads=8
2019-03-05 08:30:43 INFO main - serverCallbackExecutorThreads=0
2019-03-05 08:30:43 INFO main - serverSelectorThreads=3
2019-03-05 08:30:43 INFO main - serverOnewaySemaphoreValue=256
2019-03-05 08:30:43 INFO main - serverAsyncSemaphoreValue=64
2019-03-05 08:30:43 INFO main - serverChannelMaxIdleTimeSeconds=120
2019-03-05 08:30:43 INFO main - serverSocketSndBufSize=2048
2019-03-05 08:30:43 INFO main - serverSocketRcvBufSize=1024
2019-03-05 08:30:43 INFO main - serverPooledByteBufAllocatorEnable=false
2019-03-05 08:30:44 INFO main - The Name Server boot success.
2019-03-05 08:30:44 INFO NettyEventExecuter - NettyEventExecuter service started
2019-03-05 08:31:44 INFO NSScheduledThread1 - --------------------------------------------------------
2019-03-05 08:31:44 INFO NSScheduledThread1 - configTable SIZE: 0

11. 启动BrokerServer A(192.168.10.129)

注意启动的配置文件, 这里是broker-a.properties

[root@masteryee-one bin]# cd /usr/local/rocketmq/bin

[root@masteryee-one bin]# nohup sh mqbroker -c /usr/local/rocketmq/conf/2m-noslave/broker-a.properties >/dev/null 2>&1 &

12. 启动BrokerServer B(192.168.10.196)

注意启动的配置文件, 这里是broker-b.properties

[root@masteryee-one bin]# cd /usr/local/rocketmq/bin

[root@masteryee-one bin]# nohup sh mqbroker -c /usr/local/rocketmq/conf/2m-noslave/broker-b.properties >/dev/null 2>&1 &

13. 查看启动的服务(两台机器)

[root@masteryee-one bin]# jps
6485 NamesrvStartup
6965 Jps
6904 BrokerStartup

14. 查看日志

两台机器的查看日志命令都是如下

[root@masteryee-one bin]# tail -f -n 500 /usr/local/rocketmq/logs/rocketmqlogs/broker.log

日志下方出现这个才算是启动成功, 之前在云服务器中配置时, 因为两台服务器之间的防火墙没有关闭,导致端口没有开放,不能相互连接导致失败.
所以如果出现启动失败, 连接失败的情况, 先互相ping一下端口, 端口是9876

2019-03-05 08:35:29 INFO BrokerControllerScheduledThread1 - register broker to name server rocketmq-nameserver2:9876 OK
2019-03-05 08:35:29 INFO BrokerControllerScheduledThread1 - register broker to name server rocketmq-nameserver1:9876 OK

BrokerServer A的日志

[root@masteryee-one bin]# tail -f -n 500 /usr/local/rocketmq/logs/rocketmqlogs/broker.log
2019-03-05 08:35:17 INFO main - rocketmqHome=/usr/local/rocketmq
2019-03-05 08:35:17 INFO main - namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
2019-03-05 08:35:17 INFO main - brokerIP1=192.168.10.129
2019-03-05 08:35:17 INFO main - brokerIP2=192.168.10.129
2019-03-05 08:35:17 INFO main - brokerName=broker-a
2019-03-05 08:35:17 INFO main - brokerClusterName=rocketmq-cluster
... 中间部分省略
2019-03-05 08:35:17 INFO main - syncFlushTimeout=5000
2019-03-05 08:35:17 INFO main - messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
2019-03-05 08:35:17 INFO main - flushDelayOffsetInterval=10000
2019-03-05 08:35:17 INFO main - cleanFileForciblyEnable=true
2019-03-05 08:35:17 INFO main - user specfied name server address: rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
2019-03-05 08:35:17 INFO PullRequestHoldService - PullRequestHoldService service started
2019-03-05 08:35:18 INFO main - register broker to name server rocketmq-nameserver2:9876 OK
2019-03-05 08:35:19 INFO main - register broker to name server rocketmq-nameserver1:9876 OK
2019-03-05 08:35:19 INFO main - The broker[broker-a, 192.168.10.129:10911] boot success. and name server is rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
2019-03-05 08:35:27 INFO BrokerControllerScheduledThread1 - slave fall behind master, how much, 0 bytes
2019-03-05 08:35:29 INFO BrokerControllerScheduledThread1 - register broker to name server rocketmq-nameserver2:9876 OK
2019-03-05 08:35:29 INFO BrokerControllerScheduledThread1 - register broker to name server rocketmq-nameserver1:9876 OK

BrokerServer B的日志

[root@masteryee-two bin]# tail -f -n 500 /usr/local/rocketmq/logs/rocketmqlogs/broker.log
2019-03-05 08:35:23 INFO main - rocketmqHome=/usr/local/rocketmq
2019-03-05 08:35:23 INFO main - namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
2019-03-05 08:35:23 INFO main - brokerIP1=192.168.10.196
2019-03-05 08:35:23 INFO main - brokerIP2=192.168.10.196
2019-03-05 08:35:23 INFO main - brokerName=broker-b
2019-03-05 08:35:23 INFO main - brokerClusterName=rocketmq-cluster
... 中间部分省略
2019-03-05 08:35:23 INFO main - syncFlushTimeout=5000
2019-03-05 08:35:23 INFO main - messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
2019-03-05 08:35:23 INFO main - flushDelayOffsetInterval=10000
2019-03-05 08:35:23 INFO main - cleanFileForciblyEnable=true
2019-03-05 08:35:23 INFO main - user specfied name server address: rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
2019-03-05 08:35:24 INFO PullRequestHoldService - PullRequestHoldService service started
2019-03-05 08:35:24 INFO main - register broker to name server rocketmq-nameserver1:9876 OK
2019-03-05 08:35:24 INFO main - register broker to name server rocketmq-nameserver2:9876 OK
2019-03-05 08:35:24 INFO main - The broker[broker-b, 192.168.10.196:10911] boot success. and name server is rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
2019-03-05 08:35:34 INFO BrokerControllerScheduledThread1 - slave fall behind master, how much, 0 bytes
2019-03-05 08:35:34 INFO BrokerControllerScheduledThread1 - register broker to name server rocketmq-nameserver1:9876 OK
2019-03-05 08:35:34 INFO BrokerControllerScheduledThread1 - register broker to name server rocketmq-nameserver2:9876 OK

部署RocketMQ控制台

RocketMQ的控制台是单独的一个包, 需要使用tomcat单独部署

创建rocketmq-console文件夹

在 tomcat下的webapps下创建 rocketmq-console 文件夹

[root@masteryee-one webapps]# mkdir rocketmq-console 

上传war包解压

上传 rocketmq-console-3.2.6.war 包到 tomcat下的webapps下

解压到刚刚创建的 rocketmq-console 文件夹中

[root@masteryee-one webapps]# unzip -d rocketmq-console-3.2.6 rocketmq-console

移除war包, 这个没用了

[root@masteryee-one webapps]# rm -f rocketmq-console-3.2.6 rocketmq-console

修改连接配置文件

进入 解压后的 rocketmq-console/WEB-INF/classes/ 下

[root@masteryee-one webapps]# cd rocketmq-console/WEB-INF/classes/
[root@masteryee-one classes]# ls
com  config.properties  logback.xml  spring

修改配置文件

[root@masteryee-one classes]# vim config.properties 

IP:端口 用分号;相隔, 如下: 配置两台服务器

rocketmq.namesrv.addr=192.168.10.129:9876;192.168.10.196:9876
throwDone=true

你可能感兴趣的:(linux)