mysql MMM高可用

一、 安装mysql mmm
1)
安装yum源和epel源

[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[[email protected] ~]# yum -y install epel-release

[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[[email protected] ~]# yum -y install epel-release

[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[[email protected] ~]# yum -y install epel-release

[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[[email protected] ~]# yum -y install epel-release

[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[[email protected] ~]# yum -y install epel-release
2)
安装mysql mmm

[[email protected] ~]# yum -y install mysql-mmm*
[[email protected] ~]# yum -y install mysql-mmm*
[[email protected] ~]# yum -y install mysql-mmm*
[[email protected] ~]# yum -y install mysql-mmm*
[[email protected] ~]# yum -y install mysql-mmm*
3)
修改host文件

[[email protected] ~]# vim /etc/hosts
192.168.100.10 db1
192.168.100.20 db2
192.168.100.30 db3
192.168.100.40 db4
192.168.100.50 db5
[[email protected]1 ~]# scp /etc/hosts [email protected]:/etc/
[[email protected] ~]# scp /etc/hosts [email protected]:/etc/
[[email protected] ~]# scp /etc/hosts [email protected]:/etc/
[[email protected] ~]# scp /etc/hosts [email protected]:/etc/
4)
配置mysql主服务器节点配置文件

[[email protected] ~]# vim /etc/my.cnf
log-bin=mysql-bin
log-slave-updates=true
server-id=10
relay-log=relay-log-bin
relay-log-index=relay-log-bin.index

[[email protected] ~]# vim /etc/my.cnf
log-bin=mysql-bin
log-slave-updates=true
server-id=20
relay-log=relay-log-bin
relay-log-index=relay-log-bin.index
5)
配置mysql从服务器节点配置文件

[[email protected] ~]# vim /etc/my.cnf
log-bin=mysql-bin
server-id=30
relay-log=relay-log-bin
relay-log-index=relay-log-bin.index

[[email protected] ~]# vim /etc/my.cnf
log-bin=mysql-bin
server-id=40
relay-log=relay-log-bin
relay-log-index=relay-log-bin.index
二、 配置mysql mmm
1、 配置mysql mmm配置文件
1)
修改mysql mmm主配置文件

[[email protected] ~]# vim /etc/mysql-mmm/mmm_common.conf

cluster_interface ens32
pid_path /run/mysql-mmm-agent.pid
bin_path /usr/libexec/mysql-mmm/
replication_user slave
replication_password [email protected]
agent_user mmm_agent
agent_password [email protected]

ip 192.168.100.10 mode master peer db2 ip 192.168.100.20 mode master peer db1 ip 192.168.100.30 mode slave ip 192.168.100.40 mode slave hosts db1, db2 ips 192.168.100.100 mode exclusive hosts db3, db4 ips 192.168.100.101, 192.168.100.102 mode balanced ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200514100248388.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTQ0ODE2Mg==,size_16,color_FFFFFF,t_70) ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200514100255827.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTQ0ODE2Mg==,size_16,color_FFFFFF,t_70) [[email protected]~]# scp /etc/mysql-mmm/mmm_common.conf 192.168.100.20:/etc/mysql-mmm/ [[email protected]~]# scp /etc/mysql-mmm/mmm_common.conf 192.168.100.30:/etc/mysql-mmm/ [[email protected]~]# scp /etc/mysql-mmm/mmm_common.conf 192.168.100.40:/etc/mysql-mmm/ [[email protected]~]# scp /etc/mysql-mmm/mmm_common.conf 192.168.100.50:/etc/mysql-mmm/ **2) 在所有安装mysql服务器系欸电脑配置客户端代理** [[email protected] ~]# vim /etc/mysql-mmm/mmm_agent.conf this db1

[[email protected] ~]# vim /etc/mysql-mmm/mmm_agent.conf
this db2

[[email protected] ~]# vim /etc/mysql-mmm/mmm_agent.conf
this db3

[[email protected] ~]# vim /etc/mysql-mmm/mmm_agent.conf
this db4
3)
设置开机自动启动

[[email protected] ~]# systemctl start mysql-mmm-agent
[[email protected] ~]# systemctl enable mysql-mmm-agent

