不以物喜,不以己悲.
分类: LINUX
2013-10-14 12:11:35
有些小地方需要注意,标记一下。
环境:centos5.6 keepalived-1.2.4 ipvsadm-1.26 libnl-1.1.4
自带的libnl版本太低,如果已经安装请卸载,再安装libnl-1.1,make过程中可能会报错“route/link/vlan.c:51: error: 'VLAN_FLAG_REORDER_HDR'....",这时请修改libnl-1.1.4/lib/route/link/vlan.c:添加以下三行后make即可。
#ifndef VLAN_FLAG_REORDER_HDR
#define VLAN_FLAG_REORDER_HDR 0x01
#endif
编译安装libnl后,再安装ipvsadm,最后安装ipvsadm。
环境:centos6.x keepalived-1.2.4 ipvsadm-1.26
必须先安装自带的openssh、libnl*、popt*,再编译安装keepalived、ipvsadmin.
centos5.6/centos6安装完成后的配置是一样的:
cd /usr/local/etc/
cp -r keepalived /etc
cp sysconfig/keepalived /etc/sysconfig
cp rc.d/init.d/keepalived /etc/init.d
cp /usr/local/sbin/keepalived /sbin
编辑/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_TOIT !router_id 随便给,但如果还有一台做高可用,则两台的router_id一致。
}
vrrp_instance VI_1 {
state MASTER !另一台为BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 100
advert_int 5
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.19.195
}
}
vrrp_instance VI_2 { !如果是DR模式,这一段就不用了。
state MASTER !另一台为BACKUP
interface eth1
lvs_sync_daemon_inteface eth1
virtual_router_id 52
priority 100
advert_int 5
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.190.254
}
}
virtual_server 192.168.19.195 80 {
delay_loop 6
lb_algo rr
lb_kind NAT !根据网络架构和实际连接数选NAT还是DR,如果是DR,可以用Linux虚拟机环境实现,而NAT可能不行。
persistence_timeout 60
protocol TCP
real_server 192.168.190.192 80 {
weight 100
TCP_CHECK { !一定要注意"TCP_CHECK"和"{"之间要有空格
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.190.193 80 {
weight 100
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
配置完成后运行:service keepalived start
ipvsadm不需要任何配置。
直接运行ipvsadm应该可以看到online的realserver列表,否则请检查keepalived.conf.