数据库MHA高可用集群部署

一、MHA集群特点:

**是一套优秀的mysql高可用解决方案
**可在0~30s内完成数据可自动故障切换
**故障切换过程中最大限度保证数据库的一致性

二、MHA的组成

**MHA Manger(管理节点)
–管理所有的数据库服务器
–可以单独部署在独立的机器上也可以部署在某台数据库上
**MHA Node(数据节点)
–存储数据的mysql服务器
–运行在每台mysql服务器上

三、工作过程

**Manger定时探测集群中的master节点
**当master故障时,Manger自动将拥有最近数据的slave提升为master

四、拓扑规划

数据库MHA高可用集群部署_第1张图片数据库MHA高可用集群部署_第2张图片

ip规划
数据库MHA高可用集群部署_第3张图片

五、部署思路

1.准备集群环境(node)
①安装依赖包
②所有数据库配置免密认证登录
③配置一主多从
2.配置管理节点(mgm)----管理集群命令
①安装MHA程序的软件包
②编写主配置文件(节点信息、监控用户信息、主数据库信息、故障切换脚本)
3.配置数据库节点信息
①配置主服务器VIP地址(51)
②在所有数据库服务器上安装mha-node软件包(51/52/53)
③配置主数据库服务器后重启(监控用户授权、半同步复制、进制自动删除中继日志、binlog日志)-51/52/53
4.测试配置
①在管理主机,测试ssh配置
[root@mgm57 ~]# masterha_check_ssh --conf=/etc/mha/app1.cnf //执行测试命令
②在管理主机上测试主从同步
[root@host57 ~]# masterha_check_repl --conf=/etc/mha/app1.cnf //执行测试命令


配置完成图

数据库MHA高可用集群部署_第4张图片************************************************************************************************************************************************************
1)配置数据库服务器192.168.4.51

[root@host51 ~]# ssh-keygen //创建秘钥对

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): //回车

Enter passphrase (empty for no passphrase): //回车

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:qb7EZByHad3Jadr+zkiEbo7ZKGmCNlctgp+Wfp3Yad0 root@pxcnode71

The key's randomart image is:

+---[RSA 2048]----+

| |

| + o o |

| = o * |

| o o * |

| . = S o |

| . . * + o |

| .. =.O * + |

|.o.*+= & o E |

|. =+..B.o ..+ |

+----[SHA256]-----+

[root@host51 ~]#

[root@host51 ~]# ssh-copy-id [email protected] //传递公钥给host52主机

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]'s password: //输入host52主机系统管理员root用户密码

Number of key(s) added: 1

Now try logging into the machine, with: "ssh '[email protected]'"

and check to make sure that only the key(s) you wanted were added.

[root@host51 ~]#

[root@host51 ~]# ssh-copy-id [email protected] //传递公钥给host53主机

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]'s password: //输入host53主机系统管理员root用户密码

Number of key(s) added: 1

Now try logging into the machine, with: "ssh '[email protected]'"

and check to make sure that only the key(s) you wanted were added.

[root@host51 ~]#

[root@host51 ~]# ssh [email protected] //可以无密码连接52主机

Last login: Fri Jun 21 13:21:39 2019 from 192.168.4.254

.-"""-.

/ .===. \

\/ 6 6 \/

( \___/ )

_________ooo__\_____/_____________

/ \

| I am Virtual Host ! ! ! |

\_______________________ooo________/

| | |

|_ | _|

| | |

|__|__|

/-'Y'-\

(__/ \__)

[root@host52 ~]#

[root@host52 ~]# exit //断开连接

登出

Connection to 192.168.4.52 closed.

[root@host51 ~]#

[root@host51 ~]# ssh [email protected] //可以无密码连接52主机

Last login: Fri Jun 21 09:01:15 2019 from 192.168.4.254

.-"""-.

/ .===. \

\/ 6 6 \/

( \___/ )

_________ooo__\_____/_____________

/ \

| I am Virtual Host ! ! ! |

\_______________________ooo________/

| | |

|_ | _|

| | |

|__|__|

