lvs端部署
1. ipvsadm
yum install ipvsadm
2. keepalived
yum install keepalived
3. vim /etc/keepalived/keepalived.conf, 测试示例如下
! Configuration File for keepalived
global_defs {
notification_email {
haha@test.com
}
router_id LVS_M
}
vrrp_instance VI_1 {
state MASTER
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
protocol TCP
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
protocol TCP
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
protocol TCP
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
protocol TCP
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
protocol TCP
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
protocol TCP
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. slave 端部署同master一样, 只需要调整router_id、state、prority参数
/sbin/iptables -A INPUT -p vrrp -j ACCEPT 添加防火墙规则
realserver端部署:
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
#有多个虚拟IP,以空格分隔
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 Stoped"
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
2. 启动文件
chmod +x /etc/init.d/realserver
3. 启动
service realserver start
4. 配置开机启动
chkconfig realserver on
5. realserver 开启服务,进行各项测试
最后修改于: Monday, August 28, 2023
版权申明:
- 未标注来源的内容全部为原创,未经授权请勿转载(因转载后排版往往错乱、内容不可控、无法持续更新等);
- 非营利为目的,演绎本博客任何内容,请以'原文出处'或者'参考链接'等方式给出本站相关网页地址(方便读者)。