角色
|
所需ip
|
实现负载所需软件
|
操作
|
负载均衡器(MASTER)
|
接口ip、VIP
|
ipvsadm,keepalived
|
安装ipvsadm及keepalived
|
负载均衡器(BACKUP)
|
接口ip、VIP
|
ipvsadm,keepalived
|
安装ipvsadm及keepalived
|
真实服务器(server pool)
|
接口ip、VIP
|
Lvs 客户端配置脚本
|
按“6.1.2”节内容编写配置脚本
|
[root@huludao-2 ~]#
more /usr/local/bin/lvs_real
#!/bin/bash
#description : start realserver
VIP=125.38.38.64
/etc/rc.d/init.d/functions
case "$1" in
start)
echo " start LVS of REALServer"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
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
;;
stop)
/sbin/ifconfig lo:0 down
echo "close LVS Directorserver"
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 "Usage: $0 {start|stop}"
exit 1
esac
|
#writed by sery , contact [email protected]
#guration File for keepalived
#global define
global_defs {
router_id LVS_CNC_1
}
vrrp_sync_group VGM {
group {
VI_CACHE
}
}
################################################################
# vvrp_instance define #
################################################################
vrrp_instance VI_CACHE {
state MASTER
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 180
advert_int 5
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
125.38.38.64
}
}
##############################################################
# virtual machine setting #
##############################################################
# setting port 80 forward
virtual_server 125.38.38.64 80 {
delay_loop 6
lb_algo wlc
lb_kind DR
# persistence_timeout 20
protocol TCP
real_server 125.38.38.101 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 125.38.38.102 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 125.38.38.104 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 125.38.38.99 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
|
#writed by sery , contact [email protected]
#guration File for keepalived
#global define
global_defs {
router_id LVS_CNC_2
}
vrrp_sync_group VGM {
group {
VI_CACHE
}
}
################################################################
# vrrp_instance setting #
################################################################
vrrp_instance VI_CACHE {
state BACKUP
interface eth1
lvs_sync_daemon_inteface eth1
virtual_router_id 51
priority 150
advert_int 5
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
125.38.38.64
}
}
##############################################################
# virtual server setting #
##############################################################
# setting port 80 forward
virtual_server 125.38.28.64 80 {
delay_loop 6
lb_algo wlc
lb_kind DR
# persistence_timeout 50
protocol TCP
real_server 125.38.38.101 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 125.38.38.102 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 125.38.38.104 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 125.38.38.99 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
|
[root@hld081028-mk ~]# ipvsadm -lcn | grep 159.226.240.63
TCP 14:56 ESTABLISHED 159.226.240.63:39783 125.38.38.64:80 125.38.38.99:80
|
Jul 6 21:04:32 telcom-dl-1 Keepalived_vrrp: VRRP_Instance(VI_CACHE) Transition to MASTER STATE
Jul 6 21:04:32 telcom-dl-1 Keepalived_vrrp: VRRP_Group(VGM) Syncing instances to MASTER state
Jul 6 21:04:37 telcom-dl-1 Keepalived_vrrp: VRRP_Instance(VI_CACHE) Entering MASTER STATE
Jul 6 21:04:37 telcom-dl-1 Keepalived_vrrp: VRRP_Instance(VI_CACHE) setting protocol VIPs.
Jul 6 21:04:37 telcom-dl-1 Keepalived_vrrp: VRRP_Instance(VI_CACHE) Sending gratuitous ARPs on eth1 for 218.24.35.105
Jul 6 21:04:37 telcom-dl-1 Keepalived_vrrp: Netlink reflector reports IP 125.38.38.64 added
Jul 6 21:04:37 telcom-dl-1 Keepalived_healthcheckers: Netlink reflector reports IP 125.38.38.64 added
Jul 6 21:04:42 telcom-dl-1 Keepalived_vrrp: VRRP_Instance(VI_CACHE) Sending gratuitous ARPs on eth1 for 125.38.36.64
|
Jul 6 21:18:12 telcom-dl-1 Keepalived_vrrp: VRRP_Instance(VI_CACHE) Received higher prio advert
Jul 6 21:18:12 telcom-dl-1 Keepalived_vrrp: VRRP_Instance(VI_CAHCE) Entering BACKUP STATE
Jul 6 21:18:12 telcom-dl-1 Keepalived_vrrp: VRRP_Instance(VI_CACHE) removing protocol VIPs.
Jul 6 21:18:12 telcom-dl-1 Keepalived_vrrp: VRRP_Group(VGM) Syncing instances to BACKUP state
Jul 6 21:18:12 telcom-dl-1 Keepalived_vrrp: Netlink reflector reports IP 125.38.38.64 removed
Jul 6 21:18:12 telcom-dl-1 Keepalived_healthcheckers: Netlink reflector reports IP 125.38.38.64 removed
|