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]
[[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]
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
9)
停止第一台主节点查看
[[email protected] ~]# systemctl stop mysqld
[[email protected] ~]# mmm_control show
开启第一台主节点,停掉第二台节点查看
[[email protected] ~]# systemctl start mysqld
[[email protected] ~]# systemctl stop mysqld
[[email protected] ~]# mmm_control show
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)