Linux 安装 RocketMQ 4.9.2

1、预先安装JDK1.8,此处略过安装JDK步骤。

2、先开放MQ所需要用到的端口 9876 和 10909、10910、10911、10912

[root@VM-8-16-centos ~]# firewall-cmd --zone=public --add-port=9876/tcp --permanent
success
[root@VM-8-16-centos ~]# firewall-cmd --zone=public --add-port=10909-10912/tcp --permanent
success
[root@VM-8-16-centos ~]# firewall-cmd --reload    # 重启防火墙,安全策略也需要开放以上端口

3、使用wget下载 rocketmq-all-4.9.2-bin-release.zip,下载完并使用unzip命令解压。

[root@VM-8-16-centos ~]# cd /usr/local/    # 下载并解压在此目录下
[root@VM-8-16-centos local]# wget https://archive.apache.org/dist/rocketmq/4.9.2/rocketmq-all-4.9.2-bin-release.zip
--2022-09-22 11:41:28--  https://archive.apache.org/dist/rocketmq/4.9.2/rocketmq-all-4.9.2-bin-release.zip
Resolving archive.apache.org (archive.apache.org)... 138.201.131.134, 2a01:4f8:172:2ec5::2
Connecting to archive.apache.org (archive.apache.org)|138.201.131.134|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 20007209 (19M) [application/zip]
Saving to: ‘rocketmq-all-4.9.2-bin-release.zip’

100%[=======================================================================================================================================================================================================>] 20,007,209  4.00MB/s   in 5.9s   

2022-09-22 11:41:34 (3.26 MB/s) - ‘rocketmq-all-4.9.2-bin-release.zip’ saved [20007209/20007209]

[root@VM-8-16-centos local]# ll
-rw-r--r--   1 root   root   20007209 Oct 26  2021 rocketmq-all-4.9.2-bin-release.zip
[root@VM-8-16-centos local]# unzip rocketmq-all-4.9.2-bin-release.zip
[root@VM-8-16-centos local]# ll
drwxr-xr-x   6 root   root       4096 Sep 22 11:01 rocketmq-4.9.2
-rw-r--r--   1 root   root   20007209 Oct 26  2021 rocketmq-all-4.9.2-bin-release.zip

4、解压完,进入rocketmq-4.9.2下的conf目录,修改 broker.conf 配置文件,添加两行配置。

[root@VM-8-16-centos local]# cd rocketmq-4.9.2/
[root@VM-8-16-centos rocketmq-4.9.2]# vim conf/broker.conf

# 填写自己Linux服务器的IP地址
namesrvAddr=175.178.236.232:9876
brokerIP1=175.178.236.232

5、修改bin目录下:runserver.sh 和 runbroker.sh 脚本的启动参数

5.1 修改runserver.sh,因为的本演示机运行内存4G,可以根据自己的运行内存改大小。

5.2 修改runbroker.sh ,因为的本演示机运行内存4G,可以根据自己的运行内存改大小。

 6、启动 RocketMQ,需要启动 NameServer 和 Broker,先启动 NameServer,使用 jps 命令看到 NamesrvStartup 就是启动成功了,再看看启动日志,日志没报错,没有问题。

[root@VM-8-16-centos rocketmq-4.9.2]# nohup sh bin/mqnamesrv -n 175.178.236.232:9876 &
[21] 6951
[root@VM-8-16-centos rocketmq-4.9.2]# nohup: ignoring input and appending output to ‘nohup.out’

[root@VM-8-16-centos rocketmq-4.9.2]# jps
5585 Consumer
4786 nacos-server.jar
31827 Producer
6371 -- process information unavailable
32724 Producer
5476 Producer
1110 halo.jar
7020 Jps
6972 NamesrvStartup
1039 Producer
[root@VM-8-16-centos rocketmq-4.9.2]# tail -20f ~/logs/rocketmqlogs/namesrv.log
2022-09-22 15:57:56 INFO main - Tls config file doesn't exist, skip it
2022-09-22 15:57:56 INFO main - Log the final used tls related configuration
2022-09-22 15:57:56 INFO main - tls.test.mode.enable = true
2022-09-22 15:57:56 INFO main - tls.server.need.client.auth = none
2022-09-22 15:57:56 INFO main - tls.server.keyPath = null
2022-09-22 15:57:56 INFO main - tls.server.keyPassword = null
2022-09-22 15:57:56 INFO main - tls.server.certPath = null
2022-09-22 15:57:56 INFO main - tls.server.authClient = false
2022-09-22 15:57:56 INFO main - tls.server.trustCertPath = null
2022-09-22 15:57:56 INFO main - tls.client.keyPath = null
2022-09-22 15:57:56 INFO main - tls.client.keyPassword = null
2022-09-22 15:57:56 INFO main - tls.client.certPath = null
2022-09-22 15:57:56 INFO main - tls.client.authServer = false
2022-09-22 15:57:56 INFO main - tls.client.trustCertPath = null
2022-09-22 15:57:56 INFO main - Using JDK SSL provider
2022-09-22 15:57:57 INFO main - SSLContext created for server
2022-09-22 15:57:57 INFO main - Try to start service thread:FileWatchService started:false lastThread:null
2022-09-22 15:57:57 INFO NettyEventExecutor - NettyEventExecutor service started
2022-09-22 15:57:57 INFO main - The Name Server boot success. serializeType=JSON
2022-09-22 15:57:57 INFO FileWatchService - FileWatchService service started

7、启动 Broker,如果你上面没开放 9876 端口的话,这里虽然显示启动成功了,但是日志里可能会出现连接不上的错误,看最后 to name server 175.178.236.232:9876 OK  就可以了。

