Skip to content

Instantly share code, notes, and snippets.

@kenshinx
Last active June 13, 2018 11:47
Show Gist options
  • Save kenshinx/8403129 to your computer and use it in GitHub Desktop.
Save kenshinx/8403129 to your computer and use it in GitHub Desktop.
Keepalived + LVS configuration template. VIP: 123.125.22.90 Master: 123.125.22.97 Backup: 123.125.22.98 RealServer1: 123.125.22.99 RealServer2: 123.125.22.100 Loadbalance algorithm: wrr Loadbalance type: DR
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server mail.sina.com.cn
smtp_connect_timeout 30
router_id LVS_1
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 21
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass sinasec
}
virtual_ipaddress {
123.125.22.90
}
}
virtual_server 123.125.22.90 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
#persistence_timeout 50
protocol TCP
real_server 123.125.22.99 80 {
weight 10
TCP_CHECK {
connect_port 80
nb_get_retry 3
connect_timeout 3
}
}
real_server 123.125.22.100 80 {
weight 5
TCP_CHECK {
connect_port 80
nb_get_retry 3
connect_timeout 3
}
}
}
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server mail.sina.com.cn
smtp_connect_timeout 30
router_id LVS_2L
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 21
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass sinasec
}
virtual_ipaddress {
123.125.22.90
}
}
virtual_server 123.125.22.90 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
#persistence_timeout 50
protocol TCP
real_server 123.125.22.99 80 {
weight 10
TCP_CHECK {
connect_port 80
nb_get_retry 3
connect_timeout 3
}
}
real_server 123.125.22.100 80 {
weight 5
TCP_CHECK {
connect_port 80
nb_get_retry 3
connect_timeout 3
}
}
}
#!/bin/bash
#description: Config realserver
VIP=123.125.22.90
/etc/rc.d/init.d/functions
case "$1" in
start)
/sbin/ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP
/sbin/route add -host $VIP dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p >/dev/null 2>&1
echo "RealServer Start OK"
;;
stop)
/sbin/ifconfig lo:0 down
/sbin/route del $VIP >/dev/null 2>&1
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "RealServer Stoped"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
@sunnoy
Copy link

sunnoy commented Jun 13, 2018

so cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment