跳转至

29. MHA准备工作

1. 准备一主两从GTID环境(略)

#见第27篇文章

2. 设置从库relay的自动删除功能,从库设置只读

#slave1,slave2
set global relay_log_purge=0;  #建议3个节点都做
set global read_only=1;        #只在从库设置

vim /etc/my.cnf
[mysqld]
relay_log_purge=0    #建议3个节点都做
read_only=1         #只在从库设置

3. 配置关键程序软连接

ln -s /application/mysql/bin/mysqlbinlog  /usr/bin/mysqlbinlog
ln -s /application/mysql/bin/mysql  /usr/bin/mysql

#是否需要更改属主属组呢?

4. 配置各节点互信(郭老师自创快速互信法)

# 郭老师自创快速互信法
# master

#1. 删除之前的
rm -rf /root/.ssh

#2. 生成公私钥
ssh-keygen

#3. 公钥改名
cd /root/.ssh
mv id_rsa.pub   authorized_keys

#4. 远程复制发送公钥
scp -r /root/.ssh  192.168.178.161:/root/.ssh
scp -r /root/.ssh  192.168.178.162:/root/.ssh/
[root@151 ~]# 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:kSG7A1WryC1z842Go5SvI7JOb5J0qkmXi1MksIBk5VA root@151
The key's randomart image is:
+---[RSA 2048]----+
|o+oE  o.o        |
|= o  . o +       |
|o. .. . +        |
|.. o + o .       |
|  o = B S        |
| . o.= = o       |
|.o=oo o + .      |
|+*=ooo o         |
|*=++oo.          |
+----[SHA256]-----+
[root@151 ~]# cd /root/.ssh
[root@151 .ssh]# ls
id_rsa  id_rsa.pub
[root@151 .ssh]# mv id_rsa.pub   authorized_keys
[root@151 .ssh]# scp -r /root/.ssh  192.168.178.161:/root/.ssh/
The authenticity of host '192.168.178.161 (192.168.178.161)' can't be established.
ECDSA key fingerprint is SHA256:jkCd0jCyX4EpKrGzCawtEPBoWZB1hrbkOn/tnnX8xHY.
ECDSA key fingerprint is MD5:23:64:73:21:d4:3a:0a:c4:7b:e0:9d:37:73:fc:35:16.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.178.161' (ECDSA) to the list of known hosts.
root@192.168.178.161's password:
id_rsa                                        100% 1675     1.7MB/s   00:00
authorized_keys                               100%  390   618.3KB/s   00:00
known_hosts                                   100%  177   262.4KB/s   00:00
[root@151 .ssh]# scp -r /root/.ssh  192.168.178.162:/root/.ssh/
The authenticity of host '192.168.178.162 (192.168.178.162)' can't be established.
ECDSA key fingerprint is SHA256:Im67uqMIacSCgC/fBNcgS97gZ7e+s+3CZmhgK5bw5kE.
ECDSA key fingerprint is MD5:b8:c5:5a:2d:e7:66:c7:8e:c7:25:b3:63:30:0f:95:0a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.178.162' (ECDSA) to the list of known hosts.
root@192.168.178.162's password:
id_rsa                                        100% 1675     1.4MB/s   00:00
authorized_keys                               100%  390   398.1KB/s   00:00
known_hosts                                   100%  354   445.1KB/s   00:00
[root@151 .ssh]#

5. 各节点互信验证

ssh 192.168.178.151 date
ssh 192.168.178.161 date
ssh 192.168.178.162 date
#151
[root@151 .ssh]# ssh 192.168.178.151 date
The authenticity of host '192.168.178.151 (192.168.178.151)' can't be established.
ECDSA key fingerprint is SHA256:u0a2jp2ScsVePhcHkdHsZ5mgcm8siph4cQj5snJu/7g.
ECDSA key fingerprint is MD5:61:a0:76:e6:83:b0:4c:e6:99:3b:e3:f2:7a:c7:5d:77.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.178.151' (ECDSA) to the list of known hosts.
Thu Apr 29 06:04:45 CST 2021
[root@151 .ssh]#
[root@151 .ssh]# ssh 192.168.178.151 date
Thu Apr 29 06:04:51 CST 2021
[root@151 .ssh]# ssh 192.168.178.161 date
Wed Apr 28 22:27:10 CST 2021
[root@151 .ssh]# ssh 192.168.178.162 date
Wed Apr 28 22:27:12 CST 2021
[root@151 .ssh]#
#161
[root@161 ~]# ssh 192.168.178.151 date
The authenticity of host '192.168.178.151 (192.168.178.151)' can't be established.
ECDSA key fingerprint is SHA256:u0a2jp2ScsVePhcHkdHsZ5mgcm8siph4cQj5snJu/7g.
ECDSA key fingerprint is MD5:61:a0:76:e6:83:b0:4c:e6:99:3b:e3:f2:7a:c7:5d:77.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.178.151' (ECDSA) to the list of known hosts.
Thu Apr 29 06:04:58 CST 2021
[root@161 ~]#
[root@161 ~]#
[root@161 ~]#
[root@161 ~]# ssh 192.168.178.151 date
Thu Apr 29 06:05:23 CST 2021
[root@161 ~]# ssh 192.168.178.161 date
Wed Apr 28 22:27:43 CST 2021
[root@161 ~]# ssh 192.168.178.162 date
The authenticity of host '192.168.178.162 (192.168.178.162)' can't be established.
ECDSA key fingerprint is SHA256:Im67uqMIacSCgC/fBNcgS97gZ7e+s+3CZmhgK5bw5kE.
ECDSA key fingerprint is MD5:b8:c5:5a:2d:e7:66:c7:8e:c7:25:b3:63:30:0f:95:0a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.178.162' (ECDSA) to the list of known hosts.
Wed Apr 28 22:27:47 CST 2021
[root@161 ~]#
[root@161 ~]#
[root@161 ~]# ssh 192.168.178.151 date
Thu Apr 29 06:05:31 CST 2021
[root@161 ~]# ssh 192.168.178.161 date
Wed Apr 28 22:27:51 CST 2021
[root@161 ~]# ssh 192.168.178.162 date
Wed Apr 28 22:27:52 CST 2021
[root@161 ~]#
#162
[root@162 ~]# ssh 192.168.178.151 date
The authenticity of host '192.168.178.151 (192.168.178.151)' can't be established.
ECDSA key fingerprint is SHA256:u0a2jp2ScsVePhcHkdHsZ5mgcm8siph4cQj5snJu/7g.
ECDSA key fingerprint is MD5:61:a0:76:e6:83:b0:4c:e6:99:3b:e3:f2:7a:c7:5d:77.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.178.151' (ECDSA) to the list of known hosts.
Thu Apr 29 06:05:07 CST 2021
[root@162 ~]#
[root@162 ~]#
[root@162 ~]#
[root@162 ~]# ssh 192.168.178.151 date
Thu Apr 29 06:05:36 CST 2021
[root@162 ~]# ssh 192.168.178.161 date
Wed Apr 28 22:27:55 CST 2021
[root@162 ~]# ssh 192.168.178.162 date
Wed Apr 28 22:27:56 CST 2021

最后更新: 2022-02-20 08:44:07