1. 下载所需版本。
2.解压所需keepalived包
tar zxvf
keepalived*
3.编译包
./configure && make
&& make install
在编译过程中提示错误,解决办法:
1)提示 "!!! OpenSSL is not properly installed on your system. !!!
!!! Can not include OpenSSL headers files."
需要安装opendevel:yum -y install openssl-devel
2)提示 ”Keepalive popt libraries is required “
需要安装popt:wget
1.16
.tar.gz
3)如果configure就提示GCC NO
需要安装gcc : yum -y install gcc
4) 当编译提示如下:
Keepalived configuration
------------------------
Keepalived version : 1.2.2
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lpopt -lssl -lcrypto
Use IPVS Framework : No
IPVS sync daemon support : No
Use VRRP Framework : Yes
Use Debug flags : No
这两个出现NO,说明keepalived没有找到内核,可先查看/usr/src/kernels 目录下是否有文件,如没有可先yum -y install kernel-devel ,然后通过如下方式解决:
方法一:编译时可加入参数 --with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-i686/ 内核地址
方法二:由于keepalived编译时默认从/usr/src/linux这个位置找内核,所以可以建立一个链接,
ln -s /usr/src/kernels/2.6.18-164.el5-i686/ /usr/src/linux
4. 在lvs1和lvs2将keepalived配置成系统服务
1)#cp
/usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
2)#cp /usr/local/etc/sysconfig/keepalived
/etc/sysconfig/
3)#mkdir /etc/keepalived
4)#cp
/usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
5)#cp /usr/local/sbin/keepalived /usr/sbin/
6)#service keepalived start|stop
5.在lvs1和lvs2上修改keepalived配置文件
#vi /etc/keepalived/keepalived.conf //标红地方需要修改!
! Configuration File for keepalived
global_defs {
notification_email {
}
notification_email_from
smtp_server
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER //备份服务器设置为backup
interface eth0 //注意如果网卡不是eth0,一定要修改这个地方
virtual_router_id 51
priority 100 //备份服务器设置小于100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.1 // 虚拟IP地址,也就是LO:1的地址 ,如果有多个VIP,继续换行填写
}
}
virtual_server 192.168.1.1 80 {
delay_loop 6 //隔6秒查询realserver状态
lb_algo wrr //lvs算法
lb_kind DR //(Direct Route),可修改成NAT
persistence_timeout 60 //同一IP的连接60秒内被分配到同一台realserver
inhibit_on_failure //当web挂掉的时候,前面请求的用户,可以继续打开网页,但是后面的请求不会调度到挂掉的web上面。
protocol TCP //用TCP协议检查realserver状态
real_server 192.168.1.2 80 { //真实服务器地址
weight 1 //权重
TCP_CHECK {
connect_timeout 10 //10秒无响应超时
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.3 80 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
}
}
}
6.先设置LVS策略用ipvsadm查看,之后在启动keepalived。
相当有用的文档: keepalived权威指南.rar
阅读(1806) | 评论(0) | 转发(0) |