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
版權申明:
- 未標註來源的內容皆為原創,未經授權請勿轉載(因轉載後排版往往錯亂、內容不可控、無法持續更新等);
- 非營利為目的,演繹本博客任何內容,請以'原文出處'或者'參考鏈接'等方式給出本站相關網頁地址(方便讀者)。