分类:
2010-01-07 10:56:01
#sysctl –p
登陆real server 服务器配置keepalived
#vi /etc/keepalived/keepalived.conf
内容如下:
主服务器的配置:
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_pass 1111
}
virtual_ipaddress {
192.168.1.100
}
notify_master /opt/sbin/master.sh
notify_backup /opt/sbin/backup.sh
}
virtual_server 219.224.99.19 80 {
delay_loop 6
lb_algo rr
! lb_kind NAT
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.1.10 80 {
weight 1
TCP_CHECK {
connect_timeout 3
}
}
real_server 192.168.1.11 80 {
weight 3
TCP_CHECK {
connect_timeout 3
}
}
}
从服务器的配置:
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_pass 1111
}
virtual_ipaddress {
192.168.1.100
}
notify_master /opt/sbin/master.sh
notify_backup /opt/sbin/backup.sh
}
virtual_server 219.224.99.19 80 {
delay_loop 6
lb_algo rr
! lb_kind NAT
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.1.10 80 {
weight 1
TCP_CHECK {
connect_timeout 3
}
}
real_server 192.168.1.11 80 {
weight 3
TCP_CHECK {
connect_timeout 3
}
}
}
配置脚本:
#vi /opt/sbin/master.sh
加入:
#!/bin/sh
#master.sh
ip addr
ip addr add 192.168.1.100/32 dev eth0
#vi /opt/sbin/backup.sh
加入:
#!/bin/sh
#backup.sh
ip addr add 192.168.1.100/32 dev eth0
启动
#/etc/init.d/keepalived start
查看ipvsadm
#ipvsadm –ln
将node1的keeplive关闭,查看node2是否能将虚拟IP抢过去
将node2的WEB关闭,查看IPVS中是否自动将改节点删除
访问WEB,看是否是访问到不同的NODE
全局配置是对整个KEEPALIVED都起左右的配置,不管是否使用LVS。
每个配置块都是包含在{}中,包括2个部分全局定义(global definition)和静态路由定义(static ipaddress/routes)
全局定义定义keepalived的通讯机制和标识
global_defs
{
notification_email
{
admin@example.com
}
notification_email_from admin@example.com
smtp_server 127.0.0.1
stmp_connect_timeout 30
router_id my_hostname
}
说明:
notification_email 定义keepalived发生切换是,发送邮件通知的对象,可以多个,每个一行
smtp_server SMTP服务器地址
admin@example.com 发送邮件地址
router_id 定义运行keepalived服务器的标识
静态地址和路由定义,定义的地址是不会随VRRPD定义的地址变化而变化的,虚拟IP是变化的。一般需要在realserver上定义。
static_ipaddress
{
192.168.1.1/24 brd + dev eth0 scope global
...
}
static_routes
{
src $SRC_IP to $DST_IP dev $SRC_DEVICE
...
src $SRC_IP to $DST_IP via $GW dev $SRC_DEVICE
}
说明:
每一行设置一个IP ,使用的是linux下IP命令,上面的static_ipaddress命令等同与ip addr add 192.168.1.1/32 dev eth0
静态路由设置将哪来的IP从哪返回
VRRPD配置包括2部分,同步组和实例。
同步组是用于当一个服务器有2个网段,比如内网和外网,分别有1个实例,当内网出现故障是,keepalived做检查发现外网没问题,不会发生切换。同步组就是将内外网放到一个组中,不管哪出问题了都进行切换。
vrrp_sync_group VG_1 {
group {
inside_network # 这里是实例(比如VG_1)
outside_network
…
}
notify_master /path/to/to_master.sh
notify_backup /path_to/to_backup.sh
notify_fault "/path/fault.sh VG_1"
notify /path/to/notify.sh
smtp_alert
}