RocketMQ教程(三) - 高可用部署

目录

(一)基础
(二)进阶
(三)高可用部署
(四)常见问题

 

正文

这里采用双主双从的配置,选择Linux系统,并假定两台服务器的私有IP分别为192.168.0.1和192.168.0.2。

下载
http://rocketmq.apache.org/dowloading/releases/

解压
unzip rocketmq-all-4.5.0-bin-release.zip

分别在两台服务器上启动NameServer

nohup sh bin/mqnamesrv &

服务器1 Master Broker配置(conf/broker.conf)

namesrvAddr = 192.168.0.1:9876;192.168.0.2:9876
brokerClusterName = DefaultCluster
brokerIP1 = 192.168.0.1
brokerIP2 = 192.168.0.1
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 168
brokerRole = SYNC_MASTER
flushDiskType = ASYNC_FLUSH
listenPort = 10911
storePathRootDir = /home/rocketmq/store-a
sendMessageThreadPoolNums = 32

其中

namesrvAddr
NameServer的地址,配置多个以保证NameServer的高可用。

brokerClusterName
Cluster的地址,如果集群机器数比较多,可以分成多个Cluster,每个Cluster 供一个业务群使用。

brokerIP1
Broker监听的IP,如果有多个网卡,按需要配置公网或内网IP。

brokerIP2
Slave Broker连接主Broker的IP。

brokerName
Broker的名称,Master和Slave通过使用相同的Broker名称来表明相互关系。

brokerId
一个Master Broker可以有多个Slave,0表示Master,大于0表示不同Slave 的ID。

fileReservedTime
在磁盘上保存消息的时长,单位是小时,自动删除超时的消息。

deleteWhen
与fileReservedTime参数呼应,表明在几点做消息删除动作,默认值04表示凌晨4点。

brokerRole
SYNC_MASTER表示当Slave 和Master 消息同步完成后,再返回发送成功的状态。

flushDiskType
刷盘策略,分为SYNC_FLUSH和ASYNC_FLUSH两种,分别代表同步刷盘和异步刷盘。

listenPort
Broker监听的端口号,如果一台机器上启动了多个Broker,则要设置不同的端口号,避免冲突。

服务器2 Master Broker配置(conf/broker.conf)

namesrvAddr = 192.168.0.1:9876;192.168.0.2:9876
brokerClusterName = DefaultCluster
brokerIP1 = 192.168.0.2
brokerIP2 = 192.168.0.2
brokerName = broker-b
brokerId = 0
deleteWhen = 04
fileReservedTime = 168
brokerRole = SYNC_MASTER
flushDiskType = ASYNC_FLUSH
listenPort = 10911
storePathRootDir = /home/rocketmq/store-b
sendMessageThreadPoolNums = 32

服务器1 Slave Broker配置(conf/broker.conf)

namesrvAddr = 192.168.0.1:9876;192.168.0.2:9876
brokerClusterName = DefaultCluster
brokerIP1 = 192.168.0.1
brokerName = broker-b
brokerId = 1
deleteWhen = 04
fileReservedTime = 168
brokerRole = SLAVE
flushDiskType = ASYNC_FLUSH
listenPort=11011
storePathRootDir = /home/rocketmq/store-b
sendMessageThreadPoolNums = 32

服务器2 Slave Broker配置(conf/broker.conf)

namesrvAddr = 192.168.0.1:9876;192.168.0.2:9876
brokerClusterName = DefaultCluster
brokerIP1 = 192.168.0.2
brokerName = broker-a
brokerId = 1
deleteWhen = 04
fileReservedTime = 168
brokerRole = SLAVE
flushDiskType = ASYNC_FLUSH
listenPort=11011
storePathRootDir = /home/rocketmq/store-a
sendMessageThreadPoolNums = 32

分别启动两个Master Broker和两个Slave Broker

nohup sh bin/mqbroker -c conf/broker.conf &

这样一个高可用的RocketMQ集群就搭建好了,下面使用rocketmq-console检查其状态。

下载
https://github.com/apache/rocketmq-externals/tree/master/rocketmq-console

编译
mvn clean package -Dmaven.test.skip=true

在编译的rocketmq-console-ng-1.0.0.jar同目录下创建application.properties文件

server.contextPath=
server.port=8080
spring.application.name=rocketmq-console
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
logging.config=classpath:logback.xml
rocketmq.config.namesrvAddr=192.168.0.1:9876;192.168.0.2:9876
rocketmq.config.isVIPChannel=false
rocketmq.config.dataPath=/tmp/rocketmq-console/data
rocketmq.config.enableDashBoardCollect=true
rocketmq.config.msgTrackTopicName=

启动

java -jar rocketmq-console-ng-1.0.0.jar

用浏览器访问http://192.168.0.1:8080/#/cluster

RocketMQ教程(三) - 高可用部署_第1张图片

你可能感兴趣的:(分布式开发)