一、实验环境
四台虚拟机
server1 :172.25.7.2 MHA的Manager
server2 :172.25.7.3 主机master
server3 :172.25.7.4 从机slave
server4 :172.25.7.5 从机slave
首先,后三台主机实验环境清空,重新初始化,
/etc/init.d/mysqld stop
cd /data/mysql
rm -rf *
mysqld --initialize --user=mysql
二、主从复制的配置
1.主机server2的配置
1.修改/etc/my.cnf文件
[root@server2 mysql]# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/data/mysql/mysql.sock
server-id=1
gtid_mode=ON
enforce-gtid-consistency=ON
default_authentication_plugin=mysql_native_password
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
2.初始化,
[root@server2 mysql]#/etc/init.d/mysqld stop
[root@server2 mysql]#pwd
/data/mysql
[root@server2 mysql]# rm -rf *
[root@server2 mysql]# ls
[root@server2 mysql]# mysqld --initialize --user=mysql #初始化
2020-08-22T01:52:16.382767Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.21) initializing of server in progress as process 28860
2020-08-22T01:52:16.392786Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-08-22T01:52:17.099404Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-08-22T01:52:18.708445Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 79!fv?KLFvy
[root@server2 mysql]# /etc/init.d/mysqld start #开启mysql
Starting MySQL.Logging to '/data/mysql/lue3.westos.com.err'.
SUCCESS!
3.登陆mysql数据库创建用户
[root@server2 mysql]# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set sql_log_bin=0;
Query OK, 0 rows affected (0.00 sec)
mysql> alter user root@localhost identified by 'westos'; #修改密码
Query OK, 0 rows affected (0.01 sec)
mysql> set sql_log_bin=1;
Query OK, 0 rows affected (0.00 sec)
mysql> create user repl@'%' identified by 'westos'; #创建用户
Query OK, 0 rows affected (0.01 sec)
mysql> grant replication slave on *.* to repl@'%'; #给权限
Query OK, 0 rows affected (0.01 sec)
mysql>
2.server3和server4从机的配置
1./etc/my.cnf文件的配置
[root@server3 ~]# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/data/mysql/mysql.sock
server-id=2 #server4的server_id改为3
gtid_mode=ON
enforce-gtid-consistency=ON
default_authentication_plugin=mysql_native_password
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
2.初始化
[root@server3 mysql]# /etc/init.d/mysqld stop
Shutting down MySQL.... SUCCESS!
[root@lue2 mysql]# vim /etc/my.cnf
[root@lue2 mysql]# pwd
/data/mysql
[root@server3 mysql]# rm -rf *
[root@server3 mysql]# ls
[root@server3 mysql]# ls
[root@server3 mysql]# mysqld --initialize --user=mysql
2020-08-22T01:57:03.950961Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.21) initializing of server in progress as process 5155
2020-08-22T01:57:03.961356Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-08-22T01:57:05.224378Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-08-22T01:57:06.818661Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: !SwlaLrKN7)y
[root@server3 mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/lue2.westos.com.err'.
. SUCCESS!
3.从库的配置
[root@server3 mysql]# mysql -p
E