MySQL+Keepalived實驗指導
Keepalived+mysql 自動切換
專案環境:
VIP 192.168.246.100
mysql1 192.168.246.162 keepalived-master
mysql2 192.168.246.163 keepalived-salve
一、mysql 主主同步 (不使用共享儲存,資料儲存本地儲存)
二、安裝keepalived
三、keepalived 主備配置檔案
四、mysql狀態檢測指令碼/root/bin/keepalived_check_mysql.sh
五、測試及診斷
實施步驟:
一、mysql 主主同步
二、安裝keepalived---兩臺機器都操作
[root@mysql-keepalived-master ~]
[root@mysql-keepalived-slave ~]
三、keepalived 主備配置檔案
192.168.246.162 master配置
[root@mysql-keepalived-master ~]
[root@mysql-keepalived-master ~]
! Configuration File for keepalived
global_defs {
router_id master
}
vrrp_script check_run {
script "/etc/keepalived/keepalived_chech_mysql.sh"
interval 5
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 89
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.246.100/24
}
track_script {
check_run
}
}
slave 192.168.246.163 配置
[root@mysql-keepalived-slave ~]
[root@mysql-keepalived-slave ~]
! Configuration File for keepalived
global_defs {
router_id backup
}
vrrp_script check_run {
script "/etc/keepalived/keepalived_check_mysql.sh"
interval 5
}
vrrp_instance VI_1 {
state BACKUP
nopreempt
interface ens33
virtual_router_id 89
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.246.100/24
}
track_script {
check_run
}
}
四、mysql狀態檢測指令碼/root/keepalived_check_mysql.sh(兩臺MySQL同樣的指令碼)
版本一:簡單使用:
[root@mysql-keepalived-master ~]
/usr/bin/mysql -uroot -p'QianFeng@2019!' -e "show status" &>/dev/null
if [ $? -ne 0 ] ;then
systemctl stop keepalived
fi
[root@mysql-keepalived-master ~]
==========================================================================
兩邊均啟動keepalived
方式一:
[root@mysql-keepalived-master ~]
[root@mysql-keepalived-master ~]
方式二:
注意:在任意一臺機器作為客戶端。在測試的時候記得檢查mysql使用者的可不可以遠端登入。
MySQL+Keepalived實驗操作