共计 4250 个字符,预计需要花费 11 分钟才能阅读完成。
一、编译安装 keepalived-1.2.8
下载地址:http://www.keepalived.org/download.html
注意最新的不一定是最好的,所以选择 1.2.8
tar xf keepalived-1.2.8.tar.gz
cd keepalived-1.2.8
mkdir -p /data/soft/keepalived
./configure –prefix=/data/soft/keepalived
注意:编译安装之前,可能需要先安装 gcc 和一些额外的包,请自行解决make && make install
编译报错 1
../include/vrrp_ipaddress.h:32:27: error: linux/if_addr.h: No such file or directory
In file included from ../include/vrrp.h:31,
from ../include/smtp.h:34,
from smtp.c:27:
../include/vrrp_ipaddress.h:41: error: field‘ifa’has incomplete type
make2: * [smtp.o] Error 1
make2: Leaving directory `/root/keepalived-1.2.7/keepalived/core’
make1: [all] Error 1
make1: Leaving directory `/root/keepalived-1.2.7/keepalived’
make: ** [all] Error 2
原因及解决办法:
这是 kernel-headers 软件版本过低造成的yum -y install kernel-headers
问题解决
编译报错 2
make2: * [vrrp_ipaddress.o] Error 1
make2: Leaving directory `/data/soft/keepalived-1.2.9/keepalived/vrrp’
make1: [all] Error 1
make1: Leaving directory `/data/soft/keepalived-1.2.9/keepalived’
make: ** [all] Error 2
解决办法:
将编译 keepalived-1.2.9.tar.gz 改成编译 keepalived-1.2.8.tar.gz 即可
转移文件到正确的位置mkdir /etc/keepalived
pwd
/data/soft/keepalivedcp etc/keepalived/keepalived.conf /etc/keepalived/
cp etc/rc.d/init.d/keepalived /etc/init.d/
cp etc/sysconfig/keepalived /etc/sysconfig/
cp sbin/keepalived /usr/sbin/
chkconfig –add keepalived
service keepalived start
Starting keepalived: [OK]chkconfig –add keepalived
chkconfig keepalived on
Keepalived 的详细介绍:请点这里
Keepalived 的下载地址:请点这里
推荐阅读:
CentOS 6.3 下 Haproxy+Keepalived+Apache 配置笔记 http://www.linuxidc.com/Linux/2013-06/85598.htm
Haproxy + KeepAlived 实现 WEB 群集 on CentOS 6 http://www.linuxidc.com/Linux/2012-03/55672.htm
Keepalived+Haproxy 配置高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/56748.htm
Haproxy+Keepalived 构建高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/55880.htm
二、配置文件以及监控脚本
配置文件
# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from amos.lu@sky-mobi.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_nginx {
script “nohup /etc/keepalived/chk_nginx.sh 2> /root/error.log & &> /dev/null”
interval 20
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 200
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.18.5.10
}
track_script {
chk_nginx
}
}
监控脚本
# vim /etc/keepalived/chk_nginx.sh
#!/bin/bash
port=80
nc -z -w 10 localhost $port &> /dev/null
if [$? -ne 0];then
sleep 10
nc -z -w 10 localhost $port &> /dev/null
if [$? -ne 0];then
/etc/init.d/MySQLd restart &> /dev/null
sleep 10
nc -z -w 10 localhost $port &> /dev/null
if [$? -ne 0];then
/etc/init.d/keepalived stop
fi
fi
fi
注意监测端口连通性的时候,不能只用 netstat 看这个端口是否存在,有时候存在端口,却是无法连通的,所有要用 nc 命令检测。
主备节点做对应修改即可。
一、编译安装 keepalived-1.2.8
下载地址:http://www.keepalived.org/download.html
注意最新的不一定是最好的,所以选择 1.2.8
tar xf keepalived-1.2.8.tar.gz
cd keepalived-1.2.8
mkdir -p /data/soft/keepalived
./configure –prefix=/data/soft/keepalived
注意:编译安装之前,可能需要先安装 gcc 和一些额外的包,请自行解决make && make install
编译报错 1
../include/vrrp_ipaddress.h:32:27: error: linux/if_addr.h: No such file or directory
In file included from ../include/vrrp.h:31,
from ../include/smtp.h:34,
from smtp.c:27:
../include/vrrp_ipaddress.h:41: error: field‘ifa’has incomplete type
make2: * [smtp.o] Error 1
make2: Leaving directory `/root/keepalived-1.2.7/keepalived/core’
make1: [all] Error 1
make1: Leaving directory `/root/keepalived-1.2.7/keepalived’
make: ** [all] Error 2
原因及解决办法:
这是 kernel-headers 软件版本过低造成的yum -y install kernel-headers
问题解决
编译报错 2
make2: * [vrrp_ipaddress.o] Error 1
make2: Leaving directory `/data/soft/keepalived-1.2.9/keepalived/vrrp’
make1: [all] Error 1
make1: Leaving directory `/data/soft/keepalived-1.2.9/keepalived’
make: ** [all] Error 2
解决办法:
将编译 keepalived-1.2.9.tar.gz 改成编译 keepalived-1.2.8.tar.gz 即可
转移文件到正确的位置mkdir /etc/keepalived
pwd
/data/soft/keepalivedcp etc/keepalived/keepalived.conf /etc/keepalived/
cp etc/rc.d/init.d/keepalived /etc/init.d/
cp etc/sysconfig/keepalived /etc/sysconfig/
cp sbin/keepalived /usr/sbin/
chkconfig –add keepalived
service keepalived start
Starting keepalived: [OK]chkconfig –add keepalived
chkconfig keepalived on
Keepalived 的详细介绍:请点这里
Keepalived 的下载地址:请点这里
推荐阅读:
CentOS 6.3 下 Haproxy+Keepalived+Apache 配置笔记 http://www.linuxidc.com/Linux/2013-06/85598.htm
Haproxy + KeepAlived 实现 WEB 群集 on CentOS 6 http://www.linuxidc.com/Linux/2012-03/55672.htm
Keepalived+Haproxy 配置高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/56748.htm
Haproxy+Keepalived 构建高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/55880.htm