下載tar包mysql
./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/ \ 注意加內核 nginx
&&make && make installsql
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/shell
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/服務器
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/架構
cp -r /usr/local/keepalived/etc/keepalived/ /etc 將配置文件 CP可到/etcoop
架構 192.168.10.129 httpd服務器 連的VIP 192.168.10.128 真實IP 爲master 192.168.10.130 真實IP 爲bakcupspa
配置文件 VIP需跟本地IP同一網段且IP不曾使用3d
master 配置日誌
! Configuration File for keepalived
global_defs {
notification_email {
liu6630@qq.com
}
notification_email_from liu6630@qq.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 151
priority 100
advert_int 5
nopreempt
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
192.168.111.111
}
}
virtual_server 192.168.111.111 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.10.128 3306 {
weight 100
notify_down /root/shell/mysql_keepalived.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
BACK_UP 配置
! Configuration File for keepalived
global_defs {
notification_email {
liu6630@qq.com
}
notification_email_from liu6630@qq.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 151
priority 100
advert_int 5
nopreempt
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
192.168.111.111
}
}
virtual_server 192.168.111.111 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.10.130 3306 {
weight 100
notify_down /root/shell/mysql_keepalived.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
TCP_CHECK 模板只能 檢測本機端口 notify_down檢測到端口掛了執行 殺死keepalived 腳本
global_defs {
notification_email {
wgkgood@139.com
}
notification_email_from wgkgood@139.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_nginx {
script "/data/sh/nginx.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 151
priority 90
advert_int 5
authentication {
auth_type PASS
auth_pass 2222
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.111.188
}
}
用腳本檢測 腳本內容可爲
BACKMSG= `ps -C nginx --noheader |wc -l `
if [ $BACKMSG -eq 0 ];then
service keepalived stop
else
exit
fi
notify_master 腳本 放到VRRP實例
URL_CHECK
HTTP_GET
配置文件重啓keeeplived
需手動加載 modprobe ip_vs
排錯
1.編譯是否加了內核 沒加內核不會啓動檢測 加了
2配置文件是否在 /etc/keepalivde 下 cp -r /usr/local/keepalived/etc/keepalived/ /etc 最終配置文件/etc/keepalived/keepalived.cof
3是否加載modprobe ip_vs 未加載虛擬IP模塊 有VIP也不能 其餘服務也不能訪問VIP
4是否VIP與真實IP同一網段且無IP衝突
5VIP是否起來 能夠用 ip addr list 查看
6 virtual_router_id 同一集羣的keepalived的主、備機的virtual_router_id 必須相同,取值0-255 可是同一內網中不該有相同virtual_router_id的集羣
7 查看/var/messages日誌