lvs side deployment
1. ipvsadm
yum install ipvsadm
2. keepalived
yum install keepalived
3. vim /etc/keepalived/keepalived.conf, the test example is as follows
! Configuration File for keepalived
global_defs { notification_email { haha@test.com } router_id LVS_M }
vrrp_instance VI_1 { stateMASTER interface em1 virtual_router_id 99 priority 100 advert_int 1 smtp_alert authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { your_vip_1 your_vip_2 your_vip_3 } }
virtual_server your_vip_1 80{ delay_loop 6 lb_algo wlc lb_kind DR protocolTCP
real_server your_rs_1 80 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
real_server your_rs_2 80 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
real_server your_rs_3 80 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } } }
virtual_server your_vip_2 80{ delay_loop 6 lb_algo wlc lb_kind DR protocolTCP
real_server your_rs_1 80 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
real_server your_rs_2 80 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
real_server your_rs_3 80 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
}
virtual_server your_vip_3 80{ delay_loop 6 lb_algo wlc lb_kind DR protocolTCP
real_server your_rs_1 80 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
real_server your_rs_2 80 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
real_server your_rs_3 80 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
}
#https
virtual_server your_vip_1 443{ delay_loop 6 lb_algo wlc lb_kind DR protocolTCP
real_server your_rs1 443 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
real_server your_rs_2 443 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
real_server your_rs_3 443 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } } }
virtual_server your_vip_2 443{ delay_loop 6 lb_algo wlc lb_kind DR protocolTCP
real_server your_rs_1 443 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
real_server your_rs_2 443 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
real_server your_rs_3 443 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
}
virtual_server your_vip_3 443{ delay_loop 6 lb_algo wlc lb_kind DR protocolTCP
real_server your_rs_1 443 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
real_server your_rs_2 443 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
real_server your_rs_3 443 { weight 1 MISC_CHECK { misc_path "/opt/adminsh/check-realserver-health.sh" misc_timeout 5 } }
}
4. Deployment on the slave side is the same as on the master side. Only the router_id, state, and prority parameters need to be adjusted.
/sbin/iptables -A INPUT -p vrrp -j ACCEPT Add firewall rules
Deployment on the realserver side:
1. vim /etc/init.d/realserver
#!/bin/sh
BEGIN INIT INFO
Provides: lvs_realserver
Default-Start: 3 4 5
Default-Stop: 0 1 6
Short-Description: LVS real_server service scripts
Description: LVS real_server start and stop controller
###END INIT INFO
Copyright 2013 lxcong
chkconfig: - 20 80
Author: xxxx@xxxx
#There are multiple virtual IPs, separated by spaces SNS_VIP="1.1.1.1" ./etc/rc.d/init.d/functions if [[ -z "$SNS_VIP" ]];then echo Please set vips in $0 with SNS_VIP! fi
start(){ num=0 for loop in $SNS_VIP do /sbin/ifconfig lo:$num $loop netmask 255.255.255.255 broadcast $loop /sbin/route add -host $loop dev lo:$num ((num++)) done 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 -e -p >/dev/null 2>&1 }
stop(){ num=0 for loop in $SNS_VIP do /sbin/ifconfig lo:$num down /sbin/route del -host $loop >/dev/null 2>&1 ((num++)) done 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 sysctl -e -p >/dev/null 2>&1 }
case "$1" in start) start echo "RealServer Start OK" ;; stop) stop echo "RealServer Stopped" ;; restart) stop start ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 esac exit 0
2. Startup file
chmod +x /etc/init.d/realserver
3. Startup
service realserver start
4. Configure startup
chkconfig realserver on
5. Start the realserver service and perform various tests
Copyright statement:
- All content that is not sourced is original., please do not reprint without authorization (because the typesetting is often disordered after reprinting, the content is uncontrollable, and cannot be continuously updated, etc.);
- For non-profit purposes, to deduce any content of this blog, please give the relevant webpage address of this site in the form of 'source of original text' or 'reference link' (for the convenience of readers).
See Also:
- alacritty terminal use
- Ubuntu LDAP Client Installation
- Ubuntu notify-send Scheduled Notifications
- Building a Raspberry Pi Wireless Router