[[email protected] ~]# systemctl start mysql-mmm-agent
[[email protected] ~]# systemctl enable mysql-mmm-agent

[[email protected] ~]# systemctl start mysql-mmm-agent
[[email protected] ~]# systemctl enable mysql-mmm-agent

[[email protected] ~]# systemctl start mysql-mmm-agent
[[email protected] ~]# systemctl enable mysql-mmm-agent
4)
mysql中授权监控端管理mysql节点

[[email protected] ~]# mysql -uroot [email protected]
mysql> grant all on . to ‘mmm_agent’@‘192.168.100.%’ identified by ‘[email protected]’;
Query OK, 0 rows affected (0.00 sec)

[[email protected] ~]# mysql -uroot [email protected]
mysql> grant all on . to ‘mmm_agent’@‘192.168.100.%’ identified by ‘[email protected]’;
Query OK, 0 rows affected (0.00 sec)

[[email protected] ~]# mysql -uroot [email protected]
mysql> grant all on . to ‘mmm_agent’@‘192.168.100.%’ identified by ‘[email protected]’;
Query OK, 0 rows affected (0.00 sec)

[[email protected] ~]# mysql -uroot [email protected]
mysql> grant all on . to ‘mmm_agent’@‘192.168.100.%’ identified by ‘[email protected]’;
Query OK, 0 rows affected (0.00 sec)
5)
配置服务器监控端

[[email protected] ~]# vim /etc/mysql-mmm/mmm_mon.conf
8 ping_ips 192.168.100.10,192.168.100.20,192.168.100.30,192.168.100.40
9 auto_set_online 5
20 monitor_user mmm_monitor
21 monitor_password [email protected]
mysql MMM高可用
6)
授权监控mysql连接监控端账户密码

[[email protected] ~]# mysql -uroot [email protected]
mysql> grant all on . to ‘mmm_monitor’@‘192.168.100.%’ identified by ‘[email protected]’;
Query OK, 0 rows affected (0.00 sec)

[[email protected] ~]# mysql -uroot [email protected]
mysql> grant all on . to ‘mmm_monitor’@‘192.168.100.%’ identified by ‘[email protected]’;
Query OK, 0 rows affected (0.00 sec)

[[email protected] ~]# mysql -uroot [email protected]
mysql> grant all on . to ‘mmm_monitor’@‘192.168.100.%’ identified by ‘[email protected]’;
Query OK, 0 rows affected (0.00 sec)

[[email protected] ~]# mysql -uroot [email protected]
mysql> grant all on . to ‘mmm_monitor’@‘192.168.100.%’ identified by ‘[email protected]’;
Query OK, 0 rows affected (0.00 sec)
7)
启动监控端服务器

[[email protected] ~]# systemctl start mysql-mmm-monitor
[[email protected] ~]# systemctl enable mysql-mmm-monitor
8)
查看mysql状态

[[email protected] ~]# mmm_control show
mysql MMM高可用
9)
停止第一台主节点查看

[[email protected] ~]# systemctl stop mysqld
[[email protected] ~]# mmm_control show
mysql MMM高可用
mysql MMM高可用
开启第一台主节点,停掉第二台节点查看
[[email protected] ~]# systemctl start mysqld
[[email protected] ~]# systemctl stop mysqld
[[email protected] ~]# mmm_control show
mysql MMM高可用
10)
授权用户访问mysql账户和密码

[[email protected] ~]# mysql -uroot [email protected]
mysql> grant all on . to ‘bob’@‘192.168.100.%’ identified by ‘[email protected]’;
Query OK, 0 rows affected (0.00 sec)
三、 客户端访问
1)
安装mysql客户端

[[email protected] ~]# rm -rf /etc/yum.repos.d/CentOS-*
[[email protected] ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[[email protected] ~]# yum -y install mysql
2)
登陆

[[email protected] ~]# mysql -ubob -p -h 192.168.100.10 -P 3306
Enter password:
3)
Mysql客户端创建数据库测试

MySQL [(none)]> create database cheng;
Query OK, 1 row affected (0.00 sec)
mysql MMM高可用
mysql MMM高可用

相关文章: