1. 程式人生 > >011.MySQL雙主多從+Keepalived配置

011.MySQL雙主多從+Keepalived配置

一 基礎環境

主機名 系統版本 MySQL版本 主機IP
Master01 CentOS 6.8 MySQL 5.6 172.24.8.10
Master02 CentOS 6.8 MySQL 5.6 172.24.8.11
VIP 172.24.8.12
Slave01 CentOS 6.8
MySQL 5.6 172.24.8.12
Slave02 CentOS 6.8 MySQL 5.6 172.24.8.13

二 實際部署

2.1 MySQL雙主+Keepalived高可用

略,具體參考《MySQL雙主+Keepalived高可用》筆記。

2.2 所有Slave節點配置配置

  1 [[email protected] ~]# scp /etc/my.cnf [email protected]:/etc/
  2 [[email protected] ~]# scp /etc/my.cnf [email protected]:/etc/
  3 [[email protected] ~]# vi /etc/my.cnf
  4 [mysqld]
  5 ……
  6 server-id=3				#設定主伺服器Slave01的id
  7 [[email protected] ~]# vi /etc/my.cnf
  8 [mysqld]
  9 ……
 10 server-id=4				#設定主伺服器Slave02的id
  提示:從Master01將複製my.cnf至所有Slave節點,並修改相應的server id。

2.3 所有Slave節點建立賬號

  1 [[email protected] ~]# service mysqld start
  2 [[email protected] ~]# mysql -uroot -px120952576
  3 mysql> grant replication slave on *.* to 'repl_user'@'172.24.8.%' identified by 'x12345678';			#建立用於複製的賬號
  4 mysql> grant all privileges on *.* to 'root'@'172.24.8.%'  identified by 'x120952576' with grant option;
  5 mysql> flush privileges;
  提示:Slave02如上操作。

2.4 Slave節點配置Master01為主

  1 [[email protected] ~]# service mysqld restart
  2 [[email protected] ~]# mysql -uroot -px120952576
  3 mysql> change master to master_host='172.24.8.10',
  4     -> master_user='repl_user',
  5     -> master_password='x12345678',
  6     -> master_log_file='mysql-bin.000001',
  7     -> master_log_pos=120;
  8 mysql> start slave;
  9 mysql> show slave status\G			#檢視slave狀態