RocketMQ单机部署集群
环境准备
系统: centos 7
Java:1.8以上
关闭防火墙
软件包下载路径
https://archive.apache.org/dist/rocketmq/4.6.1/
安装部署
[root@rocketmq ~]# unzip rocketmq-all-4.6.1-bin-release.zip
创建存储(message持久化)目录,每一个broker制定一个持久化路径
mkdir -p /rocketmqStore/a-m
mkdir -p /rocketmqStore/a-s
mkdir -p /rocketmqStore/b-m
mkdir -p /rocketmqStore/b-s
启动nameserver,默认端口9876
[root@rocketmq ~]# nohup rocketmq-all-4.6.1-bin-release//bin/mqnamesrv &
[root@rocketmq ~]# nohup: 忽略输入并把输出追加到"nohup.out"
集群的配置文件
[root@rocketmq conf]# ll /root/rocketmq-all-4.6.1-bin-release/conf/
总用量 36
drwxr-xr-x. 2 root root 118 3月 9 13:58 2m-2s-async ##2主2从不实时同步配置文件
drwxr-xr-x. 2 root root 118 3月 9 14:38 2m-2s-sync ##2主2从实时同步
drwxr-xr-x. 2 root root 91 11月 28 20:47 2m-noslave ##2主0从
-rw-r--r--. 1 root root 949 1月 6 16:43 broker.conf ##只起单个broker的配置文件
drwxr-xr-x. 2 root root 72 11月 28 20:47 dledger
-rw-r--r--. 1 root root 14978 11月 28 20:47 logback_broker.xml
-rw-r--r--. 1 root root 3836 11月 28 20:47 logback_namesrv.xml
-rw-r--r--. 1 root root 3761 11月 28 20:47 logback_tools.xml
-rw-r--r--. 1 root root 1305 11月 28 20:47 plain_acl.yml
-rw-r--r--. 1 root root 834 11月 28 20:47 tools.yml
配置2主2从:
[root@rocketmq ~]# cd /root/rocketmq-all-4.6.1-bin-release/conf/2m-2s-sync
[root@rocketmq 2m-2s-sync]# ll
总用量 16
-rw-r--r-- 1 root root 1008 3月 9 14:32 broker-a.properties
-rw-r--r-- 1 root root 1002 3月 9 14:32 broker-a-s.properties
-rw-r--r-- 1 root root 1008 3月 9 14:33 broker-b.properties
-rw-r--r-- 1 root root 1002 3月 9 14:33 broker-b-s.properties
cd /root/rocketmq-all-4.6.1-bin-release/conf/
vim 2m-2s-sync/broker-a.properties
brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
listenPort=10911
storePathRootDir=/rocketmqStore/a-m
namesrvAddr=127.0.0.1:9876
vim 2m-2s-sync/broker-a-s.properties
brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
listenPort=10811
storePathRootDir=/rocketmqStore/a-s
namesrvAddr=127.0.0.1:9876
vim 2m-2s-sync/broker-b.properties
brokerClusterName=DefaultCluster
brokerName=broker-b
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
listenPort=10711
storePathRootDir=/rocketmqStore/b-m
namesrvAddr=127.0.0.1:9876
vim 2m-2s-sync/broker-b-s.properties
brokerClusterName=DefaultCluster
brokerName=broker-b
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
listenPort=10611
storePathRootDir=/rocketmqStore/b-s
namesrvAddr=127.0.0.1:9876
启动namesrv、broker前修改bin/runserver.sh、bin/runbroker.sh
修改java内存大小(默认为4G,服务器内存无法分配那么多)
vim bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms64m -Xmx64m -Xmn32m"
vim bin/runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms64m -Xmx64m -Xmn32m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=128m"
先启动mqnamesrv
nohup mqnamesrv &
然后启动4个broker -c用于指定启动配置文件
cd /conf
nohup mqbroker -c broker-a.properties &
nohup mqbroker -c broker-a-s.properties &
nohup mqbroker -c broker-b.properties &
nohup mqbroker -c broker-b-s.properties &
生产者和消费者测试
声明nameserver、rocketmq环境变量
export ROCKETMQ_HOME=/usr/local/rocketmq/rocketmq-all-4.3.2-bin-release
export NAMESRV_ADDR=‘localhost:9876‘
PATH=$PATH:$JAVA_HOME/bin:$ROCKETMQ_HOME/bin
export PATH
生产者测试(因为配置了ROCKETMQ_HOME,所以不需要加路径前缀):
tools.sh org.apache.rocketmq.example.quickstart.Producer
消费者测试:
tools.sh org.apache.rocketmq.example.quickstart.Consumer
Rocketmq-console安装
git下载rocketmq-console源码
cd rocketmq-console
mvn clean package -Dmaven.test.skip=true
注意:打包前在rocketmq-console中配置namesrv集群地址
rocketmq.config.namesrvAddr=47.98.47.1
上传服务器后,启动rocketmq-console:
java -jar rocketmq-console-ng-1.0.0.jar
启动成功后,通过浏览器访问,localhost:8080进入控制台