mysql主主复制+主从复制+读写分离+mmm高可用群集

mysql主主复制+主从复制+读写分离+mmm高可用群集配置

CentOS 6.5安装mysql5.7.18 #这里只展示一台的安装过程,另几台一样操作

实验环境:
Mysql主1:172.16.16.80
Mysql主2:172.16.16.100
Mysql副1:172.16.16.60
Mysql副2:172.16.16.70
读写分离及mmm代理服务器:172.16.16.90

下载地址:
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

1、下载,解压,并创建软链接

[root@kgc1 ~]# 
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
[root@kgc1 ~]# tar xf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/src //解压到usr/src文件下
[root@kgc1 ~]#cd /usr/src
[root@kgc1 ~]#mv mysql-5.7.18-linux-glibc2.5-x86_64/ mysql  改名为mysql

2、新建mysql用户组和mysql用户

[root@kgc1 src]# groupadd mysql 创建mysql用户组
[root@kgc1 src]# useradd -M -s /sbin/nologin mysql -g mysql  //把mysql用户添加到mysql用户组中

3、新建数据目录并赋予相关属组及权限

[root@kgc1 src]# chown -R mysql:mysql /usr/src/mysql
[root@kgc1 src]# mkdir -p /data/mysql
[root@kgc1 src]# chmod -R 770 /data/mysql
[root@kgc1 src]# chown -R mysql:mysql /data/mysql

4、初始化mysqld

[root@kgc1 mysql]# ./bin/mysqld --user=mysql --basedir=/usr/src/mysql --datadir=/data/mysql --initialize

5、编辑配置文件及将mysql的服务脚本放到系统服务中,并配置环境变量让系统可以直接使用mysql的相关命令

[root@kgc1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
cp:是否覆盖"/etc/init.d/mysqld"? yes
[root@kgc1 mysql]# ldconfig
[root@kgc1 mysql]# echo "PATH=$PATH:/usr/src/mysql/bin" > /etc/profile.d/mysql.sh
[root@kgc1 mysql]#  source /etc/profile.d/mysql.sh
[root@kgc1 mysql]# chkconfig mysqld on
修改配置文件/etc/my.conf

basedir=/usr/src/mysql #mysql路径
datadir=/data/mysql #mysql数据目录
socket=/data/mysql/mysql.sock套接字位置
user=mysql  //用户
server_id=1 #MySQLid 后面2个从服务器需设置不同
port=3306端口号
添加
skip-grant-tables选项  登录数据跳过密码验证

启动数据库
[root@kgc1 mysql]# systemctl start mysqld
登录数据库:
root@kgc1 mysql]# mysql -uroot -p
修改当前用户密码:
update mysql.user set authentication_string=password('123456') where user='root';
使用密码登录:
[root@kgc1 mysql]# mysql -uroot -p123456
修改数据库密码:
set password=password('1234567');
添加授权访问用户:(主12 ,从12都需要添加这个用户)
mysql> grant all on *.*  to zhongjiao@'172.16.16.%' identified by'123456';
mysql> flush privileges; //刷新
mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user; //查看用户表
mysql> show grants for 'zhongjiao'@'172.16.16.%'; //查看该用户的权限

二、配置mysql主主复制环境,配置主1主2mysql配置文件:

注意:如果不是两个yes可以考虑删除/data/mysql/文件下的auto.cnf文件和master.info然后登陆数据库关闭slave服务重新同步记得同步完之后刷新服务flush privileges;再开启slave服务
1)添加:
Vim /etc/my.conf
server-id =10  /两台主机的id号不能一样
Log_bin=mysql-bin //开启二进制文件
log-slave-updates=true //开始宕机自动切换
auto_increment_increment=2
auto_increment_offset=1
2)登录数据库mysql主1 mysql主2相互提升访问权限:
Mysql主1:
mysql> grant replication slave on *.* to 'zj'@'172.16.16.100' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;   //立即刷新
Query OK, 0 rows affected (0.01 sec)
Mysql主2:
mysql> grant replication slave on *.* to 'zj'@'172.16.16.80' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

3)Mysql1:查看master状态:
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000006 |     1752 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

4)mysql主2开启同步:
mysql> change master to master_host='172.16.16.80',master_user='zj',master_password='123456',master_log_file='mysql-binn.000006',master_log_pos=1752; //配置同步二进制文件
\Query OK, 0 rows affected, 2 warnings (0.11 sec)