/-'Y'-\

(__/ \__)

[root@host53 ~]# exit//断开连接

登出

Connection to 192.168.4.53 closed.

[root@host51 ~]#

2)配置数据库服务器192.168.4.52

[root@host52 ~]# ssh-keygen //创建秘钥对

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): //回车

Enter passphrase (empty for no passphrase): //回车

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:qb7EZByHad3Jadr+zkiEbo7ZKGmCNlctgp+Wfp3Yad0 root@pxcnode71

The key's randomart image is:

+---[RSA 2048]----+

| |

| + o o |

| = o * |

| o o * |

| . = S o |

| . . * + o |

| .. =.O * + |

|.o.*+= & o E |

|. =+..B.o ..+ |

+----[SHA256]-----+

[root@host52 ~]#

[root@host52 ~]# ssh-copy-id [email protected] //传递公钥给host51主机

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]'s password: //输入host51主机系统管理员root用户密码

Number of key(s) added: 1

Now try logging into the machine, with: "ssh '[email protected]'"

and check to make sure that only the key(s) you wanted were added.

[root@host52 ~]#

[root@host52 ~]# ssh-copy-id [email protected] //传递公钥给host53主机

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]'s password: //输入host53主机系统管理员root用户密码

Number of key(s) added: 1

Now try logging into the machine, with: "ssh '[email protected]'"

and check to make sure that only the key(s) you wanted were added.

[root@host52 ~]#

[root@host52 ~]# ssh [email protected] //可以无密码连接51主机

Last login: Fri Jun 21 13:21:39 2019 from 192.168.4.254

.-"""-.

/ .===. \

\/ 6 6 \/

( \___/ )

_________ooo__\_____/_____________

/ \

| I am Virtual Host ! ! ! |

\_______________________ooo________/

| | |

|_ | _|

| | |

|__|__|

/-'Y'-\

(__/ \__)

[root@host51 ~]#

[root@host51 ~]# exit //断开连接

登出

Connection to 192.168.4.52 closed.

[root@host52 ~]#

[root@host52 ~]# ssh [email protected] //可以无密码连接53主机

Last login: Fri Jun 21 09:01:15 2019 from 192.168.4.254

.-"""-.

/ .===. \

\/ 6 6 \/

( \___/ )

_________ooo__\_____/_____________

/ \

| I am Virtual Host ! ! ! |

\_______________________ooo________/

| | |

|_ | _|

| | |

|__|__|

/-'Y'-\

(__/ \__)

[root@host53 ~]# exit//断开连接

登出

Connection to 192.168.4.53 closed.

[root@host52 ~]#

3)配置数据库服务器192.168.4.53

[root@host53 ~]# ssh-keygen //创建秘钥对

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): //回车

Enter passphrase (empty for no passphrase): //回车

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:qb7EZByHad3Jadr+zkiEbo7ZKGmCNlctgp+Wfp3Yad0 root@pxcnode71

The key's randomart image is:

+---[RSA 2048]----+

| |

| + o o |

| = o * |

| o o * |

| . = S o |

| . . * + o |

| .. =.O * + |

|.o.*+= & o E |

|. =+..B.o ..+ |

+----[SHA256]-----+

[root@host53 ~]#

[root@host53 ~]# ssh-copy-id [email protected] //传递公钥给host51主机

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]'s password: //输入host51主机系统管理员root用户密码

Number of key(s) added: 1

Now try logging into the machine, with: "ssh '[email protected]'"

and check to make sure that only the key(s) you wanted were added.

[root@host53 ~]#

[root@host53 ~]# ssh-copy-id [email protected] //传递公钥给host52主机

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]'s password: //输入host52主机系统管理员root用户密码

Number of key(s) added: 1

Now try logging into the machine, with: "ssh '[email protected]'"

and check to make sure that only the key(s) you wanted were added.

[root@host53 ~]#

[root@host53 ~]# ssh [email protected] //可以无密码连接51主机

Last login: Fri Jun 21 13:21:39 2019 from 192.168.4.254

