CentOS下RocketMQ单机版安装

这里介绍怎么在CentOS下安装RocketMQ单机版。

一、准备工作

  • 安装好jdk,并且已经配置好jdk环境变量
image
  • 关闭CentOS防火墙(这里主要是为了方便,在生产环境建议单纯开放RocketMq访问端口:9876)
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# 

二、安装RocketMQ

1. 从RocketMQ官网下载RocketMQ的二进制安装包,下载链接如下:
https://www-eu.apache.org/dist/rocketmq/4.4.0/rocketmq-all-4.4.0-bin-release.zip
2. 将RocketMQ安装包上传到CentOS,并且使用unzip命令解压,重命名为rocketmq
[root@localhost opt]# ll
总用量 202544
drwxr-xr-x. 7   10  143       245 7月   4 19:37 java
-rw-r--r--. 1 root root 195094741 8月  17 14:45 jdk-8u221-linux-x64.tar.gz
drwxr-xr-x. 6 root root       103 1月  22 2019 rocketmq-all-4.4.0-bin-release
-rw-r--r--. 1 root root  12306820 8月  17 21:06 rocketmq-all-4.4.0-bin-release.zip
[root@localhost opt]# mv rocketmq-all-4.4.0-bin-release rocketmq
[root@localhost opt]# ll
总用量 202544
drwxr-xr-x. 7   10  143       245 7月   4 19:37 java
-rw-r--r--. 1 root root 195094741 8月  17 14:45 jdk-8u221-linux-x64.tar.gz
drwxr-xr-x. 6 root root       103 1月  22 2019 rocketmq
-rw-r--r--. 1 root root  12306820 8月  17 21:06 rocketmq-all-4.4.0-bin-release.zip
[root@localhost opt]# 
3. 修改broker.conf(该文件所在目录:/opt/rocketmq/conf/broker.conf),添加nameServer地址的属性以及自动创建Topic的属性
namesrvAddr = 127.0.0.1:9876
autoCreateTopicEnable = true
image
4. 修改jvm参数,RocketMQ默认启动需要的jvm内存很大,这里需要根据自己实际的内存进行修改

主要改动两个文件,即bin目录下的runserver.sh和runbroker.sh
修改runserver.sh, 将

JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

修改为:

JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

修改runbroker.sh,将

JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"

修改为

JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m"
5. 新建nameserver和broker启动和关闭脚本

在rocketMQ的解压目录新建start_namesrv.sh(开启NameServer)、start_broker.sh(开启broker)、stop_namesrv.sh(关闭nameserver)、stop_broker.sh(关闭broker)四个nameserver和broker的启动和关闭脚本,目录是

[root@localhost rocketmq]# pwd
/opt/rocketmq
[root@localhost rocketmq]# ll
总用量 36
drwxr-xr-x. 2 root root    83 1月  17 2019 benchmark
drwxr-xr-x. 2 root root  4096 8月  17 21:17 bin
drwxr-xr-x. 5 root root   196 8月  17 21:12 conf
drwxr-xr-x. 2 root root  4096 1月  17 2019 lib
-rw-r--r--. 1 root root 17336 1月  17 2019 LICENSE
-rw-r--r--. 1 root root  1337 1月  17 2019 NOTICE
-rw-r--r--. 1 root root  2481 1月  17 2019 README.md
[root@localhost rocketmq]# 
  • start_namesrv.sh内容:
nohup sh bin/mqnamesrv &
  • start_broker.sh内容
nohup sh bin/mqbroker -c /opt/rocketmq/conf/broker.conf &
  • stop_namesrv.sh内容
sh bin/mqshutdown namesrv
  • stop_broker.sh内容
sh bin/mqshutdown broker

新建完四个脚本后如下:


image

由上图可以看出,这四个启动脚本还没有执行的权限,下面通过chmod命令增加执行权限

[root@localhost rocketmq]# chmod +x start_namesrv.sh 
[root@localhost rocketmq]# chmod +x start_broker.sh 
[root@localhost rocketmq]# chmod +x stop_namesrv.sh 
[root@localhost rocketmq]# chmod +x stop_broker.sh 
[root@localhost rocketmq]# ll
总用量 52
drwxr-xr-x. 2 root root    83 1月  17 2019 benchmark
drwxr-xr-x. 2 root root  4096 8月  17 21:17 bin
drwxr-xr-x. 5 root root   196 8月  17 21:12 conf
drwxr-xr-x. 2 root root  4096 1月  17 2019 lib
-rw-r--r--. 1 root root 17336 1月  17 2019 LICENSE
-rw-r--r--. 1 root root  1337 1月  17 2019 NOTICE
-rw-r--r--. 1 root root  2481 1月  17 2019 README.md
-rwxr-xr-x. 1 root root    58 8月  17 21:24 start_broker.sh
-rwxr-xr-x. 1 root root    23 8月  17 21:22 start_namesrv.sh
-rwxr-xr-x. 1 root root    25 8月  17 21:27 stop_broker.sh
-rwxr-xr-x. 1 root root    26 8月  17 21:27 stop_namesrv.sh
[root@localhost rocketmq]# 
image
6. 启动rocketMQ

