IPVS TUN +keepalived 配置

环境:
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




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值