.-"""-.

/ .===. \

\/ 6 6 \/

( \___/ )

_________ooo__\_____/_____________

/ \

| I am Virtual Host ! ! ! |

\_______________________ooo________/

| | |

|_ | _|

| | |

|__|__|

/-'Y'-\

(__/ \__)

[root@host51 ~]#

[root@host51 ~]# exit //断开连接

登出

Connection to 192.168.4.51 closed.

[root@host53 ~]#

[root@host53 ~]# ssh [email protected] //可以无密码连接52主机

Last login: Fri Jun 21 09:01:15 2019 from 192.168.4.254

.-"""-.

/ .===. \

\/ 6 6 \/

( \___/ )

_________ooo__\_____/_____________

/ \

| I am Virtual Host ! ! ! |

\_______________________ooo________/

| | |

|_ | _|

| | |

|__|__|

/-'Y'-\

(__/ \__)

[root@host52 ~]# exit//断开连接

登出

Connection to 192.168.4.52 closed.

[root@host53 ~]#

4)配置管理服务器192.168.4.57

[root@mgm57 ~]# ssh-keygen //创建秘钥对

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): //回车

Enter passphrase (empty for no passphrase): //回车

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:qb7EZByHad3Jadr+zkiEbo7ZKGmCNlctgp+Wfp3Yad0 root@pxcnode71

The key's randomart image is:

+---[RSA 2048]----+

| |

| + o o |

| = o * |

| o o * |

| . = S o |

| . . * + o |

| .. =.O * + |

|.o.*+= & o E |

|. =+..B.o ..+ |

+----[SHA256]-----+

[root@mgm57 ~]#

[root@mgm57 ~]# ssh-copy-id [email protected] //传递公钥给host51主机

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]'s password: //输入host51主机系统管理员root用户密码

Number of key(s) added: 1

Now try logging into the machine, with: "ssh '[email protected]'"

and check to make sure that only the key(s) you wanted were added.

[root@mgm57 ~]#

[root@mgm57 ~]# ssh-copy-id [email protected] //传递公钥给host52主机

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]'s password: //输入host52主机系统管理员root用户密码

Number of key(s) added: 1

Now try logging into the machine, with: "ssh '[email protected]'"

and check to make sure that only the key(s) you wanted were added.

[root@mgm57 ~]#

[root@mgm57 ~]# ssh-copy-id [email protected] //传递公钥给host52主机

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]'s password: //输入host53主机系统管理员root用户密码

Number of key(s) added: 1

Now try logging into the machine, with: "ssh '[email protected]'"

and check to make sure that only the key(s) you wanted were added.

[root@mgm57 ~]

[root@mgm57 ~]# ssh [email protected] //可以无密码连接51主机

Last login: Fri Jun 21 13:21:39 2019 from 192.168.4.254

.-"""-.

/ .===. \

\/ 6 6 \/

( \___/ )

_________ooo__\_____/_____________

/ \

| I am Virtual Host ! ! ! |

\_______________________ooo________/

| | |

|_ | _|

| | |

|__|__|

/-'Y'-\

(__/ \__)

[root@host51 ~]#

[root@host51 ~]# exit //断开连接

登出

Connection to 192.168.4.51 closed.

[root@mgm57 ~]#

[root@mgm57 ~]# ssh [email protected] //可以无密码连接52主机

Last login: Fri Jun 21 09:01:15 2019 from 192.168.4.254

.-"""-.

/ .===. \

\/ 6 6 \/

( \___/ )

_________ooo__\_____/_____________

/ \

| I am Virtual Host ! ! ! |

\_______________________ooo________/

| | |

|_ | _|

| | |

|__|__|

/-'Y'-\

(__/ \__)

[root@host52 ~]# exit//断开连接

登出

Connection to 192.168.4.52 closed.

[root@mgm57 ~]# ssh [email protected] //可以无密码连接53主机

Last login: Fri Jun 21 09:01:15 2019 from 192.168.4.254

