yum install -y gcc gcc-c++ openssl openssl-develnginx
目前keepalived最新版本下載:
[root@rhel ~]#wget -c http://www.keepalived.org/software/keepalived-1.2.12.tar.gz
[root@rhel ~]# tar zxvf keepalived-1.2.12.tar.gz
[root@rhel ~]# cd keepalived-1.2.12
安裝編譯環境:
[root@rhel ~]# yum install -y gcc gcc-c++ openssl openssl-devel
1c++
//指定安裝路徑
[root@rhel keepalived-1.2.12]# ./configure --prefix=/usr/local/keepalived --sysconf=/etc bash
[root@rhel keepalived-1.2.12]# make && make install //安裝
將keepalived命令軟鏈接到/usr/bin下
[root@rhel keepalived-1.2.12]# ln -s /usr/local/keepalived/sbin/keepalived /usr/bin/keepalived測試
添加啓動腳本且方便用service keepalived start/stop/restart管理(若是沒有init.d/keepalived則從源碼目錄拷貝)
[root@rhel keepalived-1.2.12]# cp /keepalived/keepalived-2.0.8/keepalived/etc/init.d/keepalived /etc/init.d/keepalived
[root@rhel keepalived-1.2.12]# chmod 755 /etc/init.d/keepalived //添加執行權限
[root@rhel keepalived-1.2.12]# chkconfig keepalived on //開機啓動spa
修改/etc/init.d/keepalived中的程序路徑
# Source configuration file (we set KEEPALIVED_OPTIONS there)
. /etc/sysconfig/keepalivedrest
改成:
# Source configuration file (we set KEEPALIVED_OPTIONS there)
. /keepalived/keepalived-2.0.8/keepalived/etc/sysconfig/keepalivedrouter
默認狀況下,keepalived 會讀取 /etc/keepalived 下keepalived.conf 文件
若是沒有創建這個文件,keepalived也不會報錯,可是會發現,所建立的關於keepalived的相關參數根本就沒有生效。
[root@rhel keepalived-1.2.12]# mkdir /etc/keepalived
[root@rhel keepalived-1.2.12]# ln -s /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.confserver
keepalived.conf進程
! Configuration File for keepalivedip
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script Monitor_Nginx {
script "/monitor_nginx.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER
interface ens192
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
track_script {
Monitor_Nginx #(調用nginx進程檢測腳本)
}
virtual_ipaddress {
172.16.9.30
}
}
monitor_nginx.sh
啓動測試:
[root@rhel keepalived-1.2.12]# service keepalived restart
中止 keepalived: [肯定]
啓動 keepalived: [肯定]
安裝完成
service keepalived restart
service keepalived stop
service keepalived start
systemctl start keepalivedsystemctl restart keepalivedsystemctl stop keepalived