keepalived 解決系統單點問題
1 安裝
wget http://www.keepalived.org/software/keepalived-1.2.15.tar.gz
tar -zxvf keepalived-1.2.15.tar.gz
cd keepalived-1.2.15
./configure --sysconf=/etc/ --with-kernel-dir=/usr/src/kernels/2.6.32-573.8.1.el6.x86_64
常見三種錯誤:
錯誤1: 報錯*** WARNING - this build will not support IPVS with IPv6. Please install libnl/libnl-3 dev libraries to support IPv6 with IPVS.
執行: yum -y install libnl libnl-devel
錯誤2: 報錯 openssl not property
yum -y install openssl openssl-devel
錯誤3: configure: error: libnfnetlink headers missing
yum install -y libnfnetlink-devel
而後:
make && make install
ln -s /usr/local/sbin/keepalived /sbin/
#這一步很重要,不執行
配置檔案:
MASTER
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_MASTER
}
vrrp_script chk_http_port {
script "/etc/keepalived/check_nginx.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state BACKUP
nopreempt
interface eth1
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_http_port
}
virtual_ipaddress {
192.168.137.100
}
}
主要說明的幾點:
state 的數值,BACKUP MASTER 沒有區別的,決定是不是 master 是 priority ,這個越大,代表是 主
interface eth1 ,後面這個 eth1 必須是伺服器已經存在的,否則 新增失敗,是不是存在的 路由 使用命令
ip a 進行檢視:
service keepalived start, 進行啟動,啟動成功,ip a 檢視 eth1 下面可以看到多了一個 虛擬ip
從節點,只需將 許可權改小, priority 即可, 判斷 是否安裝成功,可以進行如下操作
主節點 service keepalived stop, 從節點 虛擬 ip 能否成功,如果主節點再啟動keepalived , 虛擬 ip 會再爭奪回來