mmm_control usage

本文详细介绍了如何使用mmm_control工具进行数据库集群的基本控制操作,包括角色移动、在线设置、离线设置、状态检查和ping检查。通过示例展示了如何在不同节点间移动writer角色、恢复离线状态和设置在线状态等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How to use

This page shows a few very basic things you can do to control MMM.

mmm_control

Most of the control is available through mmm_control tool on monitor server. If you have few clusters in configuration, you should always use it together with cluster name you want to query (i.e. to check C1 status, use “mmm_control @C1 show”). Otherwise, if you have single pair in configuration, it can be used without cluster name. Arguments are as follows:

mmm_control <move_role|set_online|show|ping|set_offline> [..params..]

move_role

move_role - usually used to move writer role between cluster nodes. i.e. we have this cluster status:

# mmm_control @C1 show
Config file: mmm_mon_C1.conf
Daemon is running!
Servers status:
db1(192.168.0.10): master/ONLINE. Roles: reader(192.168.0.14;)
db2(192.168.0.13): master/ONLINE. Roles: reader(192.168.0.11;), writer(192.168.0.12;)

to move writer role to db1, you should issue:

# mmm_control @C1 move_role writer db1
Config file: mmm_mon_C1.conf
Daemon is running!
Command sent to monitoring host. Result: OK: Role 'writer' has been
moved from 'db2' to 'db1'. Now you can wait some time and check
new roles info!
 
# mmm_control @C1 show
Config file: mmm_mon_C1.conf
Daemon is running!
Servers status:
db1(192.168.0.10): master/ONLINE. Roles: reader(192.168.0.14;), writer(192.168.0.12;)
db2(192.168.0.13): master/ONLINE. Roles: reader(192.168.0.11;)

set_online

set_online - command is used to recover the node when from a failure when it's state is “AWAITING_RECOVERY” or “ADMIN_OFFLINE”. For instance, I restart db1 and after restart here's the cluster status:

# mmm_control @C1 show
Config file: mmm_mon_C1.conf
Daemon is running!
Servers status:
db1(192.168.0.10): master/AWAITING_RECOVERY. Roles: None
db2(192.168.0.13): master/ONLINE. Roles: reader(192.168.0.14;), reader(192.168.0.11;), writer(192.168.0.12;)

You see all roles are moved to db2 as db1 has failed. Now that it's recovered, we should set it online:

# mmm_control @C1 set_online db1
Config file: mmm_mon_C1.conf
Daemon is running!
Command sent to monitoring host. Result: OK: State of 'db1' changed
to ONLINE. Now you can wait some time and check its new roles!
 
# mmm_control @C1 show
Config file: mmm_mon_C1.conf
Daemon is running!
Servers status:
db1(192.168.0.10): master/ONLINE. Roles: reader(192.168.0.14;)
db2(192.168.0.13): master/ONLINE. Roles: reader(192.168.0.11;), writer(192.168.0.12;)

set_offline

set_offline - this is used to bring the node down manually for maintenance:

# mmm_control @C1 show
Config file: mmm_mon_C1.conf
Daemon is running!
Servers status:
db1(192.168.0.10): master/ONLINE. Roles: reader(192.168.0.14;), writer(192.168.0.12;)
db2(192.168.0.13): master/ONLINE. Roles: reader(192.168.0.11;)
 
 
# mmm_control @C1 set_offline db1
Config file: mmm_mon_C1.conf
Daemon is running!
Command sent to monitoring host. Result: OK: State of 'db1' changed
to ADMIN_OFFLINE. Now you can wait some time and check all roles!
 
# mmm_control @C1 show
Config file: mmm_mon_C1.conf
Daemon is running!
Servers status:
db1(192.168.0.10): master/ADMIN_OFFLINE. Roles: None
db2(192.168.0.13): master/ONLINE. Roles: reader(192.168.0.14;), reader(192.168.0.11;), writer(192.168.0.12;)

Again, writer and reader roles automatically move to db1. To get db1 up, we use set_online:

# mmm_control @C1 show
Config file: mmm_mon_C1.conf
Daemon is running!
Servers status:
db1(192.168.0.10): master/ONLINE. Roles: reader(192.168.0.14;)
db2(192.168.0.13): master/ONLINE. Roles: reader(192.168.0.11;), writer(192.168.0.12;)

