1、摆设规划
角色IP主机名server-id功能备注MHA_Manager192.168.6.141mha—管理节点MHA_Node_Master192.168.6.142master10数据节点写MHA_Node_Slave1192.168.6.143slave120数据节点读MHA_Node_Slave2192.168.6.144slave230数据节点读 2、系统和软件版本
系统版本MySQL版本MHA版本CentOS 7.6MySQL-5.7.31mha4mysql-manager-0.57 mha4mysql-node-0.57 3、系统环境初始化
第一步:克隆先前建好的最小化捏造机,也可以新建按下面的步骤
起首启动MASTER,然后在一次启动SLAVE1、SLAVE2以及MHA
第二步:更改计算机的主机名称
- # hostnamectl set-hostname master
- # su
- # hostnamectl set-hostname slave1
- # su
- # hostnamectl set-hostname slave2
- # su
- # hostnamectl set-hostname mha
- # su
复制代码 第三步:更改IP地址以及绑定主机名称及IP地址到/etc/hosts文件
- # vim /etc/sysconfig/network-scripts/ifcfg-ens33
- ...
- IPADDR=192.168.6.141、IPADDR=192.168.6.142、IPADDR=192.168.6.143、IPADDR=192.168.6.144
- ...
- # systemctl stop NetworkManager
- # systemctl disable NetworkManager
- # systemctl restart network
复制代码 使用mobaxterm毗连4台服务器,绑定IP地址与主机名称到/etc/hosts文件中
- # vim /etc/hosts
- 192.168.6.142 master
- 192.168.6.143 slave1
- 192.168.6.144 slave2
- 192.168.6.141 mha
复制代码 第四步:关闭防火墙与SELinux
- # systemctl stop firewalld
- # systemctl disable firewalld
- # setenforce 0
- # sed -i '/SELINUX=enforcing/cSELINUX=disabled' /etc/selinux/config
复制代码 第五步:配置YUM源
底子源
- # wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
- # yum clean all
- # yum makecache
复制代码 配置epel源
- # wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo
- # yum clean all
- # yum makecache
复制代码 配置本地自建仓库的yum源
① 把mha-yum拖入/soft/mha目录
- # mkdir -p /soft/mha
- 把mha-yum拖入/soft/mha目录
复制代码 ② 配置本地yum源,当我们使用yum时,可以自动找到mha-yum这个仓库目录
- # vim /etc/yum.repos.d/local.repo
- [mha]
- name=mha soft
- baseurl=file:///soft/mha/mha-yum
- enabled=1
- gpgcheck=0
复制代码 测试MHA依靠软件库的安装
- yum -y install perl-DBD-MySQL \
- perl-Config-Tiny \
- perl-Time-HiRes \
- perl-Mail-Sender \
- perl-Mail-Sendmail \
- perl-MIME-Base32 \
- perl-MIME-Charset \
- perl-MIME-EncWords \
- perl-Params-Classify \
- perl-Params-Validate.x86_64 \
- perl-Log-Dispatch \
- perl-Parallel-ForkManager \
- net-tools
复制代码 第六步:ntpdate时间同步
4、摆设MySQL主从复制环境
数据库安装位置:/usr/local/mysql
数据库的数据目录:/usr/local/mysql/data
套接字文件:/tmp/mysql.sock
端口设置:3306
配置文件位置:/usr/local/mysql/my.cnf(MySQL => 安装目录下 => /etc目录下)
☆ MASTER主服务器
第一步:上传软件到/root目录
第二步:使用脚本安装MySQL软件
- # vim mysql.sh
- #!/bin/bash
- yum install libaio -y
- tar -xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
- mv mysql-5.7.31-linux-glibc2.12-x86_64 /usr/local/mysql
- useradd -r -s /sbin/nologin mysql
- rm -rf /etc/my.cnf
- cd /usr/local/mysql
- mkdir mysql-files
- chown mysql:mysql mysql-files
- chmod 750 mysql-files
- bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql &> /root/password.txt
- bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
- cp support-files/mysql.server /etc/init.d/mysqld
- service mysqld start
- echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
- source /etc/profile
- # source mysql.sh
复制代码 第三步:设置MySQL密码
- cat /root/password.txt
- # mysql -p
- mysql> set password='123';
- mysql> flush privileges;
复制代码 第四步:进行安全初始化,两次no然后yes到底
- # mysql_secure_installation
复制代码 第五步:编写MASTER主机中my.cnf配置文件
- # vim /usr/local/mysql/my.cnf
- [mysqld]
- basedir=/usr/local/mysql
- datadir=/usr/local/mysql/data
- socket=/tmp/mysql.sock
- port=3306
- log-error=/usr/local/mysql/data/master.err
- log-bin=/usr/local/mysql/data/binlog
- server-id=10
- character_set_server=utf8mb4
- gtid-mode=on
- log-slave-updates=1
- enforce-gtid-consistency
- # service mysqld restart
复制代码 ☆ SLAVE1/SLAVE2从服务器
第一步:上传MySQL软件到服务器端
第二步:使用脚本安装MySQL,但是不需要进行初始化
- # vim mysql.sh
- #!/bin/bash
- yum install libaio -y
- tar -xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
- rm -rf /usr/local/mysql
- mv mysql-5.7.31-linux-glibc2.12-x86_64 /usr/local/mysql
- useradd -r -s /sbin/nologin mysql
- rm -rf /etc/my.cnf
- cd /usr/local/mysql
- mkdir mysql-files
- chown mysql:mysql mysql-files
- chmod 750 mysql-files
- cp support-files/mysql.server /etc/init.d/mysqld
- echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
- source /etc/profile
- # source mysql.sh
复制代码 第三步:使用rsync把MASTER服务器中的data数据目录同步到SLAVE1与SLAVE2
MASTER:
- # rm -rf /usr/local/mysql/data/auto.cnf
- # rsync -av /usr/local/mysql/data root@192.168.6.143:/usr/local/mysql/
- # rsync -av /usr/local/mysql/data root@192.168.6.144:/usr/local/mysql/
复制代码 第四步:给SLAVE1与SLAVE2配置my.cnf文件
SLAVE1:
- # vim /usr/local/mysql/my.cnf
- [mysqld]
- basedir=/usr/local/mysql
- datadir=/usr/local/mysql/data
- socket=/tmp/mysql.sock
- port=3306
- log-error=/usr/local/mysql/data/slave1.err
- log-bin=/usr/local/mysql/data/binlog
- relay-log=/usr/local/mysql/data/relaylog
- server-id=20
- character_set_server=utf8mb4
- gtid-mode=on
- log-slave-updates=1
- enforce-gtid-consistency
- skip-slave-start
复制代码 SLAVE2:
- # vim /usr/local/mysql/my.cnf
- [mysqld]
- basedir=/usr/local/mysql
- datadir=/usr/local/mysql/data
- socket=/tmp/mysql.sock
- port=3306
- log-error=/usr/local/mysql/data/slave2.err
- log-bin=/usr/local/mysql/data/binlog
- relay-log=/usr/local/mysql/data/relaylog
- server-id=30
- character_set_server=utf8mb4
- gtid-mode=on
- log-slave-updates=1
- enforce-gtid-consistency
- skip-slave-start
复制代码 配置完成后,启动MySQL软件
☆ 配置主从数据同步
第一步:在MASTER服务器中创建一个slave同步账号
- mysql> create user 'slave'@'192.168.6.%' identified by '123';
- mysql> grant replication slave on *.* to 'slave'@'192.168.6.%';
- mysql> flush privileges;
复制代码 第二步:创建一个mha账号(方便后期MHA监控主从同步状态)
- mysql> create user 'mha'@'192.168.6.141' identified by '123';
- mysql> grant all privileges on *.* to 'mha'@'192.168.6.141';
- mysql> flush privileges;
复制代码 第三步:在SLAVE1与SLAVE2中配置主从数据同步
- mysql> change master to master_host='192.168.6.142',master_port=3306,master_user='slave',master_password='123',master_auto_position=1;
- mysql> start slave;
- mysql> show slave status\G
- 看到
- Slave_IO_Running: Yes
- Slave_SQL_Running: Yes
- 即可
复制代码 5、MHA软件的安装
㈠ 差别节点安装软件
说明:在所有节点安装 mha-node软件包,在 mha 管理端再安装 mha-manager 软件包
- [root@mha ~]# yum –y install mha4mysql-node-0.57-0.el7.noarch.rpm
- [root@master ~]# yum –y install mha4mysql-node-0.57-0.el7.noarch.rpm
- [root@slave1 ~]# yum -y install mha4mysql-node-0.57-0.el7.noarch.rpm
- [root@slave2 ~]# yum –y install mha4mysql-node-0.57-0.el7.noarch.rpm
- rpm -ivh install mha4mysql-node-0.57-0.el7.noarch.rpm
- [root@mha ~]# yum –y install mha4mysql-manager-0.57-0.el7.noarch.rpm
复制代码 如果已经提前安装依靠软件,则各人可以使用rpm -ivh直接安装
㈡ 配置ssh互信(免密登录)
说明:
- 在生产环境中禁止root远程登陆服务器的,所以ssh免密码登陆要在admin用户下进行配置,这是处于安全角度思量出发。
- admin用户可以是恣意普通用户
- 该普通用户用于mha的管理节点远程访问mysql复制组中的所有主机,完成一些其他工作
第一步:在所有机器上创建一个普通账号admin,密码123
- # useradd admin
- # echo 123|passwd --stdin admin
复制代码 第二步:配置mha主机到其他主机的admin用户互信
- mha端:
- [root@mha ~]# su - admin
- [admin@mha ~]$ ssh-keygen -P "" -f ~/.ssh/id_rsa
- [admin@mha ~]$ cd .ssh/
- [admin@mha .ssh]$ ls
- id_rsa id_rsa.pub
- [admin@mha .ssh]$ mv id_rsa.pub authorized_keys
- [admin@mha .ssh]$ for i in 142 143 144;do scp -r ../.ssh/ 192.168.6.$i:~/;done
- 测试免密登录:
- [admin@mha .ssh]$ ssh 192.168.6.142
复制代码 把整个.ssh目录拷贝过去了是因为MHA的互信要求不但仅是MHA免密到MASTER、SLAVE1、SLAVE2,MASTER也要免密到MHA、SLAVE1、SLAVE2…
㈢ 配置admin用户的sudo权限
MASTER主机上:
- [root@master ~]# vim /etc/sudoers.d/admin
- #User_Alias 表示具有sudo权限的用户列表; Host_Alias表示主机的列表
- User_Alias MYSQL_USERS = admin
- #Runas_Alias 表示用户以什么身份登录
- Runas_Alias MYSQL_RUNAS = root
- #Cmnd_Alias 表示允许执行命令的列表(命令需要使用完整路径)
- Cmnd_Alias MYSQL_CMNDS = /sbin/ifconfig,/sbin/arping
- MYSQL_USERS ALL = (MYSQL_RUNAS) NOPASSWD: MYSQL_CMNDS
复制代码 把这个权限分发给SLAVE1与SLAVE2一份(当故障发生时,从服务器也可以自己设置VIP)
- [root@master ~]# for i in 143 144;do scp /etc/sudoers.d/admin 192.168.6.$i:/etc/sudoers.d/;done
复制代码 测试admin用户是否可以挂载VIP(只能在MASTER机器上挂载VIP)
- # su - admin
- [admin@master ~]$ sudo /sbin/ifconfig ens33:1 192.168.6.200 broadcast 192.168.6.255 netmask 255.255.255.0
- [admin@master ~]$ sudo /sbin/arping -fqc 5 -w 5 -I ens33 -s 192.168.6.200 -U 192.168.6.142
- [admin@master ~]$ ip a
- 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
- inet 127.0.0.1/8 scope host lo
- valid_lft forever preferred_lft forever
- inet6 ::1/128 scope host
- valid_lft forever preferred_lft forever
- 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
- link/ether 00:0c:29:92:42:06 brd ff:ff:ff:ff:ff:ff
- inet 192.168.6.142/24 brd 192.168.6.255 scope global ens33
- valid_lft forever preferred_lft forever
- inet 192.168.6.200/24 brd 192.168.6.255 scope global secondary ens33:1
- valid_lft forever preferred_lft forever
- inet6 fe80::20c:29ff:fe92:4206/64 scope link
- valid_lft forever preferred_lft forever
- 补充:
- arping:用来向局域网内的其它主机发送ARP请求的指令,可以用来测试局域网内的某个IP是否已被使用。
- -f:收到第一个响应包后退出。
- -q:quite模式,不显示输出。
- -c:发送指定的count个ARP REQUEST包后停止。如果指定了-w参数,则会等待相同数量的ARP REPLY包,直到超时为止。
- -w:指定一个超时时间,单位为秒,arping在到达指定时间后退出,无论期间发送或接收了多少包。在这种情况下,arping在发送完指定的count(-c)个包后并不会停止,而是等待到超时或发送的count个包都进行了回应后才会退出。
- -I:指定设备名,用来发送ARP REQUEST包的网络设备的名称。
- -D:重复地址探测模式,用来检测有没有IP地址冲突,如果没有IP冲突则返回0。
- -s:设置发送ARP包的IP资源地址
- -U:无理由的(强制的)ARP模式去更新别的主机上的ARP CACHE列表中的本机的信息,不需要响应。
- -h:显示帮助页。
复制代码 ㈣ 创建mha相干配置文件
MHA服务器:创建工作目录
- [root@mha ~]# mkdir /etc/mha/
- [root@mha ~]# mkdir -p /data/mha/masterha/app1
- [root@mha ~]# chown -R admin. /data/mha
复制代码 创建mha局部配置文件:
解释标注的修改n根据自己环境修改,除了ip其他默认不改
- [root@mha ~]# vim /etc/mha/app1.conf
- [server default]
- # 设置监控用户和密码(修改1)
- user=mha
- password=123
- # 设置复制环境中的复制用户和密码(修改2)
- repl_user=slave
- repl_password=123
- # 设置ssh的登录用户名(修改3)
- ssh_user=admin
- # 设置监控主库,发送ping包的时间间隔,默认是3秒,尝试三次没有回应的时候自动进行failover
- ping_interval=3
- # 设置mgr的工作目录
- manager_workdir=/data/mha/masterha/app1
- # 设置mysql master保存binlog的目录,以便MHA可以找到master的二进制日志(修改4)
- master_binlog_dir=/usr/local/mysql/data
- # 设置master的pid文件(修改5)
- # 在master切换到root
- # cd /usr/local/mysql/
- # ll data/
- # 找到相应的pid
- master_pid_file=/usr/local/mysql/data/master.pid
- # 设置mysql master在发生切换时保存binlog的目录(在mysql master上创建这个目录)
- remote_workdir=/data/mysql/mha
- # 设置mgr日志文件(MHA遇到问题,主要看这个日志)
- manager_log=/data/mha/masterha/app1/app1-3306.log
- # MHA到master的监控之间出现问题,MHA Manager将会尝试从slave1和slave2登录到master上
- secondary_check_script=/usr/bin/masterha_secondary_check -s 192.168.6.143 -s 192.168.6.144 --user=admin --port=22 --master_host=192.168.6.142 --master_port=3306
- # 设置自动failover时候的切换脚本(故障发生时,自动挂载VIP到SLAVE1或SLAVE2)
- master_ip_failover_script="/etc/mha/master_ip_failover.sh 192.168.6.200 1"
- # 设置手动切换时候的切换脚本
- #master_ip_online_change_script="/etc/mha/master_ip_online_change.sh 192.168.6.200 1"
- # 设置故障发生后关闭故障主机脚本
- # shutdown_script="/etc/mha/power_manager"
- [server1]
- hostname=192.168.6.142
- port= 3306
- candidate_master=1
- [server2]
- hostname=192.168.6.143
- port= 3306
- candidate_master=1
- [server3]
- hostname=192.168.6.144
- port= 3306
- candidate_master=1
复制代码 ㈤ 上传相应脚本到/etc/mha目录,然后更改配置信息,授权
- 将master_ip_failover.sh拖到/etc/mha
- [root@mha ~]# ls /etc/mha/
- app1.conf master_ip_failover.sh
- 注意:脚本内容中要修改网卡名字和连接用户为admin
- my $vip = shift;
- my $interface = 'ens33'; 网卡名(38行)
- my $key = shift;
- ...
- sub stop_vip() {
- my $ssh_user = "admin"; 用户名(110行)
- print "=======$ssh_stop_vip==================\n";
- `ssh $ssh_user\@$orig_master_host " $ssh_stop_vip "`;
- }
- [root@mha ~]# chmod +x /etc/mha/master_ip_*
复制代码 6、检测SSH互信以及MySQL主从状态
MHA:
- # su - admin
- # 检测SSH互信
- [admin@mha ~]$ [admin@mha ~]$ masterha_check_ssh --conf=/etc/mha/app1.conf
- Tue Jul 16 16:16:54 2024 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
- Tue Jul 16 16:16:54 2024 - [info] Reading application default configuration from /etc/mha/app1.conf..
- Tue Jul 16 16:16:54 2024 - [info] Reading server configuration from /etc/mha/app1.conf..
- Tue Jul 16 16:16:54 2024 - [info] Starting SSH connection tests..
- Tue Jul 16 16:16:55 2024 - [debug]
- Tue Jul 16 16:16:54 2024 - [debug] Connecting via SSH from admin@192.168.6.142(192.168.6.142:22) to admin@192.168.6.143(192.168.6.143:22)..
- Warning: Permanently added '192.168.6.143' (ECDSA) to the list of known hosts.
- Tue Jul 16 16:16:55 2024 - [debug] ok.
- Tue Jul 16 16:16:55 2024 - [debug] Connecting via SSH from admin@192.168.6.142(192.168.6.142:22) to admin@192.168.6.144(192.168.6.144:22)..
- Warning: Permanently added '192.168.6.144' (ECDSA) to the list of known hosts.
- Tue Jul 16 16:16:55 2024 - [debug] ok.
- Tue Jul 16 16:16:55 2024 - [debug]
- Tue Jul 16 16:16:55 2024 - [debug] Connecting via SSH from admin@192.168.6.143(192.168.6.143:22) to admin@192.168.6.142(192.168.6.142:22)..
- Tue Jul 16 16:16:55 2024 - [debug] ok.
- Tue Jul 16 16:16:55 2024 - [debug] Connecting via SSH from admin@192.168.6.143(192.168.6.143:22) to admin@192.168.6.144(192.168.6.144:22)..
- Warning: Permanently added '192.168.6.144' (ECDSA) to the list of known hosts.
- Tue Jul 16 16:16:55 2024 - [debug] ok.
- Tue Jul 16 16:16:56 2024 - [debug]
- Tue Jul 16 16:16:55 2024 - [debug] Connecting via SSH from admin@192.168.6.144(192.168.6.144:22) to admin@192.168.6.142(192.168.6.142:22)..
- Tue Jul 16 16:16:56 2024 - [debug] ok.
- Tue Jul 16 16:16:56 2024 - [debug] Connecting via SSH from admin@192.168.6.144(192.168.6.144:22) to admin@192.168.6.143(192.168.6.143:22)..
- Tue Jul 16 16:16:56 2024 - [debug] ok.
- Tue Jul 16 16:16:56 2024 - [info] All SSH connection tests passed successfully.
- # 检测集群状态
- [admin@mha ~]$ masterha_check_repl --conf=/etc/mha/app1.conf
- Tue Jul 16 16:17:14 2024 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
- Tue Jul 16 16:17:14 2024 - [info] Reading application default configuration from /etc/mha/app1.conf..
- Tue Jul 16 16:17:14 2024 - [info] Reading server configuration from /etc/mha/app1.conf..
- Tue Jul 16 16:17:14 2024 - [info] MHA::MasterMonitor version 0.57.
- Tue Jul 16 16:17:15 2024 - [info] GTID failover mode = 1
- Tue Jul 16 16:17:15 2024 - [info] Dead Servers:
- Tue Jul 16 16:17:15 2024 - [info] Alive Servers:
- Tue Jul 16 16:17:15 2024 - [info] 192.168.6.142(192.168.6.142:3306)
- Tue Jul 16 16:17:15 2024 - [info] 192.168.6.143(192.168.6.143:3306)
- Tue Jul 16 16:17:15 2024 - [info] 192.168.6.144(192.168.6.144:3306)
- Tue Jul 16 16:17:15 2024 - [info] Alive Slaves:
- Tue Jul 16 16:17:15 2024 - [info] 192.168.6.143(192.168.6.143:3306) Version=5.7.31-log (oldest major version between slaves) log-bin:enabled
- Tue Jul 16 16:17:15 2024 - [info] GTID ON
- Tue Jul 16 16:17:15 2024 - [info] Replicating from 192.168.6.142(192.168.6.142:3306)
- Tue Jul 16 16:17:15 2024 - [info] Primary candidate for the new Master (candidate_master is set)
- Tue Jul 16 16:17:15 2024 - [info] 192.168.6.144(192.168.6.144:3306) Version=5.7.31-log (oldest major version between slaves) log-bin:enabled
- Tue Jul 16 16:17:15 2024 - [info] GTID ON
- Tue Jul 16 16:17:15 2024 - [info] Replicating from 192.168.6.142(192.168.6.142:3306)
- Tue Jul 16 16:17:15 2024 - [info] Primary candidate for the new Master (candidate_master is set)
- Tue Jul 16 16:17:15 2024 - [info] Current Alive Master: 192.168.6.142(192.168.6.142:3306)
- Tue Jul 16 16:17:15 2024 - [info] Checking slave configurations..
- Tue Jul 16 16:17:15 2024 - [info] read_only=1 is not set on slave 192.168.6.143(192.168.6.143:3306).
- Tue Jul 16 16:17:15 2024 - [info] read_only=1 is not set on slave 192.168.6.144(192.168.6.144:3306).
- Tue Jul 16 16:17:15 2024 - [info] Checking replication filtering settings..
- Tue Jul 16 16:17:15 2024 - [info] binlog_do_db= , binlog_ignore_db=
- Tue Jul 16 16:17:15 2024 - [info] Replication filtering check ok.
- Tue Jul 16 16:17:15 2024 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
- Tue Jul 16 16:17:15 2024 - [info] Checking SSH publickey authentication settings on the current master..
- Tue Jul 16 16:17:15 2024 - [info] HealthCheck: SSH to 192.168.6.142 is reachable.
- Tue Jul 16 16:17:15 2024 - [info]
- 192.168.6.142(192.168.6.142:3306) (current master)
- +--192.168.6.143(192.168.6.143:3306)
- +--192.168.6.144(192.168.6.144:3306)
- Tue Jul 16 16:17:15 2024 - [info] Checking replication health on 192.168.6.143..
- Tue Jul 16 16:17:15 2024 - [info] ok.
- Tue Jul 16 16:17:15 2024 - [info] Checking replication health on 192.168.6.144..
- Tue Jul 16 16:17:15 2024 - [info] ok.
- Tue Jul 16 16:17:15 2024 - [info] Checking master_ip_failover_script status:
- Tue Jul 16 16:17:15 2024 - [info] /etc/mha/master_ip_failover.sh 192.168.6.200 1 --command=status --ssh_user=admin --orig_master_host=192.168.6.142 --orig_master_ip=192.168.6.142 --orig_master_port=3306
- Checking the Status of the script.. OK
- Tue Jul 16 16:17:15 2024 - [info] OK.
- Tue Jul 16 16:17:15 2024 - [warning] shutdown_script is not defined.
- Tue Jul 16 16:17:15 2024 - [info] Got exit code 0 (Not master dead).
- MySQL Replication Health is OK.
复制代码 7、查抄MHA状态,然后运行MHA(监控开始)
MHA:
- [admin@mha ~]$ masterha_check_status --conf=/etc/mha/app1.conf
- app1 is stopped(2:NOT_RUNNING).
- 开启MHA Manager监控(关键,代表启动MHA):
- [admin@mha ~]$ nohup masterha_manager --conf=/etc/mha/app1.conf --remove_dead_master_conf --ignore_last_failover &
- 再次查看监控状态:
- [admin@mha ~]$ masterha_check_status --conf=/etc/mha/app1.conf
- app1 (pid:2357) is running(0:PING_OK), master:192.168.6.142
- 注意:
- 1. 如果正常,会显示”PING_OK ”,否则会显示”NOT_RUNNING ”,说明 MHA监控没有开启
- 2. 使用admin用户启动监控,否则会报权限拒绝
- 3. 手动停止监控命令:masterha_stop --conf=/etc/mha/app1.conf
复制代码 到此MHA配置完毕
自动Failover测试
1、在MASTER服务器安装测试工具
- [root@master ~]# yum -y install sysbench
复制代码 2、插入测试数据
- master服务器上创建测试库test
- mysql> create database test charset utf8mb4;
- Query OK, 1 row affected (0.17 sec)
- mysql> grant all on *.* to 'mha'@'localhost' identified by '123';
- Query OK, 0 rows affected (0.14 sec)
- mysql> flush privileges;
- Query OK, 0 rows affected (0.11 sec)
- mysql> exit
- Bye
- [root@master ~]# sysbench /usr/share/sysbench/oltp_read_only.lua \
- --mysql-host=192.168.6.142--mysql-port=3306 --mysql-user=mha \
- --mysql-password=123 --mysql-socket=/tmp/mysql.sock \
- --mysql-db=test --db-driver=mysql --tables=1 \
- --table-size=100000 --report-interval=10 --threads=128 --time=120 prepare
-
- mysql> use test;
- mysql> select count(*) from sbtest1;
- +----------+
- | count(*) |
- +----------+
- | 100000 |
- +----------+
- 1 row in set (0.01 sec)
复制代码 3、拍摄快照
MHA、MASTER、SLAVE1、SLAVE2
4、模拟MASTER服务器故障
MHA服务器:监控日志
- [root@mgr ~]# tail -f /data/mha/masterha/app1/app1-3306.log
复制代码 MASTER服务器:
MHA日志显示结果:
故障切换:
VIP漂移:
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |