wget http://www.keepalived.org/software/keepalived-1.2.9.tar.gz tar -xf keepalived-1.2.9.tar.gz mkdir /usr/local/keepalived cd ~/ keepalived-1.2.9 ./configure --prefix=/usr/local/keepalived/ make && make install cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/ chmod +x /etc/init.d/keepalived mkdir /etc/keepalived cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived3修改配置文件如下
[root@M128 ~]# vim /etc/keepalived/keepalived.conf global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server smtp.126.com # 郵件服務器地址 smtp_connect_timeout 30 # 連接超時時間 router_id LVS_Master } vrrp_script chk_http_port { script "/etc/keepalived/check_haproxy.sh" # haproxy運行檢測腳本[haproxy宕掉重啟haproxy服務] interval 5 # 腳本執行間隔 weight -5 # 執行腳本後優先級變更:5表示優先級+5;-5則表示優先級-5 } vrrp_instance VI_A { state MASTER # 主上此值為MASTER,從上為BACKUP interface eth0 virtual_router_id 50 # 此值主從必須一致 priority 100 advert_int 1 authentication { # authentication兩個參數值,主從也必須一致 auth_type PASS auth_pass yiban } track_script { chk_http_port } virtual_ipaddress { 192.168.78.220 } }
5啟動keepalived 確保網絡正常 service network restart (線上不要這麼做) /etc/init.d/keepalived start 查看結果 ip a