mysql> start slave; //开启slave功能
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G;  //查看同步状态
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.16.80
                  Master_User: zj
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000006
          Read_Master_Log_Pos: 1752
               Relay_Log_File: kgc1-relay-bin.000002
                Relay_Log_Pos: 320
        Relay_Master_Log_File: mysql-bin.000006
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1752
              Relay_Log_Space: 526
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 10
                  Master_UUID: 095e8560-bf3a-11ea-b3e0-00505633c80b
             Master_Info_File: /data/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)
//两个yes表示已经同步成功

5)查看msql主2master状态开启mysql主1同步:
查看mysql主2master状态:
mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000003 |   763514 |              |                  |                   |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

同步mysql主1配置:并开始slave服务:
mysql> change master to master_host='172.16.16.100',master_user='zj',master_password='123456',master_log_file='master-sbin.000003',master_log_pos=763514;
Query OK, 0 rows affected, 2 warnings (0.09 sec)

mysql> start slave; //开启slave服务
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.16.100
                  Master_User: zj
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000003
          Read_Master_Log_Pos: 763514
               Relay_Log_File: kgc1-relay-bin.000002
                Relay_Log_Pos: 321
        Relay_Master_Log_File: master-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 763514
              Relay_Log_Space: 527
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 15
                  Master_UUID: 36a57e33-bf38-11ea-8d78-005056352f54
             Master_Info_File: /data/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

ERROR: 
No query specified

出现两个yes表示同步成功:
验证:
在mysql主1上创建一个db数据库在是否在mysql主2上能否查看到:
Mysql主1:
mysql> create database db;
Query OK, 1 row affected (0.00 sec)

Mysql主2:
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db                 |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)
//主主配置成功:

三、配置主从myslq同步:

1)配置从12mysql配置文件:
添加一下内容:
server-id =30 //两个主服务器不能相同同时也不能与主服务器相同:
relay-log=relay-log-bin
relay-log-index=slave-erlay-bin.index
2)重启mysql服务(从1与从而都需要重启):
[root@kgc1 mysql]# systemctl stop mysqld
[root@kgc1 mysql]# systemctl start mysqld
3)登录mysql数据库配置同步(从1与从2都需要配置):
change master to master_host='172.16.16.100',master_user='zhongjiao'//刚刚的四台mysql数据库访问授权用户,master_password='123456',master_log_file='masmaster-bin.000004'//注意这里是主1或者主2的show master status下的文件名,master_log_pos=154;

4)开启slave功能并查看slave状态:
Mysql从1:
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.16.100
                  Master_User: zhongjiao
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000004
          Read_Master_Log_Pos: 154
               Relay_Log_File: relay-log-bin.000002
                Relay_Log_Pos: 321
        Relay_Master_Log_File: master-bin.000004
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 154
              Relay_Log_Space: 526
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 15
                  Master_UUID: 36a57e33-bf38-11ea-8d78-005056352f54
             Master_Info_File: /data/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

Mysql从2:
mysql> change master to master_host='172.16.16.100',master_user='zhongjiao',master_password='123456',master_log_file='master-bin.000004',master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.16.100
                  Master_User: zhongjiao
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000004
          Read_Master_Log_Pos: 154
               Relay_Log_File: relay-log-bin.000002
                Relay_Log_Pos: 321
        Relay_Master_Log_File: master-bin.000004
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 154
              Relay_Log_Space: 526
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 15
                  Master_UUID: 36a57e33-bf38-11ea-8d78-005056352f54
             Master_Info_File: /data/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)
Smyql从1与从2都为yes表示已经配置完成:
5)验证:从主1mysql中创建一个abc1库在从1上查看:
Mysql主1:
mysql> create database abc1;
Query OK, 1 row affected (0.15 sec)
Mysql从1:
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| abc1               |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.03 sec)

配置完成

四、配置读写分离:

1)下载:atlas
wget https://github.com/Qihoo360/Atlas/releases/download/2.2.1/Atlas-2.2.1.el6.x86_64.rpm
2)安装
rpm -ivh Atlas-2.2.1.el6.x86_64.rpm
安装完成后会自动在/usr/local/mysql-proxy下生成四个文件:
[root@kgc1 ~]# cd /usr/local/mysql-proxy/
[root@kgc1 mysql-proxy]# ls
bin  conf  lib  log
bin目录下放的都是可执行文件
1. “encrypt”是用来生成MySQL密码加密的,在配置的时候会用到
2. “mysql-proxy”是MySQL自己的读写分离代理
3. “mysql-proxyd”是360弄出来的,后面有个“d”,服务的启动、重启、停止。都是用他来执行的
conf目录下放的是配置文件
1. “test.cnf”只有一个文件,用来配置代理的,可以使用vim来编辑
lib目录下放的是一些包,以及Atlas的依赖
log目录下放的是日志,如报错等错误信息的记录