[root@VM-8-16-centos rocketmq-4.9.2]# nohup sh bin/mqbroker -n 175.178.236.232:9876 -c conf/broker.conf autoCreateTopicEnable=true &
[22] 8842
[root@VM-8-16-centos rocketmq-4.9.2]# nohup: ignoring input and appending output to ‘nohup.out’

[root@VM-8-16-centos rocketmq-4.9.2]# tail -f ~/logs/rocketmqlogs/broker.log 
2022-09-22 16:05:41 INFO HeartbeatThread_1 - registerConsumer info changed ConsumerData [groupName=test-consumer, consumeType=CONSUME_PASSIVELY, messageModel=CLUSTERING, consumeFromWhere=CONSUME_FROM_LAST_OFFSET, unitMode=false, subscriptionDataSet=[SubscriptionData [classFilterMode=false, topic=test-topic, subString=*, tagsSet=[], codeSet=[], subVersion=1663830363915, expressionType=TAG], SubscriptionData [classFilterMode=false, topic=%RETRY%test-consumer, subString=*, tagsSet=[], codeSet=[], subVersion=1663830363818, expressionType=TAG]]] 113.110.228.103:64587
2022-09-22 16:05:41 INFO HeartbeatThread_1 - new consumer connected, group: test-consumer2 CONSUME_PASSIVELY CLUSTERING channel: ClientChannelInfo [channel=[id: 0x2af57d85, L:/10.0.8.16:10911 - R:/113.110.228.103:64587], clientId=10.69.249.156@21204, language=JAVA, version=277, lastUpdateTimestamp=1663833941958]
2022-09-22 16:05:41 INFO HeartbeatThread_1 - subscription changed, add new topic, group: test-consumer2 SubscriptionData [classFilterMode=false, topic=test-topic2, subString=*, tagsSet=[], codeSet=[], subVersion=1663830965607, expressionType=TAG]
2022-09-22 16:05:41 INFO HeartbeatThread_1 - subscription changed, add new topic, group: test-consumer2 SubscriptionData [classFilterMode=false, topic=%RETRY%test-consumer2, subString=*, tagsSet=[], codeSet=[], subVersion=1663830384010, expressionType=TAG]
2022-09-22 16:05:41 INFO HeartbeatThread_1 - registerConsumer info changed ConsumerData [groupName=test-consumer2, consumeType=CONSUME_PASSIVELY, messageModel=CLUSTERING, consumeFromWhere=CONSUME_FROM_LAST_OFFSET, unitMode=false, subscriptionDataSet=[SubscriptionData [classFilterMode=false, topic=test-topic2, subString=*, tagsSet=[], codeSet=[], subVersion=1663830965607, expressionType=TAG], SubscriptionData [classFilterMode=false, topic=%RETRY%test-consumer2, subString=*, tagsSet=[], codeSet=[], subVersion=1663830384010, expressionType=TAG]]] 113.110.228.103:64587
2022-09-22 16:05:41 INFO HeartbeatThread_1 - new producer connected, group: test-group channel: ClientChannelInfo [channel=[id: 0x2af57d85, L:/10.0.8.16:10911 - R:/113.110.228.103:64587], clientId=10.69.249.156@21204, language=JAVA, version=277, lastUpdateTimestamp=1663833941959]
2022-09-22 16:05:41 INFO HeartbeatThread_1 - new producer connected, group: CLIENT_INNER_PRODUCER channel: ClientChannelInfo [channel=[id: 0x2af57d85, L:/10.0.8.16:10911 - R:/113.110.228.103:64587], clientId=10.69.249.156@21204, language=JAVA, version=277, lastUpdateTimestamp=1663833941959]
2022-09-22 16:05:51 INFO BrokerControllerScheduledThread1 - dispatch behind commit log 0 bytes
2022-09-22 16:05:51 INFO BrokerControllerScheduledThread1 - Slave fall behind master: 388358 bytes
2022-09-22 16:05:51 INFO brokerOutApi_thread_2 - register broker[0]to name server 175.178.236.232:9876 OK

8、测试消息发送和消费

8.1 发送消息:

[root@VM-8-16-centos rocketmq-4.9.2]# export NAMESRV_ADDR=175.178.236.232:9876
[root@VM-8-16-centos rocketmq-4.9.2]# sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer

发送成功的输出 :

8.2 消费消息,命令是执行了,但是显示这样的,就是说明运行内存不足,需要释放内存。

[root@VM-8-16-centos rocketmq-4.9.2]# export NAMESRV_ADDR=175.178.236.232:9876
[root@VM-8-16-centos rocketmq-4.9.2]# sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c0000000, 805306368, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 805306368 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /usr/local/rocketmq-4.9.2/hs_err_pid11456.log
[root@VM-8-16-centos rocketmq-4.9.2]# 

释放内存重新来一遍,如果还是没成功,可能是10911端口没开放,需要先开放端口再重试,消费成功信息如下:

 9、关闭 RocketMQ,关闭RocketMQ的时候,需要先先关闭 Broker,然后再关闭 Name Server。

[root@VM-8-16-centos rocketmq-4.9.2]# sh bin/mqshutdown broker
The mqbroker(8850) is running...
Send shutdown request to mqbroker(8850) OK
[root@VM-8-16-centos rocketmq-4.9.2]# sh bin/mqshutdown namesrv
The mqnamesrv(6972) is running...
Send shutdown request to mqnamesrv(6972) OK
[22]   Exit 143                nohup sh bin/mqbroker -n 175.178.236.232:9876 -c conf/broker.conf autoCreateTopicEnable=true

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值