分类: LINUX
2009-03-18 13:02:13
Keepalived
系统环境:
************************************************************
两台服务器都装了CentOS-5.2-x86_64系统,安装了Squid服务。
Virtual IP: 192.168.30.20
Squid1+Real Server 1: 网卡地址(eth0):192.168.30.12
Squid2+Real Server 2: 网卡地址(eth0):192.168.30.13
************************************************************
软件列表:
keepalived
openssl-devel
***************************************************************
配置:
配置基于高可用keepalived,确定LVS使用DR模式
1.安装配置keepalived
1.1安装
# yum install openssl-devel ;安装keepalived依赖软件
#ln -s /usr/src/kernels/2.6.18-128.1.10.el5-i686/ /usr/src/linux
;建立内核链接,编译keepalived支持lvs时需要
#tar zxvf keepalived-1.1.17.tar.gz
#cd keepalived-1.1.17
#./configure --prefix=/usr --sysconf=/etc
Keepalived configuration
------------------------
Keepalived version : 1.1.17
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lpopt -lssl -lcrypto
Use IPVS Framework : Yes ;注意编译时一定要支持lvs
IPVS sync daemon support : Yes
Use VRRP Framework : Yes
Use LinkWatch : No
Use Debug flags : No
#make
#make install
1.2编辑keepalived配置文件
#Vi /etc/keepalived/keepalived.conf
global_defs {
notification_email {
}
notification_email_from root@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER #备份服务器上将MASTER改为BACKUP
interface eth0 #HA监测网络接口
virtual_router_id 51 #主、备机的virtual_router_id必须相同
priority 100 #主、备机取不同的优先级,主机值较大,备份机值较小
advert_int 2 #VRRP Multicast广播周期秒数
authentication {
auth_type PASS #VRRP认证方式
auth_pass 1111 #VRRP口令字
}
virtual_ipaddress {
192.168.30.20 #VRRP HA虚拟地址
}
}
virtual_server 192.168.30.20 80 {
delay_loop 2 #每隔6秒查询realserver状态
lb_algo rr #lvs 算法
lb_kind DR #Direct Route
persistence_timeout 50 #同一IP的连接60秒内被分配到同一台realserver
protocol TCP #用TCP协议检查realserver状态
real_server 192.168.30.12 80 {
TCP_CHECK {
}
}
real_server 192.168.30.13 80 {
TCP_CHECK {
}
}
}
1.3 BACKUP服务器同上配置,先安装lvs再按装keepalived,仍后配置/etc/keepalived/keepalived.conf,只需将红色标示的部分改一下即可.
global_defs {
notification_email {
}
notification_email_from root@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP #备份服务器上将MASTER改为BACKUP
interface eth0 #HA监测网络接口
virtual_router_id 51 #主、备机的virtual_router_id必须相同
priority 99 #主、备机取不同的优先级,主机值较大,备份机值较小
advert_int 2 #VRRP Multicast广播周期秒数
authentication {
auth_type PASS #VRRP认证方式
auth_pass 1111 #VRRP口令字
}
virtual_ipaddress {
192.168.30.20 #VRRP HA虚拟地址
}
}
}
}
}
2. 配置虚地址: vi /etc/sysconfig/network-scripts/ifcfg-lo:0,
添加
DEVICE=lo:0
IPADDR=192.168.30.20
NETMASK=255.255.255.255
ONBOOT=yes
NAME=loopback
3. 关闭RealServer的ARP,
或者编辑/etc/sysctl.conf,修改系统变量
net.ipv4.conf.eth0.arp_ignore=1
net.ipv4.conf.eth0.arp_announce=2
net.ipv4.ip_forward = 1
#sysctl –p : 使配置生效
4. 启动keepalived 服务
#service httpd start
#/etc/init.d/keepalived start
5. 测试lvs服务是否正常
5.1通过浏览器访问是否正常
多次刷新浏览器,在主LVS上看连接数变化
5.2停止主LVS上的keepalived 看看备份keepalived是否正常接管服务