分布式消息队列RocketMQ
二、 RocketMQ的安装与启动
3.1)单机安装与启动
3.1.1)准备工作
软硬件需求:Linux系统要求是64位的,JDK要求是1.8及其以上版本的。
下载RocketMQ安装包:Apache RocketMQ
?上传安装包至Linux服务器下,并解压,路径如下:
[root@VM-20-6-centos rocketmq-4.9.3]# pwd
/root/rocketmq/rocketmq-4.9.3
[root@VM-20-6-centos rocketmq-4.9.3]# ll
total 48
drwxr-xr-x 2 root root 4096 Feb 22 01:25 benchmark
drwxr-xr-x 3 root root 4096 Feb 22 00:25 bin
drwxr-xr-x 7 root root 4096 Feb 22 00:25 conf
drwxr-xr-x 2 root root 4096 Feb 22 01:25 lib
-rw-r--r-- 1 root root 17327 Feb 22 00:25 LICENSE
-rw-r--r-- 1 root root 1338 Feb 22 00:25 NOTICE
-rw-r--r-- 1 root root 6069 Feb 22 00:25 README.md
3.1.2)修改初始内存
修改配置文件:runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
修改为:
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
修改配置文件:runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g"
修改为:
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m"
3.1.3)启动
启动NameServer
[root@VM-20-6-centos rocketmq-4.9.3]# pwd
/root/rocketmq/rocketmq-4.9.3
[root@VM-20-6-centos rocketmq-4.9.3]# nohup sh bin/mqnamesrv &
[1] 29042
[root@VM-20-6-centos rocketmq-4.9.3]# nohup: ignoring input and appending output to ‘nohup.out’
[root@VM-20-6-centos rocketmq-4.9.3]# jps -l
29063 org.apache.rocketmq.namesrv.NamesrvStartup
[root@VM-20-6-centos rocketmq-4.9.3]# tail -f ~/logs/rocketmqlogs/namesrv.log
2022-04-27 22:05:02 INFO main - tls.client.keyPassword = null
2022-04-27 22:05:02 INFO main - tls.client.certPath = null
2022-04-27 22:05:02 INFO main - tls.client.authServer = false
2022-04-27 22:05:02 INFO main - tls.client.trustCertPath = null
2022-04-27 22:05:02 INFO main - Using JDK SSL provider
2022-04-27 22:05:03 INFO main - SSLContext created for server
2022-04-27 22:05:03 INFO main - Try to start service thread:FileWatchService started:false lastThread:null
2022-04-27 22:05:03 INFO NettyEventExecutor - NettyEventExecutor service started
2022-04-27 22:05:03 INFO main - The Name Server boot success. serializeType=JSON
2022-04-27 22:05:03 INFO FileWatchService - FileWatchService service started
启动broker
[root@VM-20-6-centos rocketmq-4.9.3]# pwd
/root/rocketmq/rocketmq-4.9.3
root@VM-20-6-centos rocketmq-4.9.3]# nohup sh bin/mqbroker -n localhost:9876 &
[2] 15158
[root@VM-20-6-centos rocketmq-4.9.3]# nohup: ignoring input and appending output to ‘nohup.out’
?
[root@VM-20-6-centos rocketmq-4.9.3]# tail -f ~/logs/rocketmqlogs/broker.log
2022-04-27 22:10:01 INFO main - Try to start service thread:FileWatchService started:false lastThread:null
2022-04-27 22:10:01 INFO main - Try to start service thread:PullRequestHoldService started:false lastThread:null
2022-04-27 22:10:01 INFO FileWatchService - FileWatchService service started
2022-04-27 22:10:01 INFO main - Try to start service thread:TransactionalMessageCheckService started:false lastThread:null
2022-04-27 22:10:01 INFO PullRequestHoldService - PullRequestHoldService service started
2022-04-27 22:10:02 INFO brokerOutApi_thread_1 - register broker[0]to name server localhost:9876 OK
2022-04-27 22:10:02 INFO main - The broker[VM-20-6-centos, 10.0.20.6:10911] boot success. serializeType=JSON and name server is localhost:9876
2022-04-27 22:10:11 INFO BrokerControllerScheduledThread1 - dispatch behind commit log 0 bytes
2022-04-27 22:10:11 INFO BrokerControllerScheduledThread1 - Slave fall behind master: 0 bytes
2022-04-27 22:10:12 INFO brokerOutApi_thread_2 - register broker[0]to name server localhost:9876 OK
2022-04-27 22:11:01 INFO TransactionalMessageCheckService - create new topic TopicConfig [topicName=RMQ_SYS_TRANS_HALF_TOPIC, readQueueNums=1, writeQueueNums=1, perm=RW-, topicFilterType=SINGLE_TAG, topicSysFlag=0, order=false]
2022-04-27 22:11:01 INFO brokerOutApi_thread_4 - register broker[0]to name server localhost:9876 OK
2022-04-27 22:11:11 INFO BrokerControllerScheduledThread1 - dispatch behind commit log 0 bytes
2022-04-27 22:11:11 INFO BrokerControllerScheduledThread1 - Slave fall behind master: 0 bytes
2022-04-27 22:11:12 INFO brokerOutApi_thread_1 - register broker[0]to name server localhost:9876 OK
3.1.4)发送/接收消息测试
发送消息
> export NAMESRV_ADDR=localhost:9876
> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
SendResult [sendStatus=SEND_OK, msgId= ...
SendResult [sendStatus=SEND_OK, msgId= ...
SendResult [sendStatus=SEND_OK, msgId= ...
接收消息
> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
ConsumeMessageThread_%d Receive New Messages: [MessageExt...
3.1.5)关闭Server
无论是关闭name server还是broker,都是使用bin/mqshutdown命令
[root@VM-20-6-centos rocketmq-4.9.3]# sh bin/mqshutdown broker
The mqbroker(15602) is running...
Send shutdown request to mqbroker(15602) OK
?
[root@VM-20-6-centos rocketmq-4.9.3]# sh bin/mqshutdown namesrv
The mqnamesrv(13506) is running...
Send shutdown request to mqnamesrv(13506) OK
[2]+ Exit 143 ? ? ? ? ? ? ? nohup sh bin/mqbroker -n localhost:9876
|