拓?fù)鋱D
配置前提:各節(jié)點時間同步阳惹,關(guān)閉iptables和selinux癌淮;
DR1:
1.配置keepalived
[root@localhost keepalived]# cat keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@loaclhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node1
vrrp_mcast_group4 224.100.100.20
}
//定義虛擬路由實例1
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 50
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass ck2384
}
virtual_ipaddress {
172.18.20.80/16 dev ens33
}
}
//定義虛擬路由實例2
vrrp_instance VI_2 {
state BACKUP
interface ens33
virtual_router_id 51
priority 98
advert_int 1
authentication {
auth_type PASS
auth_pass ck2384zw
}
virtual_ipaddress {
172.18.20.81/16 dev ens33
}
}
//定義集群服務(wù)20.80
virtual_server 172.18.20.80 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
sorry_server 127.0.0.1 80
//定義RealServer
real_server 172.18.20.5 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 172.18.20.8 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
}
//定義集群服務(wù)20.81
virtual_server 172.18.20.81 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
sorry_server 127.0.0.1 80
//定義RealServer
real_server 172.18.20.5 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 172.18.20.8 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
2.配置本機(jī)為sorry_server
DR2上操作:
1.配置keepalived服務(wù)
[root@localhost html]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@loaclhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node2
vrrp_mcast_group4 224.100.100.20
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 50
priority 98
advert_int 1
authentication {
auth_type PASS
auth_pass ck2384
}
virtual_ipaddress {
172.18.20.80/16 dev eth0
}
}
vrrp_instance VI_2 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass ck2384zw
}
virtual_ipaddress {
172.18.20.81/16 dev eth0
}
}
virtual_server 172.18.20.80 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
sorry_server 127.0.0.1 80
real_server 172.18.20.5 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 172.18.20.8 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
}
}
}
virtual_server 172.18.20.81 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
sorry_server 127.0.0.1 80
real_server 172.18.20.5 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 172.18.20.8 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
}
}
}
2.配置本機(jī)為sorry server
在RS1上操作:(RS2上相同操作)
1.設(shè)置內(nèi)核參數(shù),配置兩個vip地址许师,腳本實現(xiàn)
cat setparm.sh
#!/bin/bash
vip1='172.18.20.80'
vip2=’172.18.20.81’
netmask='255.255.255.255'
iface1='lo:0'
iface2=’lo:1’
case $1 in
start)
echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
echo 2 >/proc/sys/net/ipv4/conf/lo/arp_announce
ifconfig $iface1 $vip1 netmask $netmask broadcast $vip1 up
ifconfig $iface 2$vip2 netmask $netmask broadcast $vip2 up
route add -host $vip1 dev $iface1
route add -host $vip2 dev $iface2
洋闽;瓤球;
stop)
ifconfig $iface1 down
Ifconfig $iface2 down
echo 0 >/proc/sys/net/ipv4/conf/all/arp_ignore
echo 0 >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo 0 >/proc/sys/net/ipv4/conf/all/arp_announce
echo 0 >/proc/sys/net/ipv4/conf/lo/arp_announce
溺忧;咏连;
*)
Usage:start|stop
esac
2.配置web服務(wù)
##啟動各節(jié)點的web服務(wù)盯孙,啟動keepalived服務(wù);
查看ipvs規(guī)則:在DR1上
[root@localhost keepalived]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.18.20.80:80 rr
-> 172.18.20.5:80 Route 1 0 0
-> 172.18.20.8:80 Route 1 0 0
TCP 172.18.20.81:80 rr
-> 172.18.20.5:80 Route 1 0 0
-> 172.18.20.8:80 Route 1 0 0
當(dāng)DR1宕機(jī)祟滴,DR2能正常調(diào)度