启动name server
nohup sh bin/mqnamesrv &
tail -f ~/logs/rocketmqlogs/namesrv.log
启动broker
nohup sh bin/mqbroker -n localhost:9876 &
tail -f ~/logs/rocketmqlogs/broker.log
-n: name server
生产/消费测试消息
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
shutdown server
sh bin/mqshutdown broker
sh bin/mqshutdown namesrv
下broker
先关掉broker的读写权限,客户端对这个节点的读写操作会报no permission异常,客户端会重试其他节点
观察该节点无读写流量后,再执行下机器操作
集群搭建
修改配置文件
配置文件目录conf
配置文件broker-a.properties
参数名 | 参考值 | 说明 |
---|---|---|
brokerClusterName | broker集群名 | |
brokerName | broker-a | 指定master - slave集群的名称,一个rocketmq集群可以包含多个master-slave集群 |
brokerId | 0 | 0为master,非0为slave |
deletewhen | 04(凌晨4点) | 指定删除消息存储过期文件的时间 |
fileReservedTime | 48(48h后过期) | 指定未发生更新的消息存储文件的保留时间 |
brokerRole | ASYNC_MASTER(异步复制master) | |
flushDiskType | ASYNC_FLUSH | 刷盘策略 |
namesrvAddr | 192.168.1.1:9876;192.168.1.2:9876 | name server地址,多个之间;分割 |
listenPort | ||
storePathRootDir | ~/store | 默认是/store,slave可以设置成/store-s |
storePathCommitLog | ~/store/commitlog | |
storePathConsumeQueue | ~/store/consumequeue | |
storePathIndex | ~/store/index | |
storeCheckPoint | ~/store/checkpoint | |
abortFile | ~/store/abort | |
defaultTopicQueueNums | 默认4 | 每个topic对应队列的数量,默认为4,实际应参考consumer实例的数量,值过小不利于consumer负载均衡 |
autoCreateTopicEnable | 是否允许 Broker 自动创建Topic,生产建议关闭 | |
autoCreateSubscriptionGroup | 是否允许 Broker 自动创建订阅组,生产建议关闭 |
启动master
2个master
nohup sh bin/mqbroker -c conf/2m-2s-async/broker-a.properties -n localhost:9876 &
tail -f ~/logs/rocketmqlogs/broker.log
nohup sh bin/mqbroker -c conf/2m-2s-async/broker-b.properties -n localhost:9876 &
tail -f ~/logs/rocketmqlogs/broker.log
启动slave
2个slave
nohup sh bin/mqbroker -c conf/2m-2s-async/broker-a-s.properties -n localhost:9876 &
tail -f ~/logs/rocketmqlogs/broker.log
nohup sh bin/mqbroker -c conf/2m-2s-async/broker-b-s.properties -n localhost:9876 &
tail -f ~/logs/rocketmqlogs/broker.log