3(必备,根据实际情况配置)用户名与其对应的加密过的MySQL密码,密码使用安装路径 /bin目录下的加密程序encrypt加密,用户名与密码之间用冒号分隔。主从数据库上需要先创建该用户并设置密码(用户名和密码在主从数据库上要一致)。
  加密密码:
[root@kgc1 mysql-proxy]# cd bin/
[root@kgc1 bin]# ./encrypt 123456 //这里是只mysql授权atlas远程登录用户的密码:
/iZxz+0GRoA=

4)配置atlsa文件/usr/local/mysql-proxy/conf文件下的test.conf
[root@kgc1 conf]# vim test.cnf 

[mysql-proxy]

#管理接口的用户名
admin-username = user

#管理接口的密码
admin-password = pwd

#Atlas后端连接的MySQL主库的IP和端口,可设置多项,用逗号分隔
proxy-backend-addresses =172.16.16.80:3306, 172.16.16.100:3306 //主mysql主1和主2的IP地址及端口

#Atlas后端连接的MySQL从库的IP和端口,@后面的数字代表权重,用来作负载均衡,若省略则默认为1,可设置多项,用逗号分隔
proxy-read-only-backend-addresses = 172.16.16.60:3306@1,172.16.16.70:3306@1 //mysql从服务从1和从2的IP地址和端口:

#用户名与其对应的加密过的MySQL密码,密码使用PREFIX/bin目录下的加密程序encrypt加密,下行的user1和user2为示例,将其替换>为你的MySQL的用户名和加密密码!
pwds = zhongjiao:/iZxz+0GRoA=

#设置Atlas的运行方式,设为true时为守护进程方式,设为false时为前台方式,一般开发调试时设为false,线上运行时设为true,true后面不能有空格。
daemon = true

5)配置完成进入到bin下目录开启Atlas服务
[root@kgc1 bin]# ./mysql-proxyd test start
OK: MySQL-Proxy of test is started

6)

然后用代理服务器登入数据库
mysql -h127.0.0.1 -P2345 -uuser -ppwd      //-P2345是管理接口(配置文件里指明了的)端

MySQL [(none)]> SELECT * FROM backends  ;//查看后端服务
+-------------+--------------------+-------+------+
| backend_ndx | address            | state | type |
+-------------+--------------------+-------+------+
|           1 | 172.16.16.80:3306  | up    | rw   |
|           2 | 172.16.16.100:3306 | up    | rw   |
|           3 | 172.16.16.60:3306  | up    | ro   |
|           4 | 172.16.16.70:3306  | up    | ro   |
+-------------+--------------------+-------+------+
4 rows in set (0.00 sec)

7)mysql -h172.16.16.90 -P1234 -uzhongjiao -p123456     //-P1234是操作界面(被代理服务器授权的用户)端口不一样,登入的用户不一样。
使用操作界面登入进来你会发现和原来的数据库不一样
查看mysql库:
MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| abc1               |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.01 sec)

8)执行sql进行测试,可以通过日志看到写操作都在Master,读操作都连接到Slave了
[root@kgc1 bin]# more /usr/local/mysql-proxy/log/test.log
2020-07-02 10:37:15: (message) chassis-unix-daemon.c:138: [angel] we try to keep PID=2663 alive
2020-07-02 10:37:15: (message) mysql-proxy 0.8.2 started - instance: test
2020-07-02 10:37:15: (message) proxy listening on port 0.0.0.0:1234
2020-07-02 10:37:15: (message) added read/write backend: 172.16.16.80:3306
2020-07-02 10:37:15: (message) added read-only backend: 172.16.16.60:3306
2020-07-02 10:37:15: (message) added read-only backend: 172.16.16.70:3306
配置完成:

五、配置mysql高可用群集MMM

1)安装MMM
需要使用epel源可用直接去阿里源下载: 注意所有的服务器节点都需要下载:
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
在MMM代理服务器上下载:
[root@kgc1 bin]# yum install  -y mysql-mmm*
 
2)在mysql主1212中授权monitor访问:
mysql> grant replication client on *.* to 'mmm_monitor'@'172.16.16.%' identified by'monitor';
Query OK, 0 rows affected, 1 warning (0.09 sec)

mysql> grant super,replication client,process on *.* to 'mmm_agent'@'172.16.16.%' identified by'agent';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;  //立即刷新
Query OK, 0 rows affected (0.09 sec)