show

show - as I noticed, command is used to get current cluster status. These are the most common node states:

  • master/ONLINE - this indicates that the node is running without any problems.
  • master/AWAITING_RECOVERY - it's common to see this state when MySQL is restarted and the node is not set on-line in cluster yet. If the node can't be set on-line, command “mmm_control @C1 set_online node” prints the explanation on what is the problem. If the problem is with replication, this is where you should check the problem manually in MySQL itself.
  • master/ADMIN_OFFLINE - indicates that node was set offline manually, but MySQL server is actually running.
  • master/HARD_OFFLINE - shows that MySQL server is unreachable. This could be a network failure or MySQL might actually be down.
  • master/REPLICATION_FAIL - indicates an obvious replication error. You should check the problem and fix it manually.
  • master/REPLICATION_DELAY - this happens when the node can't catch up with the master. It's common to see this if MySQL was down for a while but if this happens on a normal workload, probably there's some serious problem (slow network, weak hardware etc). When this happens,  MMM automatically moves reader role to the active master server so the node could catch up faster and the data from database would be actual.

ping

- ping - this is to simply check the monitor status. If monitor is on-line:

# mmm_control @C1 ping
Config file: mmm_mon_C1.conf
Daemon is running!

when the monitor is down:

# mmm_control @C1 ping
Config file: mmm_mon_C1.conf
 
WARNING!!! DAEMON IS NOT RUNNING. INFORMATION MAY NOT BE ACTUAL!!!
...

General guidelines

Now, few general guidelines:

- To make an lvm based clone from one master (or a slave from master/slave), mmm_clone command can be used:

db2:~# mmm_clone --host db1 --clone-mode master-master

Note, command must be executed in the destination server.

- If you are going to do some manual shutdown/restart operations on the cluster nodes, please make use of manual set offline/online commands. For example to upgrade mysql on both nodes w/o downtime (only few active mysql sessions will get killed):

  1. “mmm_control @C1 set_offline db2” (db1 will be the only working server at this point)
  2. upgrade mysql on db2, make sure mysql is started and replication_delay is going well on both nodes (“SHOW SLAVE STATUS\G” sql statement should show seconds_behind_master: 0)
  3. “mmm_control @C1 set_online db2” to bring db2 back in cluster and ensure that the cluster status is fine with “mmm_control @C1 show” command.
  4. move writer role manually to db2: “mmm_control @C1 move_role writer db2”
  5. now repeat set_offline, upgrade and set_online for db1
  6. again, ensure cluster is running fine.

If both nodes have equal hardware configuration and are equally well to serve as masters (which is what we would usually expect), you should be fine at this point, otherwise you may need to move writer role to db1 with command:

mmm_control @C1 move_role writer db1
<think>我们正在处理的是MySQLMMM(Master-MasterReplicationManager)中的`mmm_control`命令缓存问题。用户希望清除`mmm_control`的缓存记录,使其`show`命令恢复到初始状态。在MySQLMMM架构中:-`mmm_agent`运行在每个MySQL节点上,负责监控本地MySQL状态并执行操作。-`mmm_monitor`运行在监控节点上,通过收集所有agent的信息来管理整个集群。-`mmm_control`是一个客户端工具,用于向monitor发送命令并获取集群状态。`mmm_controlshow`命令显示的状态信息是由monitor节点维护的。这些状态信息可能会因为监控过程中收集的历史数据而发生变化(比如节点状态的变化历史)。但是,monitor节点本身并不会永久存储这些状态(通常存储在内存中),因此重启monitor服务会清除这些状态。然而,用户提到“缓存记录”,可能是指monitor在运行过程中积累的状态信息,或者是指`mmm_control`客户端本地可能存在的缓存?实际上,`mmm_control`命令本身并不在本地缓存数据,它每次执行都会连接到monitor节点获取实时状态。因此,我们主要关注monitor节点上的状态。清除monitor节点上的状态(即重置为初始状态)的方法:1.重启monitor服务:这会清除monitor内存中保存的所有状态,重新开始收集信息。2.如果monitor配置了持久化状态(默认情况下没有),则还需要删除持久化文件(但默认不持久化)。另外,用户可能希望重置所有状态计数器(比如节点标记为不可用的次数等),重启monitor也可以达到这个效果。具体步骤:-在monitor节点上重启`mysql-mmm-monitor`服务。-注意:重启monitor服务期间,集群将暂时失去监控(但不会影响数据库运行)。如果用户希望在不重启服务的情况下重置某些状态,mmm_monitor并没有提供直接的命令来清除缓存。但是,我们可以通过让monitor重新加载配置(reload)来刷新一些状态(但可能不会清除所有运行状态)。因此,推荐的方法是重启monitor服务。操作步骤:1.在monitor节点上执行:```bash#对于使用systemd的系统(如CentOS7+)sudosystemctlrestartmysql-mmm-monitor#对于使用init的系统(如CentOS6)sudoservicemysql-mmm-monitorrestart```2.重启后,等待monitor重新与所有agent建立连接并收集状态(可能需要几秒钟到一分钟)。3.然后使用`mmm_controlshow`查看,此时显示的状态应该是初始状态(即没有任何历史事件影响的状态)。注意:重启monitor服务不会改变集群中MySQL节点的实际状态(比如复制状态、读写设置等),它只会重置monitor内部的状态记录。如果重启monitor服务后问题仍然存在,那么可能是集群中确实存在问题,需要进一步检查。另外,如果用户希望清除agent节点上的状态,可以重启agent服务(但通常不需要,因为monitor的状态是独立的):```bashsudosystemctlrestartmysql-mmm-agent```但是,用户的问题是关于`mmm_controlshow`的,所以重点在monitor。最后,确保在操作过程中不影响生产环境,最好在维护窗口进行。相关问题:1.如何重启mysql-mmm-monitor服务?2.重启monitor服务对MySQL集群有什么影响?3.如何检查mysql-mmm-monitor是否正常运行?</think>要清除 `mmm_control` 的缓存记录并使其 `show` 命令恢复到初始状态,请按以下步骤操作。MySQL MMM 的缓存状态主要存储在 monitor 节点上,清除缓存需要通过重置 monitor 服务实现: ### 清除缓存步骤 1. **停止 MMM Monitor 服务** 在 monitor 节点上执行: ```bash # systemd 系统 sudo systemctl stop mysql-mmm-monitor # init 系统 sudo service mysql-mmm-monitor stop ``` 2. **删除状态缓存文件** 删除 monitor 的运行时状态文件(默认位置): ```bash sudo rm -f /var/lib/mysql-mmm/mmm_mond.state sudo rm -f /var/lib/mysql-mmm/mmm_mond.status ``` > 这些文件存储集群的实时状态缓存[^1] 3. **清理日志文件(可选但推荐)** 重置日志避免旧状态干扰: ```bash sudo truncate -s 0 /var/log/mysql-mmm/monitor.log ``` 4. **重启 Monitor 服务** 重新启动服务加载初始状态: ```bash sudo systemctl start mysql-mmm-monitor # systemd sudo service mysql-mmm-monitor start # init ``` 5. **验证初始状态** 等待 30 秒后检查状态: ```bash mmm_control show ``` 预期输出:所有节点状态应为 `ONLINE`,角色显示为初始配置(无 `HARD_OFFLINE` 等异常状态) ### 关键注意事项 1. **执行节点**:所有操作必须在 **MMM Monitor 节点** 执行(非 agent 节点) 2. **权限要求**:需 root 权限或 `sudo` 3. **影响范围**: - 清除缓存期间集群监控短暂中断(约 10-30 秒) - **不会影响** MySQL 数据库运行和复制 4. 若状态未重置,检查配置文件: ```bash mmm_control --check-config # 验证配置一致性[^1] ``` ### 持久化配置建议 为防止状态漂移,在 `mmm_common.conf` 中添加: ```perl active_master_role writer ``` 该设置强制指定主节点角色[^2]。 --- **故障恢复流程图** ```mermaid graph TD A[mmm_control show 状态异常] --> B{停止 monitor 服务} B --> C[删除状态文件] C --> D[清理日志] D --> E[重启 monitor] E --> F[验证初始状态] F -->|成功| G[完成] F -->|失败| H[检查配置和日志] H --> I[修复配置错误] I --> E ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值