千家信息网

Mysql-mmm集群部署

发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,90主 <----------> 91主|||------------------------------| || || |92从 93从systemctl stop firewalld.servic
千家信息网最后更新 2025年11月07日Mysql-mmm集群部署

90主 <----------> 91主

|

|

|

------------------------------

| |

| |

| |

92从 93从


systemctl stop firewalld.service ;systemctl disable firewalld.service ;setenforce 0



MySQL-mmm

一、配置主从同步结构

1)配置主从同步

90: 用户配置 启用 binlog 日志 重启数据库服务 指定主数据库服务器信息

91: 用户配置 启用 binlog 日志 允许级联复制 重启数据库服务 指定主数据库服务器信息

[root@pc91 ~]# vim /etc/my.cnf

[mysqld]

validate_password_policy=0

validate_password_length=6

server_id=91

log-bin=master91

binlog_format="mixed"

log_slave_updates


-> grant replication slave on *.* to slaveuser@"%" identified by '123456';


-> change master to

-> master_host="主服务器 ip 地址",

-> master_user="授权用户名",

-> master_password="授权用户密码",

-> master_log_file="主服务器正在使用的 binlog 日志",

-> master_log_pos=主服务当前的偏移量;

#指定主服务器


2)配置一主多从结构

92: 指定server_id 重启数据库服务 指定主数据库服务器信息

93: 指定server_id 重启数据库服务 指定主数据库服务器信息


[root@pc92 ~]# vim /etc/my.cnf

[mysqld]

validate_password_policy=0

validate_password_length=6

server_id=92


-> change master to

-> master_host="主服务器 ip 地址",

-> master_user="授权用户名",

-> master_password="授权用户密码",

-> master_log_file="主服务器正在使用的 binlog 日志",

-> master_log_pos=主服务当前的偏移量;

#指定主服务器


mysql> show master status\G;


mysql> start slave;


mysql> show slave status\G;


3)在客户端测试主从同步配置

a、

在90主机上添加访问数据的用户guser,能够在其他3台主机上也有相同的授权用户

-> grant select on gamedb.* to guser@'%' identified by '123456';


b、

在客户端主机94 使用授权用户guser 连接14服务器,产生的新数据在他3台主机上也有

-> select user,host from mysql.user where user="guser";


二、配置mysql-mmm

1)mysql-mmm 介绍

监控服务: 运行在管理节点 用来监控数据节点

代理服务: 运行在数据节点 用来提供系统给监控主机


2)在所有主机上安装mysql-mmm软件(90-94)

#yum -y install perl-*

#unzip mysql-mmm.zip

#cd mysql-mmm

#make install

#ls /etc/mysql-mmm/*.conf


3)修改配置文件

a 修改数据节点代理服务配置文件 (90 91 92 93)

vim /etc/mysql-mmm/mmm_agent.conf

include mmm_command.conf

this 自定义名称


b 修改管理节点监控服务的配置文件 (94)

vim /etc/mysql-mmm/mmm_mon.conf

>

include mmm_common.conf


ip 192.168.4.94 //本机IP

pid_path /var/run/mmm_mond.pid

bin_path /usr/lib/mysql-mmm/

status_path /var/lib/misc/mmm_mond.status

ping_ips 192.168.4.90, 192.168.4.91, 192.168.4.92, 192.168.4.93 //监控的服务器IP


monitor_user monitor //监控状态时使用的用户名

monitor_password 123456 //监控状态时使用的用户密码

>


c 修改公共文件

vim /etc/mysql-mmm/mmm_command.conf

>

active_master_role writer



cluster_interface eth0


pid_path /var/run/mmm_agentd.pid

bin_path /usr/lib/mysql-mmm/


replication_user slaveuser //设置主从同步的用户

replication_password 123456 //设置主从同步用户密码


agent_user agent //控制数据库用户

agent_password 123456 //控制数据库用户密码


//设置第一个主服务器

ip 192.168.4.90

mode master

peer db91 //指定另外一台主服务器


//设置第二台主服务器

ip 192.168.4.91

mode master

peer db90


//设置从服务器

ip 192.168.4.92

mode slave


//设置从服务器

ip 192.168.4.93

mode slave



//指定主服务器VIP地址

hosts db90, db91

ips 192.168.4.100

mode exclusive


//指定从服务器VIP地址

hosts db92, db93

ips 192.168.4.101, 192.168.0.102

mode balanced

>


d 根据配置文件的设置,在数据节点主机上添加对应授权用户

-> grant replication client on *.* to monitor@'%' identified by '123456';

-> grant replication client,process,super on *.* to agent@'%' identified by '123456';

-> select user,host from mysql.user where user in ("monitor","agent");


4)启动服务

a 启动数据节点主机上代理服务: mmm_agent

安装服务运行依赖的软件包 安装获取vip地址软件包arp_net 启动服务

[root@pc90 ~]# /etc/init.d/mysql-mmm-agent start

[root@pc90 ~]# netstat -pantu | grep 9989


b 启动管理节点主机上监控服务:mmm_mond

安装服务运行依赖的软件包 启动服务

[root@pc94 ~]# /etc/init.d/mysql-mmm-monitor start

[root@pc94 ~]# netstat -pantu | grep 9988


三、验证mysql-mmm配置

a 查看数据库节点上的数据库服务是运行的

[root@pc94 ~]# systemctl status mysqld


b IO线程 和 SQL 线程都是Yes状态

mysql> show slave status\G;


c 在监控服务器本机登录管理界面查看,查看数据库服务器的状态

[root@pc94 ~]# mmm_control show

defined(@array) is deprecated at /usr/share/perl5/vendor_perl/Log/Log4perl/Config.pm line 863.

(Maybe you should just omit the defined()?)

db90(192.168.4.90) master/AWAITING_RECOVERY. Roles:

db91(192.168.4.91) master/AWAITING_RECOVERY. Roles:

db92(192.168.4.92) slave/AWAITING_RECOVERY. Roles:

db93(192.168.4.93) slave/AWAITING_RECOVERY. Roles:


[root@pc94 ~]# mmm_control set_online db90

[root@pc94 ~]# mmm_control show

defined(@array) is deprecated at /usr/share/perl5/vendor_perl/Log/Log4perl/Config.pm line 863.

(Maybe you should just omit the defined()?)

db90(192.168.4.90) master/ONLINE. Roles: writer(192.168.4.100)

db91(192.168.4.91) master/ONLINE. Roles:

db92(192.168.4.92) slave/ONLINE. Roles: reader(192.168.0.102)

db93(192.168.4.93) slave/ONLINE. Roles: reader(192.168.4.101)


[root@pc94 ~]# mmm_control show

defined(@array) is deprecated at /usr/share/perl5/vendor_perl/Log/Log4perl/Config.pm line 863.

(Maybe you should just omit the defined()?)

db90(192.168.4.90) master/ONLINE. Roles: writer(192.168.4.100)

db91(192.168.4.91) master/HARD_OFFLINE. Roles:

db92(192.168.4.92) slave/ONLINE. Roles: reader(192.168.0.102)

db93(192.168.4.93) slave/ONLINE. Roles: reader(192.168.4.101)


0