您好,登錄后才能下訂單哦!
10.1.1.174:23316 M1
10.1.1.237:23316 M2
[root@master1 ~]# cd /usr/local/src/
[root@master1 src]# wget https://www.keepalived.org/software/keepalived-2.0.17.tar.gz
[root@master1 src]# tar -xf keepalived-2.0.17.tar.gz
[root@master1 src]# cd keepalived-2.0.17
[root@master1 keepalived-2.0.17]# yum install openssl* libnl‐dev* gcc-c++
[root@master1 keepalived-2.0.17]# ./configure --prefix=/usr/local/keepalived
[root@master1 keepalived-2.0.17]# make
[root@master1 keepalived-2.0.17]# make install
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
echo "/etc/init.d/keepalived start" >> /etc/rc.local
mkdir -p /etc/keepalived/
mv /etc/keepalived/keepalived.conf /root/keepalived.conf.bak
M1:keepalive配置文件:
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
vrrp_script chk_mysql_port { #檢測mysql服務是否在運行。有很多方式,比如進程,用腳本檢測等等
script "/etc/keepalived/chk_mysql.sh" #這里通過腳本監測
interval 2 #腳本執行間隔,每2s檢測一次
weight -5 #腳本結果導致的優先級變更,檢測失敗(腳本返回非0)則優先級 -5
fall 2 #檢測連續2次失敗才算確定是真失敗。會用weight減少優先級(1-255之間)
rise 1 #檢測1次成功就算成功。但不修改優先級
}
vrrp_instance VI_1 {
state MASTER
interface ens192 #指定虛擬ip的網卡接口,改成你自己的 eth0或者其它什么的
# mcast_src_ip 10.1.1.174
virtual_router_id 51 #路由器標識,MASTER和BACKUP必須是一致的
priority 101 #定義優先級,數字越大,優先級越高,在同一個vrrp_instance下,MASTER的優先級必須大于BACKUP的優先級。這樣MASTER故障恢復后,就可以將VIP資源再次搶回來
unicast_src_ip 10.1.1.174 ##(本地IP地址)
unicast_peer {
10.1.1.237 ##(對端IP地址)此地址一定不能忘記
}
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.1.1.111
}
track_script {
chk_mysql_port
}
}
[root@crm-db01 ~]# cat /etc/keepalived/chk_mysql.sh #####注意可執行權限
#!/bin/bash
counter=$(netstat -na|grep "LISTEN"|grep "23316"|wc -l)
if [ "${counter}" -eq 0 ]; then
/etc/init.d/keepalived stop
fi
M2:keepalived配置文件:
[root@#localhost keepalived]# cat keepalived.conf
! Configuration File for keepalived
vrrp_script chk_mysql_port {
script "/etc/keepalived/chk_mysql.sh"
interval 2
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state BACKUP
interface ens192 #指定虛擬ip的網卡接口,改成你自己的 eth0或者其它什么的
#mcast_src_ip 10.1.1.237
virtual_router_id 51
priority 90
unicast_src_ip 10.1.1.237 ##(本地IP地址)
unicast_peer {
10.1.1.174 ##(對端IP地址)此地址一定不能忘記
}
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.1.1.111
}
track_script {
chk_mysql_port
}
}
[root@#localhost keepalived]# cat chk_mysql.sh #####注意可執行權限
#!/bin/bash
counter=$(netstat -na|grep "LISTEN"|grep "23316"|wc -l)
if [ "${counter}" -eq 0 ]; then
/etc/init.d/keepalived stop
fi
啟動keepalived服務
[root@master1 ~]# /etc/init.d/keepalived start
常用命令:
/etc/init.d/keepalived restart|start|stop
/etc/init.d/mysqld restart|start|stop
查看keepalive狀態:
systemctl status keepalived.service
查看日志:
tail -f /var/log/messages
1.啟動兩個keepalived ,兩邊都有VIP。
我這個配置文件已經修改過,應該不會出現這個情況。
2.VIP起來后,無法通過VIP訪問MySQL數據庫。
關閉防火墻或者開放相關端口。
查看你的MySQL配置文件,看看有沒有這個參數#bind-address = 10.1.1.237,有的話注釋掉,重啟數據庫。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。