环境:
OS: fedora 14 虚拟机
一、 Director(Balancer) server
eth2 192.168.0.201/24
eth2:1 192.168.0.10 (VIP)
安装keepalived
yum install keepalived
配置脚本如下:
1 文件 /root/start_lvs_by_keepalived内容如下:
#!/bin/sh
ifconfig eth2 192.168.0.201
iptables --flush
modprobe ip_vs
ifconfig eth2:1 192.168.0.10 netmask 255.255.255.255 broadcast 192.168.0.255 up
echo "0" >/proc/sys/net/ipv4/ip_forward
echo "1" >/proc/sys/net/ipv4/conf/all/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/default/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/eth2/send_redirects
service keepalived start
2 文件 /etc/keepalived/keepalived.conf 内容如下
global_defs {
lvs_id lvs_app
}
vrrp_sync_groups VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth2
virtual_router_id 51
priority 100
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.0.10/24
}
}
virtual_server 192.168.0.10 9500 {
delay_loop 6
lb_algo wlc
lb_kind TUN
#nat_mask 255.255.255.0
persistence_timeout 10
protocol TCP
real_server 192.168.0.30 9500 {
weight 2
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 9500
}
}
real_server 192.168.0.31 9500 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 9500
}
}
}
二、 Real Cluster Server 1
eth3: 192.168.0.30/24
配置文件lvs_cfg内容如下:
#!/bin/sh
ifconfig eth3 192.168.0.30
iptables --flush
modprobe ipip
ip addr add 192.168.0.10/32 dev tunl0
ip link set tunl0 up
/sbin/ifconfig tunl0 192.168.0.10 broadcast 192.168.0.10 netmask 255.255.255.255 up
echo "0" >/proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
echo 0 > /proc/sys/net/ipv4/conf/tunl0/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
三、Real Cluster Server 2
eth3: 192.168.0.30/24
配置文件lvs_cfg内容如下:
#!/bin/sh
ifconfig eth3 192.168.0.31
iptables --flush
modprobe ipip
ip addr add 192.168.0.10/32 dev tunl0
ip link set tunl0 up
/sbin/ifconfig tunl0 192.168.0.10 broadcast 192.168.0.10 netmask 255.255.255.255 up
echo "0" >/proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
echo 0 > /proc/sys/net/ipv4/conf/tunl0/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
OS: fedora 14 虚拟机
一、 Director(Balancer) server
eth2 192.168.0.201/24
eth2:1 192.168.0.10 (VIP)
安装keepalived
yum install keepalived
配置脚本如下:
1 文件 /root/start_lvs_by_keepalived内容如下:
#!/bin/sh
ifconfig eth2 192.168.0.201
iptables --flush
modprobe ip_vs
ifconfig eth2:1 192.168.0.10 netmask 255.255.255.255 broadcast 192.168.0.255 up
echo "0" >/proc/sys/net/ipv4/ip_forward
echo "1" >/proc/sys/net/ipv4/conf/all/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/default/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/eth2/send_redirects
service keepalived start
2 文件 /etc/keepalived/keepalived.conf 内容如下
global_defs {
lvs_id lvs_app
}
vrrp_sync_groups VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth2
virtual_router_id 51
priority 100
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.0.10/24
}
}
virtual_server 192.168.0.10 9500 {
delay_loop 6
lb_algo wlc
lb_kind TUN
#nat_mask 255.255.255.0
persistence_timeout 10
protocol TCP
real_server 192.168.0.30 9500 {
weight 2
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 9500
}
}
real_server 192.168.0.31 9500 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 9500
}
}
}
二、 Real Cluster Server 1
eth3: 192.168.0.30/24
配置文件lvs_cfg内容如下:
#!/bin/sh
ifconfig eth3 192.168.0.30
iptables --flush
modprobe ipip
ip addr add 192.168.0.10/32 dev tunl0
ip link set tunl0 up
/sbin/ifconfig tunl0 192.168.0.10 broadcast 192.168.0.10 netmask 255.255.255.255 up
echo "0" >/proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
echo 0 > /proc/sys/net/ipv4/conf/tunl0/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
三、Real Cluster Server 2
eth3: 192.168.0.30/24
配置文件lvs_cfg内容如下:
#!/bin/sh
ifconfig eth3 192.168.0.31
iptables --flush
modprobe ipip
ip addr add 192.168.0.10/32 dev tunl0
ip link set tunl0 up
/sbin/ifconfig tunl0 192.168.0.10 broadcast 192.168.0.10 netmask 255.255.255.255 up
echo "0" >/proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
echo 0 > /proc/sys/net/ipv4/conf/tunl0/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter