SUSE 12 環境安裝keepalived及遇到的問題 (0penStack平臺下虛機)
SUSE 12 環境安裝keepalived及遇到的問題 (0penStack平臺下虛機)
1、專案要求需做mysql高可用叢集,最終選擇的mysql+keepalived的方式實現,此文件只介紹keepalived安裝及遇到的問題。
2、提前準備好安裝包 :keepalived-2.0.7.tar.gz
安裝keepalived必須先安裝好各依賴包zypper install -y libnfnetlink-devel zlib zlib-devel gcc gcc-c++ openssl openssl-devel openssh
zypper install -y libnl* ipvsadm (這兩個包必須安裝,因為keepalived是基於ipvsadm來實現的高可用的)
安裝完成後檢查ip_vs模組是否啟動 lsmod |grep ip_vs
3、解壓keepalived-2.0.7.tar.gz
tar -zxvf keepalived-2.0.7.tar.gz
cd keepalived-2.0.7
執行 ./configure --prefix=/usr/local/keepalived(指定安裝目錄-自定義) && make && make install
執行完成檢查有無報錯。
進入安裝目錄 修改配置檔案
4、啟動keepalived (本次是做的雙活,另一臺按如上操作再來一遍)
檢視日誌程序 檢查keepalived 是否正常啟動
5、本次安裝遇到的最大坑
兩臺keepalived無法做到自動切換,原因是此OpenStack下的虛擬機器mac地址無法自動解綁 ,當一臺keepalived宕機後虛擬IP依然繫結在當期虛擬機器網絡卡下。由於環境的侷限性我這邊的臨時解決方案是當另一臺keepalived監控到另外一臺無心跳後,執行 “ping 區域網閘道器或者其他可聯通伺服器IP地址 -I keepalived虛擬IP -c 3”
(意思是通過虛擬IP 短ping閘道器或區域網內機器三次,當虛擬平臺檢測到地址失效後解綁)從而另外一臺可繫結虛擬IP達到切換的目的,注意:此方法在切換時會丟1~2個包
下圖是我的keepalived配置
! Configuration File for keepalived global_defs { notification_email { [email protected] [email protected] [email protected] } notification_email_from [email protected] smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id joychat vrrp_skip_check_adv_addr # vrrp_strict # vrrp_garp_interval 0 # vrrp_gna_interval 0 } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 54 priority 100 advert_int 1 # nopreempt authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 虛擬-IP } notify_master "/data/keepalived/Ping.sh" } virtual_server 虛擬-IP 3306 { delay_loop 2 # lb_algo rr # lb_kind NAT persistence_timeout 60 protocol TCP real_server mysq-IP 3306 { weight 1 notify_down /data/keepalived/shutdown.sh TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_prot 3306 } } } 本人水平有限,望其他有更好方法的朋友留言探討!