MMMについて
MMMは(MySQL用のマスターマスターレプリケーションマネージャー)デュアルデュアルマスタースクリプトや日々の管理のためのマスター・フェイルオーバー・サポートのセットです。MMM使用Perl言語の開発、主にコピーMySQLのマスター・マスター(ダブルマスター)を監視し、管理するために使用され、それはmysqlのマスターマスターレプリケーションマネージャーに言うことができます。また、メインメインメイン予熱時間の切り替えを加速するために、代わりにメイン読みデュアルマスター・レプリケーションと呼ばれるが、同じ時間でのサービスは他の部分にサービスを提供するために、1つのマスタのみ書き込みを許可しますが、それはMMMと言うことができます追加のツールのスクリプトは、複数のスレーブの均衡読み取り負荷を実現することができるの内側に一方ではスクリプトのセットは、他の一方で、フェイルオーバー機能を実現しています。mysqlのマスターマスターレプリケーション構成の監視について、スケーラブルなスイートスクリプトのフェールオーバーおよび管理(1つのノードのみいつでも書き込むことができます)、キットはまた、家庭での生活の標準から、任意の数の構成からなることができますあなたはほかに、コピーを生きて起動する仮想IPのサーバーのグループにそれを使用することができますので、サーバーの負荷分散を読んで、それはノード間のバックアップデータのスクリプトの再同期化を実現しました。
MMMは、高い待ち時間サーバー仮想IPサーバーのコピー・セットの自動および手動モード除去を提供するが、それ缶バックアップデータ、2つのノード間のデータの同期。MMMはない完全に保証データの一貫性、一貫性MMMは、データ要件に適用することができるので非常に高くはありませんが、サービスの可用性シナリオの最大の度合いを確認したいです。MMM方式は、高可用性のmysqlを達成するために、サーバーをフェイルオーバーすることができてのMySQL自体は、レプリケーションのフェイルオーバーソリューションを提供していません。業務のデータ要件のそれらの高い一貫性を保つため、これはMMM高可用性アーキテクチャをお勧めしません。
実験環境
主服务器1:192.168.52.135 db1 writer VIP:192.168.52.200
主服务器2:192.168.52.133 db2
从服务器1:192.168.52.134 db3 reader VIP:192.168.52.210,192.168.52.220
从服务器2:192.168.52.148 db4
监控服务器:192.168.52.150
実験操作
4台のMySQLサーバ上でまず、インストールされたmariadbサービス
(それぞれ、同じサーバー上の4つの操作)ローカルYUMソースを構成する1
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#配置aliyun源
--2019-11-25 09:51:39-- http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 124.14.2.219, 124.14.2.218, 124.14.2.234, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|124.14.2.219|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”
100%[====================================================================================>] 2,523 --.-K/s 用时 0s
2019-11-25 09:51:39 (225 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])
[root@localhost ~]# yum -y install epel-release #安装epel-release源
.......................//省略过程
[root@localhost ~]# yum clean all && yum makecache #清除缓存旧的缓存,同步现在服务器的缓存
........................//省略过程
図2に示すように、プライマリ・サーバ上で実装MariaDB(サービスのMySQLの一種)サービス1
[root@localhost ~]# hostnamectl set-hostname db1 #修改主机名
[root@localhost ~]# su #切换bash环境
[root@db1 ~]#
[root@db1 ~]# yum install mariadb-server mariadb -y #安装服务
....................//省略过程
[root@db1 ~]# vim /etc/my.cnf #修改配置文件
[mysqld]
log_error=/var/lib/mysql/mysql.err
log=/var/lib/mysql/mysql_log.log
log_slow_queries=/var/lib/mysql_slow_queris.log
binlog-ignore-db=mysql,information_schema
character_set_server=utf8
log_bin=mysql_bin
server_id=1
log_slave_updates=true
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
[root@db1 ~]# systemctl stop firewalld.service #关闭防火墙
[root@db1 ~]# setenforce 0 #关闭增强性安全功能
[root@db1 ~]# systemctl start mariadb.service #开启服务
[root@db1 ~]# netstat -ntap | grep 3306 #查看端口
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 4601/mysqld
[root@db1 ~]#
3、プライマリサーバサービスmariadbにインストールされている2
[root@localhost ~]# hostnamectl set-hostname db2
[root@localhost ~]# su
[root@db2 ~]#
[root@db2 ~]# yum install mariadb-server mariadb -y
[root@db2 ~]# vim /etc/my.cnf
[mysqld]
log_error=/var/lib/mysql/mysql.err
log=/var/lib/mysql/mysql_log.log
log_slow_queries=/var/lib/mysql_slow_queris.log
binlog-ignore-db=mysql,information_schema
character_set_server=utf8
log_bin=mysql_bin
server_id=2
log_slave_updates=true
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
[root@db2 ~]# systemctl stop firewalld.service
[root@db2 ~]# setenforce 0
[root@db2 ~]# systemctl start mariadb.service
[root@db2 ~]# netstat -ntap | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 50643/mysqld
[root@db2 ~]#
4、サーバ1 mariadbサービスからのインストール
[root@localhost ~]# hostnamectl set-hostname db3
[root@localhost ~]# su
[root@db3 ~]#
[root@db3 ~]# yum install mariadb-server mariadb -y
[root@db3 ~]# vim /etc/my.cnf
[mysqld]
log_error=/var/lib/mysql/mysql.err
log=/var/lib/mysql/mysql_log.log
log_slow_queries=/var/lib/mysql_slow_queris.log
binlog-ignore-db=mysql,information_schema
character_set_server=utf8
log_bin=mysql_bin
server_id=11
log_slave_updates=true
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
[root@db3 ~]# systemctl stop firewalld.service
[root@db3 ~]# setenforce 0
[root@db3 ~]# systemctl start mariadb.service
[root@db3 ~]# netstat -ntap | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 50578/mysqld
[root@db3 ~]#
5、サーバ2 mariadbサービスからのインストール
[root@localhost ~]# hostnamectl set-hostname db4
[root@localhost ~]# su
[root@db4 ~]#
[root@db4 ~]# yum install mariadb-server mariadb -y
[root@db4 ~]# vim /etc/my.cnf
[mysqld]
log_error=/var/lib/mysql/mysql.err
log=/var/lib/mysql/mysql_log.log
log_slow_queries=/var/lib/mysql_slow_queris.log
binlog-ignore-db=mysql,information_schema
character_set_server=utf8
log_bin=mysql_bin
server_id=22
log_slave_updates=true
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
[root@db4 ~]# systemctl stop firewalld.service
[root@db4 ~]# setenforce 0
[root@db4 ~]# systemctl start mariadb.service
[root@db4 ~]# netstat -ntap | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 39804/mysqld
[root@db4 ~]#
第二に、マルチモード、マルチマスタのMySQLの設定から
ロケーションPOS値log_bin 1、各マスタ・サーバと1とメインサーバログ2
主服务器1:
[root@db1 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show master status; #查看状态
+------------------+----------+--------------+--------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+--------------------------+
| mysql_bin.000003 | 245 | | mysql,information_schema |
+------------------+----------+--------------+--------------------------+
1 row in set (0.00 sec)
主服务器2:
[root@db2 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show master status; #查看状态
+------------------+----------+--------------+--------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+--------------------------+
| mysql_bin.000003 | 245 | | mysql,information_schema |
+------------------+----------+--------------+--------------------------+
1 row in set (0.00 sec)
図2に示すように、メインサーバ1とメインサーバ2は、互いへのアクセスを強化します
主服务器1:
MariaDB [(none)]> grant replication slave on *.* to 'replication'@'192.168.52.%' identified by '123456';
#提权
Query OK, 0 rows affected (0.01 sec)
主服务器2:
MariaDB [(none)]> grant replication slave on *.* to 'replication'@'192.168.52.%' identified by '123456';
#提权
Query OK, 0 rows affected (0.01 sec)
主服务器1:
MariaDB [(none)]> change master to master_host='192.168.52.133',master_user='replication',master_password='123456',master_log_file='mysql_bin.000003',master_log_pos=245;
#指定同步服务器的具体信息
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> start slave; #开启同步
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show slave status\G; #查看状态
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.52.133
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql_bin.000003
Read_Master_Log_Pos: 575
Relay_Log_File: mariadb-relay-bin.000002
Relay_Log_Pos: 694
Relay_Master_Log_File: mysql_bin.000003
Slave_IO_Running: Yes #确认开启
Slave_SQL_Running: Yes #确认开启
Master_Server_Id: 2
1 row in set (0.00 sec)
ERROR: No query specified
主服务器2:
MariaDB [(none)]> change master to master_host='192.168.52.135',master_user='replication',master_password='123456',master_log_file='mysql_bin.000003',master_log_pos=245;
#指定同步服务器的具体信息
Query OK, 0 rows affected (0.02 sec)
MariaDB [(none)]> start slave; #开启同步
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> show slave status\G; #查看状态
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.52.135
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql_bin.000003
Read_Master_Log_Pos: 575
Relay_Log_File: mariadb-relay-bin.000002
Relay_Log_Pos: 694
Relay_Master_Log_File: mysql_bin.000003
Slave_IO_Running: Yes #确认开启
Slave_SQL_Running: Yes #确认开启
Master_Server_Id: 1
1 row in set (0.00 sec)
ERROR: No query specified
3、試験マスタプライマリ同期
主服务器1:
MariaDB [(none)]> create database school; #创建数据库school
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> show databases; #查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| school | #创建成功
| test |
+--------------------+
5 rows in set (0.00 sec)
主服务器2:
MariaDB [(none)]> show databases; #查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| school | #同步成功
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> drop database school; #删除数据库school
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> show databases; #查看数据库(删除成功)
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
主服务器1:
MariaDB [(none)]> show databases; #查看数据库(同步成功)
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
図4に示すように、ライブラリからのマスタサーバとしてサーバ1から構成1
从服务器1:
[root@db3 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> change master to master_host='192.168.52.135',master_user='replication',master_password='123456',master_log_file='mysql_bin.000003',master_log_pos=245;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]>
从服务器2:
[root@db4 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> change master to master_host='192.168.52.135',master_user='replication',master_password='123456',master_log_file='mysql_bin.000003',master_log_pos=245;
Query OK, 0 rows affected (0.02 sec)
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
図5に示すように、マルチモードマルチマスター試験から
主服务器1:
MariaDB [(none)]> create database myschool; #创建数据库myschool
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> show databases; #查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| myschool | #创建成功
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> quit
Bye
[root@db1 ~]#
主服务器2:
MariaDB [(none)]> show databases; #查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| myschool | #同步成功
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> quit
Bye
[root@db2 ~]#
从服务器1:
MariaDB [(none)]> show databases; #查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| myschool | #同步成功
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> quit
Bye
[root@db3 ~]#
从服务器2:
MariaDB [(none)]> show databases; #查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| myschool | #同步成功
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> quit
Bye
[root@db4 ~]#
第三に、インストール構成のMySQL-MMM
1は、4つのMySQLサーバーはMMMインストールされています
[root@db1 ~]# yum -y install mysql-mmm*
........//省略过程
[root@db1 ~]#
[root@db2 ~]# yum -y install mysql-mmm*
.......//省略过程
[root@db2 ~]#
[root@db3 ~]# yum -y install mysql-mmm*
........//省略过程
[root@db3 ~]#
[root@db4 ~]# yum -y install mysql-mmm*
.........//省略过程
[root@db4 ~]#
2、設定ファイルを変更し/etc/mysql-mmm/mmm_common.conf
[root@db1 ~]# vim /etc/mysql-mmm/mmm_common.conf
<host default>
cluster_interface ens33
pid_path /run/mysql-mmm-agent.pid
bin_path /usr/libexec/mysql-mmm/
replication_user replication
replication_password 123456
agent_user mmm_agent
agent_password 123456
</host>
<host db1>
ip 192.168.52.135
mode master
peer db2
</host>
<host db2>
ip 192.168.52.133
mode master
peer db1
</host>
<host db3>
ip 192.168.52.134
mode slave
</host>
<host db4>
ip 192.168.52.148
mode slave
</host>
<role writer>
hosts db1, db2
ips 192.168.52.200
mode exclusive
</role>
<role reader>
hosts db3, db4
ips 192.168.52.210, 192.168.52.220
mode balanced
</role>
3、/etc/mysql-mmm/mmm_common.confプロファイル、他の3つのプッシュサーバー
[root@db1 ~]# scp /etc/mysql-mmm/mmm_common.conf [email protected]:/etc/mysql-mmm/
[email protected]'s password:
mmm_common.conf 100% 837 1.1MB/s 00:00
[root@db1 ~]# scp /etc/mysql-mmm/mmm_common.conf [email protected]:/etc/mysql-mmm/
[email protected]'s password:
mmm_common.conf 100% 837 1.1MB/s 00:00
[root@db1 ~]# scp /etc/mysql-mmm/mmm_common.conf [email protected]:/etc/mysql-mmm/
[email protected]'s password:
mmm_common.conf 100% 837 951.0KB/s 00:00
図4に示すように、モニター上のローカル設定サーバYUMソースモニタ
[root@localhost ~]# hostnamectl set-hostname monitor
[root@localhost ~]# su
[root@monitor ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2019-11-25 11:40:39-- http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 124.14.2.222, 124.14.2.218, 124.14.2.234, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|124.14.2.222|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”
100%[====================================================================================>] 2,523 --.-K/s 用时 0s
2019-11-25 11:40:39 (663 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])
[root@monitor ~]#
[root@monitor ~]# yum -y install epel-release
..........//省略过程
[root@monitor ~]# yum clean all && yum makecache
.........//省略过程
[root@monitor ~]# yum -y install mysql-mmm*
.........//省略过程
図5に示すように、メインサーバ1は、モニタプロファイルプッシュ/etc/mysql-mmm/mmm_common.conf
[root@db1 ~]# scp /etc/mysql-mmm/mmm_common.conf [email protected]:/etc/mysql-mmm/
[email protected]'s password:
mmm_common.conf 100% 837 1.4MB/s 00:00
[root@db1 ~]#
6、コンフィギュレーションファイルを変更/etc/mysql-mmm/mmm_mon.conf
[root@monitor ~]# vim /etc/mysql-mmm/mmm_mon.conf
ping_ips 192.168.52.135,192.168.52.133,192.168.52.134,192.168.52.148 #监控服务器IP
auto_set_online 10
<host default>
monitor_user mmm_monitor #用户名
monitor_password 123456 #密码
</host>
7、それぞれ、4回の許可されたアクセスでMySQLサーバを監視します
主服务器1:
[root@db1 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant super, replication client, process on *.* to 'mmm_agent'@'192.168.52.%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> grant replication client on *.* to 'mmm_monitor'@'192.168.52.%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> quit
Bye
[root@db1 ~]#
主服务器2:
[root@db2 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant super, replication client, process on *.* to 'mmm_agent'@'192.168.52.%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> grant replication client on *.* to 'mmm_monitor'@'192.168.52.%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> quit
Bye
[root@db2 ~]#
从服务器1:
[root@db3 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant super, replication client, process on *.* to 'mmm_agent'@'192.168.52.%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> grant replication client on *.* to 'mmm_monitor'@'192.168.52.%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> quit
Bye
[root@db3 ~]#
从服务器2:
[root@db4 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant super, replication client, process on *.* to 'mmm_agent'@'192.168.52.%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> grant replication client on *.* to 'mmm_monitor'@'192.168.52.%' identified by '123456';
Query OK, 0 rows affected (0.02 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit
Bye
[root@db4 ~]#
8、それぞれ、/etc/mysql-mmm/mmm_agent.confファイルのMySQLサーバを変更
主服务器1:
[root@db1 ~]# 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 #根据不同主机修改
[root@db1 ~]# systemctl start mysql-mmm-agent.service #开启服务
[root@db1 ~]# systemctl enable mysql-mmm-agent.service #开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/mysql-mmm-agent.service to /usr/lib/systemd/system/mysql-mmm-agent.service.
[root@db1 ~]#
主服务器2:
[root@db2 ~]# 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 db2 #根据不同主机修改
[root@db2 ~]# systemctl start mysql-mmm-agent.service #开启服务
[root@db2 ~]# systemctl enable mysql-mmm-agent.service #开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/mysql-mmm-agent.service to /usr/lib/systemd/system/mysql-mmm-agent.service.
[root@db2 ~]#
从服务器1:
[root@db3 ~]# 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 db3 #根据不同主机修改
[root@db3 ~]# systemctl start mysql-mmm-agent.service #开启服务
[root@db3 ~]# systemctl enable mysql-mmm-agent.service #开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/mysql-mmm-agent.service to /usr/lib/systemd/system/mysql-mmm-agent.service.
[root@db3 ~]#
从服务器2:
[root@db4 ~]# 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 db4 #根据不同主机修改
[root@db4 ~]# systemctl start mysql-mmm-agent.service #开启服务
[root@db4 ~]# systemctl enable mysql-mmm-agent.service #开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/mysql-mmm-agent.service to /usr/lib/systemd/system/mysql-mmm-agent.service.
[root@db4 ~]#
第四に、テストMMMの可用性
1、オープンのmysql-MMM-monitor.service
[root@monitor ~]# systemctl stop firewalld.service #关闭防火墙
[root@monitor ~]# setenforce 0 #关闭增强性安全功能
[root@monitor ~]# systemctl start mysql-mmm-monitor.service #开启服务
[root@monitor ~]# mmm_control show #测试群集
db1(192.168.52.135) master/ONLINE. Roles: writer(192.168.52.200)
db2(192.168.52.133) master/ONLINE. Roles:
db3(192.168.52.134) slave/ONLINE. Roles: reader(192.168.52.220)
db4(192.168.52.148) slave/ONLINE. Roles: reader(192.168.52.210)
2、クラスター(すべてOK)をチェック
[root@monitor ~]# mmm_control checks all
db4 ping [last change: 2019/11/25 12:15:00] OK
db4 mysql [last change: 2019/11/25 12:15:00] OK
db4 rep_threads [last change: 2019/11/25 12:15:00] OK
db4 rep_backlog [last change: 2019/11/25 12:15:00] OK: Backlog is null
db2 ping [last change: 2019/11/25 12:15:00] OK
db2 mysql [last change: 2019/11/25 12:15:00] OK
db2 rep_threads [last change: 2019/11/25 12:15:00] OK
db2 rep_backlog [last change: 2019/11/25 12:15:00] OK: Backlog is null
db3 ping [last change: 2019/11/25 12:15:00] OK
db3 mysql [last change: 2019/11/25 12:15:00] OK
db3 rep_threads [last change: 2019/11/25 12:15:00] OK
db3 rep_backlog [last change: 2019/11/25 12:15:00] OK: Backlog is null
db1 ping [last change: 2019/11/25 12:15:00] OK
db1 mysql [last change: 2019/11/25 12:15:00] OK
db1 rep_threads [last change: 2019/11/25 12:15:00] OK
db1 rep_backlog [last change: 2019/11/25 12:15:00] OK: Backlog is null
[root@monitor ~]#
3、切り替えてライターDB2
[root@monitor ~]# mmm_control move_role writer db2
OK: Role 'writer' has been moved from 'db1' to 'db2'. Now you can wait some time and check new roles info!
[root@monitor ~]# mmm_control show
db1(192.168.52.135) master/ONLINE. Roles:
db2(192.168.52.133) master/ONLINE. Roles: writer(192.168.52.200)
db3(192.168.52.134) slave/ONLINE. Roles: reader(192.168.52.220)
db4(192.168.52.148) slave/ONLINE. Roles: reader(192.168.52.210)
[root@monitor ~]#
4、モニターの設置mariadbサービス
[root@monitor ~]# yum install mariadb-server mariadb -y
.......//省略过程
[root@monitor ~]#
図5は、各モニタはメインサーバ1へのアクセスを許可しました
主服务器1:
[root@db1 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 464
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant all on *.* to 'testdb'@'192.168.52.150' identified by '123456'; #授权
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]>
図6は、マスターサーバーモニタの仮想IPを使用してログインします
[root@monitor ~]# mysql -u testdb -p123456 -h 192.168.52.200
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 584
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| myschool |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]>
7、メインサーバのMySQLサービスをオフ1
[root@db1 ~]# systemctl stop mariadb.service
[root@db1 ~]#
8、監視サーバーのmyschool上のデータベースを削除
monitor:
MariaDB [(none)]> drop database myschool;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
それぞれ9、3は、データベース・サーバを閉じていなかった参照するには
主服务器2:
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
从服务器1:
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
从服务器2:
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
10、メインサーバは、データベースを表示するには、MySQLのサービス1を再起動します
[root@db1 ~]# systemctl stop mariadb.service
[root@db1 ~]#
[root@db1 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 464
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases; #查看数据库(同步成功)
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>