# vi /etc/sysctl.conf
# Useful for LVS loadbalancing on the same network net.ipv4.conf.all.arp_ignore=1 net.ipv4.conf.all.arp_announce=2 net.ipv4.conf.eth0.arp_ignore=1 net.ipv4.conf.eth0.arp_announce=2
* Debian
# vi /etc/network/interfaces
auto tunl0
iface tunl0 inet static
address 192.168.1.99 (<<< nouvelle vip créée)
netmask 255.255.255.255
broascast 192.168.1.255
# ifup tunl0
* Red-Hat
# vi /etc/sysconfig/network-scripts/ifcfg-tunl0 DEVICE=tunl0 IPADDR=192.168.1.99 NETMASK=255.255.255.255 BROADCAST=192.168.1.255 ONBOOT=yes TYPE=IPIP
# ifup tunl0
# ifconfig tunl0 tunl0 Link encap:IPIP Tunnel HWaddr inet addr:192.168.1.99 Mask:255.255.255.255 UP RUNNING NOARP MTU:1480 Metric:1 RX packets:273 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:11328 (11.0 KiB) TX bytes:0 (0.0 b)
# vi /etc/sysctl.conf # for LVS tun net.ipv4.ip_forward=1
# apt-get install keepalived
Ceci et le fichier de configuration du serveur LVS_1 (server MASTER) le serveur LVS_2 à le même fichier de configuration hormis "state MASTER" à changer par "state BACKUP"
# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
postmaster@your-domain
}
notification_email_from postmaster@your-domain
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_XXX
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state MASTER
interface eth0
garp_master_delay 10
smtp_alert
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.99
}
}
virtual_server 192.168.1.99 80 {
delay_loop 6
lb_algo rr
lb_kind TUN
persistence_timeout 600
protocol TCP
real_server 192.168.1.2 80 {
weight 100
TCP_CHECK {
connect_port 80
connect_timeout 3
}
}
real_server 192.168.1.3 80 {
weight 100
TCP_CHECK {
connect_port 80
connect_timeout 3
}
}
}
# ipvsadm -l IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.1.99:www rr persistent 600 -> 192.168.1.2:www Tunnel 100 0 0 -> 192.168.1.3:www Tunnel 100 0 0
# ipvsadm -Ln --stats IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Conns InPkts OutPkts InBytes OutBytes -> RemoteAddress:Port TCP 192.168.1.99:80 0 0 0 0 0 -> 192.168.1.2:80 0 0 0 0 0 -> 192.168.1.3:80 0 0 0 0 0