启动RocketMQ分为两步,一步是启动nameserver,一步是启动broker,必须先启动namesrv才能启动broker

  • 执行start_namesrv.sh启动nameserver,
[root@localhost rocketmq]# ./start_namesrv.sh 
[root@localhost rocketmq]# nohup: 把输出追加到"nohup.out"
^C
[root@localhost rocketmq]# tail -f ~/logs/rocketmqlogs/namesrv.log 
2019-08-17 21:33:29 INFO main - tls.client.keyPath = null
2019-08-17 21:33:29 INFO main - tls.client.keyPassword = null
2019-08-17 21:33:29 INFO main - tls.client.certPath = null
2019-08-17 21:33:29 INFO main - tls.client.authServer = false
2019-08-17 21:33:29 INFO main - tls.client.trustCertPath = null
2019-08-17 21:33:29 INFO main - Using OpenSSL provider
2019-08-17 21:33:29 INFO main - SSLContext created for server
2019-08-17 21:33:29 INFO NettyEventExecutor - NettyEventExecutor service started
2019-08-17 21:33:29 INFO main - The Name Server boot success. serializeType=JSON
2019-08-17 21:33:30 INFO FileWatchService - FileWatchService service started

通过上面的日志可以发现nameserver启动成功。通过jps命令查看进程可以发现存在NamesrvStartup进程

[root@localhost rocketmq]# jps
16984 NamesrvStartup
17004 Jps
[root@localhost rocketmq]# 
  • 执行stop_broker.sh启动broker,
[root@localhost rocketmq]# ./start_broker.sh 
[root@localhost rocketmq]# nohup: 把输出追加到"nohup.out"
^C
[root@localhost rocketmq]# tail -f ~/logs/rocketmqlogs/broker.log 
2019-08-17 21:35:51 INFO main - fastFailIfNoBufferInStorePool=false
2019-08-17 21:35:52 INFO main - Set user specified name server address: 127.0.0.1:9876
2019-08-17 21:35:52 WARN main - Load default transaction message hook service: TransactionalMessageServiceImpl
2019-08-17 21:35:52 WARN main - Load default discard message hook service: DefaultTransactionalMessageCheckListener
2019-08-17 21:35:52 INFO main - The broker dose not enable acl
2019-08-17 21:35:52 INFO FileWatchService - FileWatchService service started
2019-08-17 21:35:52 INFO PullRequestHoldService - PullRequestHoldService service started
2019-08-17 21:35:52 INFO brokerOutApi_thread_1 - register broker to name server 127.0.0.1:9876 OK
2019-08-17 21:35:52 INFO main - Start transaction service!
2019-08-17 21:35:52 INFO main - The broker[broker-a, 192.168.154.130:10911] boot success. serializeType=JSON and name server is 127.0.0.1:9876
2019-08-17 21:36:02 INFO BrokerControllerScheduledThread1 - dispatch behind commit log 0 bytes
2019-08-17 21:36:02 INFO BrokerControllerScheduledThread1 - Slave fall behind master: 0 bytes
2019-08-17 21:36:02 INFO brokerOutApi_thread_2 - register broker to name server 127.0.0.1:9876 OK

通过上面的日志可以发现broker启动成功,并且broker成功注册到nameserver上。通过jps命令查看进程可以发现存在BrokerStartup进程

[root@localhost rocketmq]# jps
17027 BrokerStartup
17127 Jps
16984 NamesrvStartup
[root@localhost rocketmq]# 

至此,NameServer单机版启动成功

7. 关闭rocketMQ

由上面步骤可以得知,启动RocketMQ的过程中必须先启动NameServer,然后再启动Broker。
关闭RocketMQ的步骤刚好相反,需要先关闭Broker,然后再关闭NameServer

  • 通过stop_broker.sh关闭broker
[root@localhost rocketmq]# ./stop_broker.sh 
The mqbroker(17027) is running...
Send shutdown request to mqbroker(17027) OK

查看日志和Java进程可以发现,broker关闭成功

[root@localhost rocketmq]# jps
17200 Jps
16984 NamesrvStartup
[root@localhost rocketmq]# tail -f ~/logs/rocketmqlogs/broker.log 
2019-08-17 21:41:41 INFO ShutdownHook - shutdown thread ReputMessageService interrupt false
2019-08-17 21:41:41 INFO ShutdownHook - join thread ReputMessageService eclipse time(ms) 0 90000
2019-08-17 21:41:41 INFO ShutdownHook - shutdown thread FlushConsumeQueueService interrupt false
2019-08-17 21:41:41 INFO ShutdownHook - join thread FlushConsumeQueueService eclipse time(ms) 1 60000
2019-08-17 21:41:41 INFO ShutdownHook - unregisterBroker OK, NamesrvAddr: 127.0.0.1:9876
2019-08-17 21:41:41 INFO ShutdownHook - shutdown thread FileWatchService interrupt false
2019-08-17 21:41:41 INFO ShutdownHook - join thread FileWatchService eclipse time(ms) 0 90000
2019-08-17 21:41:41 INFO ShutdownHook - shutdown thread TransactionalMessageCheckService interrupt false
2019-08-17 21:41:41 INFO ShutdownHook - join thread TransactionalMessageCheckService eclipse time(ms) 1 90000
2019-08-17 21:41:41 INFO ShutdownHook - Shutdown hook over, consuming total time(ms): 4626
  • 通过stop_namesrv.sh关闭nameserver
[root@localhost rocketmq]# ./stop_namesrv.sh 
The mqnamesrv(16984) is running...
Send shutdown request to mqnamesrv(16984) OK

查看日志和Java进程可以发现,nameserver关闭成功

[root@localhost rocketmq]# jps
17237 Jps
[root@localhost rocketmq]# tail -f ~/logs/rocketmqlogs/namesrv.log 
2019-08-17 21:41:41 INFO NettyServerCodecThread_1 - NETTY SERVER PIPELINE: channelInactive, the channel[127.0.0.1:59032]
2019-08-17 21:41:41 INFO NettyServerCodecThread_1 - NETTY SERVER PIPELINE: channelUnregistered, the channel[127.0.0.1:59032]
2019-08-17 21:43:29 INFO ShutdownHook - shutdown hook was invoked, 1 times.
2019-08-17 21:43:29 INFO ShutdownHook - shutdown thread NettyEventExecutor interrupt false
2019-08-17 21:43:29 INFO NettyEventExecutor - NettyEventExecutor service end
2019-08-17 21:43:29 INFO ShutdownHook - join thread NettyEventExecutor eclipse time(ms) 65 90000
2019-08-17 21:43:29 INFO ShutdownHook - shutdown thread FileWatchService interrupt false
2019-08-17 21:43:29 INFO FileWatchService - FileWatchService service end
2019-08-17 21:43:29 INFO ShutdownHook - join thread FileWatchService eclipse time(ms) 5 90000
2019-08-17 21:43:29 INFO ShutdownHook - shutdown hook done, consuming time total(ms): 98

至此,RocketMQ启动和关闭介绍完毕。

三、安装RocketMQ-Console-ng

RocketMQ官方还提供了一个监控平台,我们可以通过监控平台查看RocketMQ运行状态以及生产者和消费者的信息等,这里介绍怎么搭建RocketMQ-Console-ng。rocketmq-console-ng需要我们通过官方提供的源码编译出jar包部署

1. 首先,从github上将监控平台的项目源码下载下来,地址如下:
https://github.com/apache/rocketmq-externals
2. 然后通过cmd命令进入对应的rocketmq-console目录执行maven打包命令
D:\source\rocketmq\rocketmq-externals-master\rocketmq-console>mvn clean package -Dmaven.test.skip=true

结果如下:


image
3. 将上一步打包出来的target/rocketmq-console-ng-1.0.1.jar包上传到CentOS中
[root@localhost opt]# cd rocketmq-console/
[root@localhost rocketmq-console]# ll
总用量 32496
-rw-r--r--. 1 root root 33275652 8月  17 21:54 rocketmq-console-ng-1.0.1.jar
[root@localhost rocketmq-console]# pwd
/opt/rocketmq-console
[root@localhost rocketmq-console]# 

其中rocketmq-console文件夹是自己新建的,为了方便管理

4. 新建start_rocketmq_console.sh脚本,用来启动rocketmq-console-ng-1.0.1.jar项目

start_rocketmq-console.sh内容如下

nohup java -jar rocketmq-console-ng-1.0.1.jar --server.port=8080 --rocketmq.config.namesrvAddr=127.0.0.1:9876 &

其中--server.port配置的是启动端口,--rocketmq.config.namesrvAddr配置的是nameserver的地址和端口,多个nameserver可以通过分号(;)隔开


image

给脚本start_rocketmq_console.sh添加执行权限

[root@localhost rocketmq-console]# chmod +x start_rocketmq_console.sh 
[root@localhost rocketmq-console]# 
image
5. 启动rocketmq-console-ng

image

通过查看日志可以发现项目启动成功
访问http://IP:8080/,可以发现,访问成功
image

至此RocketMQ监控平台rocketmq-console-ng部署成功。
注意:rocket-console-ng关闭可以通过杀进程的方式

四、至此,RocketMQ单机版和RocketMQ监控平台rocket-console-ng安装部署完毕

你可能感兴趣的:(CentOS下RocketMQ单机版安装)