当master服务器宕机,提升一个slave成为新的master

查询数据库节点最新的为新master
MariaDB [(none)]> show slave status\G


#修改设置文件并关闭read-only设置
[root@slave1 ~] vi /etc/my.cnf.d/mariadb-server.cnf
[mysql]
server-id=81
log-bin
read-only=off

[root@slave1 ~] systemctl restart mariadb.service

#消灭旧节点信息
MariaDB [(none)]> set global read_only=off;
MariaDB [(none)]> stop slave;
MariaDB [(none)]> reset slave all;
#备份新master的信息
[root@slave1 ~] mysqldump -A -F --single-transaction --master-data=1> /data/mariadb_backup_`date +%F_%T`.sql
[root@slave1 ~] scp /data/mariadb_backup_2020-10-18_15\:32\:22.sql 10.0.0.82:/data
#其他所有slave还原数据库,指向新master:
[root@slave2 ~] vi /data/mariadb_backup_2020-10-18_11\:33\:25.sql

CHANGE MASTER TO
  MASTER_HOST='10.0.0.80',
  MASTER_USER='abc',
  MASTER_PASSWORD='123456',
  MASTER_PORT=3306,
  MASTER_LOG_FILE='mariadb-bin.000002',
  MASTER_LOG_POS=389;

MariaDB [(none)]> stop slave;
MariaDB [(none)]> reset slave all;
ariaDB [(none)]> set sql_log_bin=off;
MariaDB [(none)]> source /data/mariadb_backup_2020-10-17_11\:33\:25.sql
MariaDB [(none)]> set sql_log_bin=on;
MariaDB [(none)]> start slave;