.-"""-.

/ .===. \

\/ 6 6 \/

( \___/ )

_________ooo__\_____/_____________

/ \

| I am Virtual Host ! ! ! |

\_______________________ooo________/

| | |

|_ | _|

| | |

|__|__|

/-'Y'-\

(__/ \__)

[root@host53 ~]# exit//断开连接

登出

Connection to 192.168.4.53 closed.

步骤二: 安装依赖包

1)配置数据库服务器192.168.4.51

[root@host51 ~]# yum -y install perl-* //安装系统自带的perl软件包`在这里插入代码片`

[root@host51 ~]# cd mha-soft-student

[root@host51 ~]# yum –y install perl-* //安装共享的perl软件包

2)配置数据库服务器192.168.4.52

[root@host52 ~]# yum  -y  install   perl-*  //安装系统自带的perl软件包
[root@host52 ~]#  cd  mha-soft-student      
[root@host52 ~]#  yum  –y  install  perl-*  //安装共享的perl软件包[root@localhost 

3)配置数据库服务器192.168.4.53

[root@host53 ~]# yum -y install perl-* //安装系统自带的perl软件包

[root@host53 ~]# cd mha-soft-student

[root@host53 ~]# yum –y install perl-* //安装共享的perl软件包

4)配置管理服务器192.168.4.57

[root@mgm57 ~]# yum -y install perl-* //安装系统自带的perl软件包

[root@mgm57 ~]# cd mha-soft-student

[root@mgm57 ~]# yum –y install perl-* //安装共享的perl软件包

步骤三: 配置MySQL一主多从结构

1)配置主服务器192.168.4.51

[root@host51 ~]# vim /etc/my.cnf
[mysqld]
log-bin=master51 //日志名
server_id=51 //指定server_id
:wq
[root@host51 ~]# systemctl  restart  mysqld
[root@host51 ~]# mysql  -uroot  -p123qqq…A
    mysql> grant  replication slave  on  *.*  to repluser@"%"  identified by “123qqq…A"; //添加从服务器同步数据连接用户
mysql> show master status; //查看日志信息
mysql: [Warning] Using a password on the command line interface can be insecure.
+-----------------+----------+--------------+------------------+-------------------+
| File            | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------+----------+--------------+------------------+-------------------+
| master51.000001 |     441 |              |                  |                   |
+-----------------+----------+--------------+------------------+-------------------+
[root@host51 ~]#

2)配置从服务器192.168.4.52

[root@host52 ~]# vim /etc/my.cnf

[mysqld]

server_id=52 //指定server_id

:wq

[root@host52 ~]# systemctl restart mysqld //重启数据库服务

[root@host52 ~]# mysql -uroot –p123qqq…A //数据库管理员登录

mysql> change master to //指定主服务器信息

master_host=“192.168.4.51”, //IP地址

master_user=“repluser”, //授权用户

master_password=“123qqq…A”, //授权用户密码

master_log_file=“master51.000001”, //binlog日志

master_log_pos=441; //偏移量

mysql> start slave; //启动slave进程

mysql> exit ; //断开连接

[root@host52 ~]# mysql -uroot –p123qqq…A –e “show slave status\G” | grep 192.168.4.51

Master_Host: 192.168.4.51 //主服务器Ip地址

[root@host52 ~]# mysql -uroot –p123qqq…A –e “show slave status\G” | grep –i yes

Slave_IO_Running: Yes //I0线程正常

Slave_SQL_Running: Yes //SQL线程正常

3)配置从服务器192.168.4.53

[root@host53 ~]# vim /etc/my.cnf

[mysqld]

server_id=53 //指定server_id

:wq

[root@host53 ~]# systemctl restart mysqld //重启数据库服务

[root@host53 ~]# mysql -uroot –p123qqq…A //数据库管理员登录

mysql> change master to //指定主服务器信息

master_host=“192.168.4.51”, //IP地址

master_user=“repluser”, //授权用户

master_password=“123qqq…A”, //授权用户密码

master_log_file=“master51.000001”, //binlog日志

master_log_pos=441; //偏移量

mysql> start slave; //启动slave进程

mysql> exit ; //断开连接

[root@host53 ~]# mysql -uroot –p123qqq…A –e “show slave status\G” | grep 192.168.4.51

Master_Host: 192.168.4.51 //主服务器Ip地址

[root@host53 ~]# mysql -uroot –p123qqq…A –e “show slave status\G” | grep –i yes

Slave_IO_Running: Yes //I0线程正常

Slave_SQL_Running: Yes //SQL线程正常
2 案例2:部署MHA集群
2.1 问题

配置管理节点
配置数据节点

2.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:配置管理节点

1)安装软件

[root@mgm57 ~]# cd mha-soft-student/
[root@mgm57 mha-soft-student]#
[root@mgm57 mha-soft-student]# rpm -ivh  mha4mysql-node-0.56-0.el6.noarch.rpm//安装mha-node软件包
准备中...                          ################################# [100%]
正在升级/安装...
   1:mha4mysql-node-0.56-0.el6        ################################# [100%]
[root@mgm57 mha-soft-student]#
[root@mgm57 mha-soft-student]# rpm -qa | grep  mha //查看是否安装成功
mha4mysql-node-0.56-0.el6.noarch
[root@mgm57 mha-soft-student]#
[root@mgm57 mha-soft-student]# tar -zxvf mha4mysql-manager-0.56.tar.gz //解压mha-manager软件包
mha4mysql-manager-0.56/
mha4mysql-manager-0.56/debian/
mha4mysql-manager-0.56/debian/control
mha4mysql-manager-0.56/debian/copyright
……
……
[root@mgm57 mha-soft-student]# ls  
app1.cnf            mha4mysql-manager-0.56        
mha4mysql-node-0.56-0.el6.noarch.rpm
master_ip_failover  mha4mysql-manager-0.56.tar.gz
[root@mgm57 mha-soft-student]# cd mha4mysql-manager-0.56  //进入源码目录
[root@mgm57 mha4mysql-manager-0.56]# ls //查看文件列表
AUTHORS  COPYING  inc  Makefile.PL  META.yml  rpm      t
bin      debian   lib  MANIFEST     README    samples  tests
[root@mgm57 mha4mysql-manager-0.56]#
[root@mgm57 mha4mysql-manager-0.56]# perl Makefile.PL //配置
*** Module::AutoInstall version 1.03
*** Checking for Perl dependencies...
[Core Features]
- DBI                   ...loaded. (1.627)
- DBD::mysql            ...loaded. (4.023)
- Time::HiRes           ...loaded. (1.9725)
- Config::Tiny          ...loaded. (2.14)
- Log::Dispatch         ...loaded. (2.41)
- Parallel::ForkManager ...loaded. (1.18)
- MHA::NodeConst        ...loaded. (0.56)
*** Module::AutoInstall configuration finished.
Checking if your kit is complete...
Looks good
Writing Makefile for mha4mysql::manager
Writing MYMETA.yml and MYMETA.json
[root@mgm57 mha4mysql-manager-0.56]#  make //编译
[root@mgm57 mha4mysql-manager-0.56]#  make install //安装
[root@mgm57 mha4mysql-manager-0.56]# ls /root/perl5/bin  //查看安装的命令
masterha_check_repl    masterha_conf_host       masterha_master_switch
masterha_check_ssh     masterha_manager         masterha_secondary_check
masterha_check_status  masterha_master_monitor  masterha_stop

2)编辑主配置文件

[root@mgm57 ~ ]#  mkdir  /etc/mha  //创建工作目录
[root@mgm57 ~ ]#  cp mha4mysql-manager-0.56/sample/conf/app1.cnf /etc/mha/ //拷贝模板文件
[root@mgm57 ~ ]#  vim /etc/mha/app1.cnf   //编辑主配置文件
     [server default]     //管理服务默认配置
                manager_workdir=/etc/mha    //工作目录
                manager_log=/etc/mha/manager.log   //日志文件
                master_ip_failover_script=/etc/mha/master_ip_failover //故障切换脚本
                 ssh_user=root  //访问ssh服务用户
                 ssh_port=22    //ssh服务端口
                 repl_user=repluser           //主服务器数据同步授权用户
                 repl_password=123qqq…A    //密码
                 user=root                   //监控用户
                 password=123qqq…A               //密码
        [server1]   //指定第1台数据库服务器
hostname=192.168.4.51    //服务器ip地址
port=3306                //服务端口
candidate_master=1               //竞选主服务器
[server2]  //指定第2台数据库服务器
hostname=192.168.4.52
port=3306
candidate_master=1  
            
[server3]  //指定第3台数据库服务器
hostname=192.168.4.53
port=3306
candidate_master=1
:wq

3)创建故障切换脚本

[root@mgm57 ~]# cp mha-soft-student/master_ip_failover /etc/mha/
[root@mgm57 ~]# vim +35 /etc/mha/master_ip_failover
my $vip = '192.168.4.100/24';  # Virtual IP  //定义VIP地址
my $key = "1"; //定义变量$key
my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip"; //部署vip地址命令
my $ssh_stop_vip = "/sbin/ifconfig eth0:$key down"; //释放vip地址命令
:wq
[root@mgm57 ~]# chmod +x  /etc/mha/master_ip_failover //给脚本加执行权限

4)在当前主服务器部署vip地址

[root@host51 ~]# ifconfig  eth0:1  //部署之前查看 
eth0:1: flags=4163  mtu 1500
        ether 52:54:00:d8:10:d7  txqueuelen 1000  (Ethernet)
[root@host51 ~]# ifconfig  eth0:1  192.168.4.100  //部署vip地址
[root@host51 ~]# ifconfig  eth0:1 //部署后查看
eth0:1: flags=4163  mtu 1500
        inet 192.168.4.100  netmask 255.255.255.0  broadcast 192.168.4.255
        ether 52:54:00:d8:10:d7  txqueuelen 1000  (Ethernet)

步骤二:配置数据节点

1)在所有数据库服务器上,安装mha-node软件包

]# cd /root/mha-soft-student/
]#  rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:mha4mysql-node-0.56-0.el6        ################################# [100%]

2)在所有数据服务器上添加监控用户

可以只在host51主机执行授权命令,host52和host53 会自动同步授权

]# mysql –uroot –p密码
mysql> grant all on  *.*  to root@"%" identified by "123qqq...A";
mysql> exit;

3)在2台从服务器上添加,数据同步连接用户

在从服务器host52添加用户

[root@host52]# mysql –uroot –p密码
mysql> grant replication slave on  *.*  to repluser@"%" identified by "123qqq...A";
mysql> exit;

在从服务器host53添加用户

[root@host53]# mysql –uroot –p密码
mysql> grant replication slave on  *.*  to repluser@"%" identified by "123qqq...A";
mysql> exit;

4)修改数据库服务运行参数

修改主服务器host51

[root@host51 ~]# vim /etc/my.cnf
[mysqld]
plugin-load="rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" //加载模块
rpl_semi_sync_master_enabled=1  //启用master模块
rpl_semi_sync_slave_enabled=1     //启用slave模块
relay_log_purge=0   //禁止自动删除中继日志文件
:wq
[root@host51 ~]#  systemctl  restart  mysqld  //重启服务

修改从服务器host52

[root@host52 ~]# vim /etc/my.cnf
[mysqld]
log-bin=master52
plugin-load="rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" //加载模块
rpl_semi_sync_master_enabled=1  //启用master模块
rpl_semi_sync_slave_enabled=1     //启用slave模块
relay_log_purge=0   //禁止自动删除中继日志文件
:wq
[root@host52 ~]#  systemctl  restart  mysqld  //重启服务

修改从服务器host53

[root@host53 ~]# vim /etc/my.cnf

[mysqld]

log-bin=master53

plugin-load=“rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so” //加载模块

rpl_semi_sync_master_enabled=1 //启用master模块

rpl_semi_sync_slave_enabled=1 //启用slave模块

relay_log_purge=0 //禁止自动删除中继日志文件

:wq

[root@host53 ~]# systemctl restart mysqld //重启服务

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