lvs LVS Keepalived雙主配置

2021-10-24 01:45:01 字數 2892 閱讀 2491

一般場景中實現lvs高可用及後端的lb,同時只有一台lvs提供服務,另一台作為backup,顯然沒有做到最大利用。我們可以讓兩台lvs都作為master,並又互為backup,與master-backup架構相比,master-master架構需要多加乙個vip。

lvs1+keepalived:192.168.1.2

lvs2+keepalived:192.168.1.3

web1:192.168.1.4

web2:192.168.1.5

vip:192.168.1.6,192.168.1.7

master host1 配置
[root@localhost ~]

# cat /etc/keepalived/keepalived.conf

vrrp_instance bl_one

virtual_ipaddress

}vrrp_instance bl_two

virtual_ipaddress

}virtual_server 192.168.1.6 80

} real_server 192.168.1.5 80 }}

virtual_server 192.168.1.7 80

connect_timeout 10

nb_get_retry 3

delay_before_retry 3

connect_port 80

}} real_server 192.168.1.5 80

connect_timeout 10

nb_get_retry 3

delay_before_retry 3

connect_port 80

}}}

master host2 配置
[root@localhost ~]

# cat /etc/keepalived/keepalived.conf

vrrp_instance bl_one

virtual_ipaddress

}vrrp_instance bl_two

virtual_ipaddress

}virtual_server 192.168.1.6 80

} real_server 192.168.1.5 80 }}

virtual_server 192.168.1.7 80

connect_timeout 10

nb_get_retry 3

delay_before_retry 3

connect_port 80

}} real_server 192.168.1.5 80

connect_timeout 10

nb_get_retry 3

delay_before_retry 3

connect_port 80

}}}

以上建立了兩個例項lb_one、lb_two ,其中a主機做為vip1位址的master,b主機做為vip2位址的master,a、b主機互為backup 。另外還有乙個技巧點,在master-backup架構中也可以配置多個vip位址,只需要在例項的vip配置中增加位址、並在後面指定對應的虛位址後面的realserver即可。在主備腳架中配置多個vip的方法如下:

virtual_ipaddress
[root@localhost # cat dr_client.sh

#!/bin/bash

vip1=192.168.1.6

vip2=192.168.1.7

# vip's broadcast

broadcast=192.168.1.255

. /etc/rc.d/init.d/functions

case

"$1"

instart)

echo

"reparing for real server"

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

ifconfig lo:0 $vip1 netmask 255.255.255.255 broadcast $broadcast up

ifconfig lo:1 $vip2 netmask 255.255.255.255 broadcast $broadcast up

/sbin/route add -host $vip1 dev lo:0

/sbin/route add -host $vip2 dev lo:1

;;stop)

ifconfig lo:0 down

ifconfig lo:1 down

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: lvs "

exit 1

esac

keepalived雙主雙從配置

機器ip位址為自己本身機器的ip請勿使用博主的ip 配置過程時間有點長,比較多,配置的時候請看清 加油,打工人 配置環境 keepalived1 192.66.66.101 keepalived2 192.66.66.102 web1 192.66.66.103 web2 192.66.66.104...

mysql雙主複製的缺點 mysql雙主複製總結

雙主複製 1 在兩台伺服器上各自建立乙個具有複製許可權的使用者 2 修改配置檔案 主伺服器a上 mysqld server id 10 log bin mysql bin relay log relay mysql auto increment offset 1 起始值 auto increment...

keepalived nginx雙主配置

1 構建後端兩台apache,保證通過192.168.0.1 192.168.0.2能夠正常訪問 另一台省略了 2 構建前端兩台nginx反向 到後端apache,保證能夠負載反向 到192.168.0.1 192.168.0.2 ifconfig eth0 1 192.168.0.4 24 rpm...