mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.14 sec)
mysql> set global rpl_semi_sync_slave_enabled=1;
Query OK, 0 rows affected (0.00 sec)
mysql> set global read_only=1;
#设置为只读模式,因为是备选 master,所以当
master 宕机时,candidate master 要充当 master,故不用写进配置文件中
Query OK, 0 rows affected (0.00 sec)
给所创建的认证用户复制权限及 root 用户所有权限的授权
mysql> grant all privileges on .to root@’172.25.40.%’ identified by ‘xxxxxxxx’;
##这个密码是 manager 主机配置文件里面所写的密码
Slave 端配置:
yum install perl-DBD-mysql -y
rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm
构建免密登陆
ssh-keygen
##生成密钥
ssh-copy-id 172.25.40.1##给另外两台 mysql 主机分发,这样可以免密连接
ssh-copy-id 172.25.40.2
mysql 主配置文件(/etc/my.cnf)配置
[mysqlnd]
除过 server-id 是不同的,其他参数均一样
server-id=3
重新启动两台服务器上的 mysql
/etc/init.d/mysqld restart
进入数据库下载半同步模块
mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.14 sec)lave_enabled=1;
Query OK, 0 rows affected (0.00
mysql> set global rpl_semi_sync_slave_enabled=1
给所创建的认证用户复制权限及 root 用户所有权限的授权
mysql> grant all privileges on *.* to 'root'@'172.168.40.%' identified
'xxxxxxxxx';
Query OK, 0 rows affected, 1 warning (0.00 sec)
by
mysql> grant replication slave on *.* to 'redhat'@'172.168.40.%' identified by
'xxxxxxxx';
mysql> change master to
master_host='172.25.40.1',master_user='redhat',master_password='xxxxxxxxxx',
master_auto_position=1;
Mha 主机
yum install perl-* mha4mysql-manager-0.56-0.el6.noarch.rpm -y
mkdir /usr/local/mha
##创建工作目录 workdir
mkdir /etc/mha
cd /etc/mha/
##创建配置文件所在目录
vim app.conf
[server default]
manager_workdir=/usr/local/mha
manager_log=/usr/local/mha/mha.log
master_binlog_dir=/var/lib/mysql
user=root ##数据库用户 登陆数据库的用户 ,用于manager监控管理用户和密码
password=xxxxxxxx ##数据库登陆密码 初始化的时候登陆数据库的密码
ping_interval=1
remote_workdir=/tmp
repl_user=redhat ##复制用户(授权在slave上)用于主从间复制
repl_password=xxxxxxxx ##slave复制用户的密码 ssh_user=root ##ssh用户
[server1]
hostname=172.25.40.1
port=3306
[server2]
hostname=172.25.40.2
port=3306
candidate_master=1 ##备用主机 check_repl_delay=0 ##日至差异大于100M的时候,不做master,两个参数通常一起使用
[server3]
hostname=172.25.40.3
port=3306
#no_master=1 ##永远不会作为master
检查MySQL复制状况
masterha_check_repl –conf=/etc/mha/app.cnf
Tue Apr 24 09:14:45 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Tue Apr 24 09:14:45 2018 - [info] Reading application default configuration from /etc/mha/app.conf..
Tue Apr 24 09:14:45 2018 - [info] Reading server configuration from /etc/mha/app.conf..
Tue Apr 24 09:14:45 2018 - [info] MHA::MasterMonitor version 0.56.
Tue Apr 24 09:14:45 2018 - [info] GTID failover mode = 1
Tue Apr 24 09:14:45 2018 - [info] Dead Servers:
Tue Apr 24 09:14:45 2018 - [info] Alive Servers:
Tue Apr 24 09:14:45 2018 - [info] 172.25.40.1(172.25.40.1:3306)
Tue Apr 24 09:14:45 2018 - [info] 172.25.40.2(172.25.40.2:3306)
Tue Apr 24 09:14:45 2018 - [info] 172.25.40.3(172.25.40.3:3306)
Tue Apr 24 09:14:45 2018 - [info] Alive Slaves:
Tue Apr 24 09:14:45 2018 - [info] 172.25.40.2(172.25.40.2:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Tue Apr 24 09:14:45 2018 - [info] GTID ON
Tue Apr 24 09:14:45 2018 - [info] Replicating from 172.25.40.1(172.25.40.1:3306)
Tue Apr 24 09:14:45 2018 - [info] Primary candidate for the new Master (candidate_master is set)
Tue Apr 24 09:14:45 2018 - [info] 172.25.40.3(172.25.40.3:3306) Version=5.7.17 (oldest major version between slaves) log-bin:disabled
Tue Apr 24 09:14:45 2018 - [info] GTID ON
Tue Apr 24 09:14:45 2018 - [info] Replicating from 172.25.40.1(172.25.40.1:3306)
Tue Apr 24 09:14:45 2018 - [info] Not candidate for the new Master (no_master is set)
Tue Apr 24 09:14:45 2018 - [info] Current Alive Master: 172.25.40.1(172.25.40.1:3306)
Tue Apr 24 09:14:45 2018 - [info] Checking slave configurations..
Tue Apr 24 09:14:45 2018 - [info] read_only=1 is not set on slave 172.25.40.2(172.25.40.2:3306).
Tue Apr 24 09:14:45 2018 - [info] read_only=1 is not set on slave 172.25.40.3(172.25.40.3:3306).
Tue Apr 24 09:14:45 2018 - [warning] log-bin is not set on slave 172.25.40.3(172.25.40.3:3306). This host cannot be a master.
Tue Apr 24 09:14:45 2018 - [info] Checking replication filtering settings..
Tue Apr 24 09:14:45 2018 - [info] binlog_do_db= , binlog_ignore_db=
Tue Apr 24 09:14:45 2018 - [info] Replication filtering check ok.
Tue Apr 24 09:14:46 2018 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Tue Apr 24 09:14:46 2018 - [info] Checking SSH publickey authentication settings on the current master..
Tue Apr 24 09:14:46 2018 - [info] HealthCheck: SSH to 172.25.40.1 is reachable.
Tue Apr 24 09:14:46 2018 - [info]
172.25.40.1(172.25.40.1:3306) (current master)
+--172.25.40.2(172.25.40.2:3306)
+--172.25.40.3(172.25.40.3:3306)