hello云胜

技术与生活

0%

消息中间件运维总结

分领域部署

不应该搭建太大的集群。因为一旦集群出故障,影响范围会很大

核心业务要按业务域进行规划

集群扩容

新扩容进原集群的broker是不会有流量进来的,因为没有创建任何Topic

为了快速让新broker上拥有集群内其他节点中的topic,我们通常可以拷贝集群内其他节点的主题定义文件,具体要复制的文件路径为:{ROCKETMQ_HOME}/store/config/topics.json 文件

如果 Broker 关闭了自动创建消费组(autoCreateSubscriptionGroup=false)(生产一般都关掉了),还需要拷贝 subscriptionGroup.json 文件。

再次重启新加入的broker,就可以承担读写流量,实现负载均衡了

集群缩容

将节点从集群中移除的基本原则是,存储在这些节点上的消息必须完成消费,否则会造成消息消费丢失。

关闭节点的写权限。避免新的数据再写入该节点,然后等消息过期再下线。

具体命令如下:

1
sh ./mqadmin updateBrokerConfig -b 127.0.0.1:10911 -n 127.0.0.1:9876 -k brokerPermission -v 4

为了保守起见,通常要等待消息过期后,再关闭 Broker。如果消息的存储时间为 72 小时,那要在关闭写权限 3 天之后才可以下线该节点。在此期间,该节点还是可以提供读取服务,也就是说,存在这个节点的消息仍然可以被消费端消费。

topic扩容

topic扩容就是扩队列数

1
sh ./mqadmin updateTopic -n 127.0.0.1:9876 -c DefaultCluster -t dw_test_01 -r 8 -w 8

-w 、-r 分别指定扩容后的队列数。其中 -w 表示写队列个数,-r 表示读队列个数,在进行Topic扩容时,它们必须一致。

topic缩容

分两步,先缩写队列

1
sh ./mqadmin updateTopic -n 127.0.0.1:9876 -c DefaultCluster -t dw_test_01 -r 8 -w 4

等消息达到过期时间后,再将读队列数量变更为缩容后的队列

1
sh ./mqadmin updateTopic -n 127.0.0.1:9876 -c DefaultCluster -t dw_test_01 -r 4 -w 4

重置位点

1
sh ./mqadmin resetOffsetByTime -g dw_test_mq_consuemr_test_01 -n 127.0.0.1:9876 -t dw_zms_test_topic -s '2022-07-10#10:00:00:000'

-s 参数,它表示回溯时间。其中:

now 或者 currentTimeMillis 表示当前时间;

yyyy-MM-dd#HH:mm:ss:SSS 表示具体的时间戳。在执行命令时,需要严格按照格式,否则会抛出空指针异常

nameserver扩容

更新两台 Broker 的配置文件,让 Broker 能够感知新 NameServer 的存在,具体的配置项:

1
namesrvAddr=192.168.3.100:9876;192.168.3.101:9876;192.168.3.107:9876

紧接着,依次重启 Broker。

一定要注意的是,**集群内的 Broker 没有全部重启时,新加入集群的 NameServer 地址是不能让消息发送 / 消息消费客户端使用的。**因为这时候新的 NameServer 上的路由信息会和集群内其他 NamServer 存储的信息不一致。

NameServer 的下线就比较简单了。直接先 kill 掉 NameServer 进程,这时,无论是 Broker、还是消息发送、消息消费客户端都会抛出错误,但这个错误不影响使用。

然后依次更新 Broker 配置文件中的 namesrvAddr,移除已下线的 NameServer 地址并依次重启。

在生产实践中,NameServer 的扩容还是比较少见的,更多的是更换机器。举个例子,192.168.3.100 这台机器由于内存、磁盘等故障,需要被下线。但为了保证 NameServer 节点数量不受影响,我们通常还会在一台新机器上部署一台新的 NameServer。同时,为了避免客户端或 Broker 需要更新 NameServer 列表,更换机器时还要 IP 保持不变。

运维命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
sh ./mqadmin
# 该命令的输出结果如下:
The most commonly used mqadmin commands are:
updateTopic Update or create topic
deleteTopic Delete topic from broker and NameServer.
updateSubGroup Update or create subscription group
deleteSubGroup Delete subscription group from broker.
updateBrokerConfig Update broker's config
updateTopicPerm Update topic perm
topicRoute Examine topic route info
topicStatus Examine topic Status info
topicClusterList get cluster info for topic
brokerStatus Fetch broker runtime status data
queryMsgById Query Message by Id
queryMsgByKey Query Message by Key
queryMsgByUniqueKey Query Message by Unique key
queryMsgByOffset Query Message by offset
QueryMsgTraceById query a message trace
printMsg Print Message Detail
printMsgByQueue Print Message Detail
sendMsgStatus send msg to broker.
brokerConsumeStats Fetch broker consume stats data
producerConnection Query producer's socket connection and client version
consumerConnection Query consumer's socket connection, client version and subscription
producerConnectionAll Query all producer's socket connection and client version
consumerProgress Query consumers's progress, speed
consumerStatus Query consumer's internal data structure
cloneGroupOffset clone offset from other group.
clusterList List all of clusters
topicList Fetch all topic list from name server
updateKvConfig Create or update KV config.
deleteKvConfig Delete KV config.
wipeWritePerm Wipe write perm of broker in all name server
resetOffsetByTime Reset consumer offset by timestamp(without client restart).
updateOrderConf Create or update or delete order conf
cleanExpiredCQ Clean expired ConsumeQueue on broker.
cleanUnusedTopic Clean unused topic on broker.
startMonitoring Start Monitoring
statsAll Topic and Consumer tps stats
allocateMQ Allocate MQ
checkMsgSendRT check message send response time
clusterRT List All clusters Message Send RT
getNamesrvConfig Get configs of name server.
updateNamesrvConfig Update configs of name server.
getBrokerConfig Get broker config by cluster or special broker!
queryCq Query cq command.
sendMessage Send a message
consumeMessage Consume message
updateAclConfig Update acl config yaml file in broker
deleteAccessConfig Delete Acl Config Account in broker
clusterAclConfigVersion List all of acl config version information in cluster
updateGlobalWhiteAddr Update global white address for acl Config File in broker
getAccessConfigSubCommand List all of acl config information in cluster

查看每一个命令的具体使用方法,可以使用如下命令:

1
sh ./mqadmin updateTopic -h