3)修改/etc/mysql-mmm/mmm_common.conf配置文件所有的节点都需要配置:
注意:此配置文件主1212和代理服务都需要配置

[root@kgc1 mysql]# vim /etc/mysql-mmm/mmm_common.conf 

active_master_role      writer

<host default>
    cluster_interface       ens33
    pid_path                /run/mysql-mmm-agent.pid
    bin_path                /usr/libexec/mysql-mmm/
    replication_user        zj    //你的mysql主服务的授权用户
    replication_password    123456
    agent_user              mmm_agent   授权的mmm_agent用户和密码
    agent_password          agent
</host>

<host db1>
    ip      172.16.16.801mysql服务器IP地址
    mode    master
    peer    db2
</host>

<host db2>
    ip      172.16.16.1002mysql服务器ip地址
    mode    master
    peer    db1
</host>

<host db3>
    ip      172.16.16.601mysql服务器ip地址
    mode    slave
</host>

<host db4>
    ip      172.16.16.702 mysql服务器ip地址
    mode    slave
</host>


<role writer>
    hosts   db1, db2
    ips     172.16.16.200
    mode    exclusive
</role>

<role reader>
    hosts   db3, db4
    ips     172.16.16.201, 172.16.16.202
    mode    balanced
</role>
          









4)修改vim /etc/mysql-mmm/mmm_agent.conf 文件:主1212都需要修改

[root@kgc1 mysql]# vim /etc/mysql-mmm/mmm_agent.conf 

include mmm_common.conf

# The 'this' variable refers to this server.  Proper operation requires
# that 'this' server (db1 by default), as well as all other servers, have the
# proper IP addresses set in mmm_common.conf.
this db1    (你在common.conf里面对应的db位置)

5)修改代理服务器上的vim /etc/mysql-mmm/mmm_mon.conf 文件

[root@kgc1 ~]# vim /etc/mysql-mmm/mmm_mon.conf 

include mmm_common.conf

<monitor>
    ip                  127.0.0.1   //本地
    pid_path            /run/mysql-mmm-monitor.pid
    bin_path            /usr/libexec/mysql-mmm
    status_path         /var/lib/mysql-mmm/mmm_mond.status
    ping_ips            172.16.16.80,172.16.16.100,172.16.16.60,172.16.16.70  //你监控的主1主2从1从2的ip第
    auto_set_online     10

    # The kill_host_bin does not exist by default, though the monitor will
    # throw a warning about it missing.  See the section 5.10 "Kill Host
    # Functionality" in the PDF documentation.
    #
    # kill_host_bin     /usr/libexec/mysql-mmm/monitor/kill_host
    #
</monitor>

<host default>
    monitor_user        mmm_monitor  //mysql数据库授权用mmm_monito和密码
    monitor_password    monitor
</host>

debug 0

注意代理服务也需要配置 vim /etc/mysql-mmm/mmm_common.conf 和前面的主从一样的配置


6)开启代理和监控服务:
[root@kgc1 mysql]# systemctl start mysql-mmm-agent //主1
[root@kgc1 mysql]# systemctl start mysql-mmm-agent  //主2
[root@kgc1 mysql]# systemctl start mysql-mmm-agent  //从1
[root@kgc1 mysql]# systemctl start mysql-mmm-agent  //从2
[root@kgc1 ~]# systemctl start mysql-mmm-monitor //监控代理服务器开启监控功能:
7)在代理服务器上测试群集:
[root@kgc1 ~]# mmm_control show
  db1(172.16.16.80) master/ONLINE. Roles: writer(172.16.16.200)
  db2(172.16.16.100) master/ONLINE. Roles: 
  db3(172.16.16.60) slave/ONLINE. Roles: reader(172.16.16.201)
  db4(172.16.16.70) slave/ONLINE. Roles: reader(172.16.16.202)
表示已经配置成功
8)如果测试群集结果如下:
[root@kgc1 ~]# mmm_control show
  db1(172.16.16.80) master/AWAITING_RECOVERY. Roles: 
  db2(172.16.16.100) master/AWAITING_RECOVERY. Roles: 
  db3(172.16.16.60) slave/AWAITING_RECOVERY. Roles: 
  db4(172.16.16.70) slave/AWAITING_RECOVERY. Roles: 、
说明各服务器没有时间同步:

9)虚拟机时间同步:可以使用yum install chrony -y来配置文件实现虚拟机时间同步:

你可能感兴趣的:(mysql,centos,数据库)