一、实验要求:
1、基于LVS-DR模型上实践;
2、调度器高可用(双主模型);
二、实验拓扑图:
三、实验步骤:
1、 设置RS
(a)设置http主页
Yum install httpd
Vim /var/www/html/index.html
<h1>172.18.24.3 server 1或者172.18.24.5
server 2</h1>
(b)设置RS的VIP
Vim setRS.sh
#!/bin/bash
vip=172.18.24.10
vip2=172.18.24.11
mask=’255.255.255.255′
iface=’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
lo:0 $vip netmask $mask broadcast $vip up
route
add -host $vip dev $iface
ifconfig
lo:0 $vip2 netmask $mask broadcast $vip2 up
route
add -host $vip2 dev $iface2
;;
stop)
ifconfig
$iface 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
;;
*)
echo
“Usage $(basename $0) start|stop”
exit
1
;;
esac
在RS上运行脚本 setRS.sh start
重启httpd服务
2、 配置VS
Yum install httpd Keepalived
Vim /var/www/html/inde.html
Sorry server 1 或者sorry
server2
(a) 设置VS1主从信息
global_defs {
notification_email {
root@localhost
}
notification_email_from keeplived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id test1
vrrp_mcast_group4 224.0.100.24
}
vrrp_instance myr1 {
state MASTER
interface eth0
virtual_router_id 67
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass UIpYPPDI
}
vrrp_instance
myr2 {
state BACKUP
interface eth0
virtual_router_id 68
priority 98
advert_int 1
authentication {
auth_type PASS
auth_pass UIpYPPDi
}
virtual_ipaddress {
172.18.24.11/16 dev eth0
}
}
virtual_ipaddress {
172.18.24.10/16 dev eth0
}
notify_master “/etc/keepalived/notify.sh master”
notify_backup “/etc/keepalived/notify.sh backup”
notify_fault “/etc/keepalived/notify.sh fault”
}
virtual_server 172.18.24.10 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
protocol TCP
sorry_server 127.0.0.1 80
real_server 172.18.24.3 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.24.5 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
(b)设置VS2主从信息
global_defs {
notification_email {
root@localhost
}
notification_email_from keeplived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id test4
vrrp_mcast_group4 224.0.100.24
}
vrrp_instance myr1 {
state BACKUP
interface ens38
virtual_router_id 67
priority 98
advert_int 1
authentication {
auth_type PASS
auth_pass UIpYPPDI
}
vrrp_instance
myr2 {
state MASTER
interface ens38
virtual_router_id 68
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass UIpYPPDi
}
virtual_ipaddress {
172.18.24.11/16 dev ens38
}
}
virtual_ipaddress {
172.18.24.10/16 dev ens38
}
notify_master “/etc/keepalived/notify.sh master”
notify_backup “/etc/keepalived/notify.sh backup”
notify_fault “/etc/keepalived/notify.sh fault”
}
virtual_server 172.18.24.11 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
protocol TCP
sorry_server 127.0.0.1 80
real_server 172.18.24.3 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.24.5 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
(c)Systemctl start httpd Systemctl start keepalived
3、测试 curl http://172.18.24.10 curl http://172.18.24.11
检测结果:不论是访问172.18.24.10还是172.18.24.11,最终显示以下的轮询结果,
<h1>172.18.24.3 server 1</h1>或者<h1>172.18.24.5
server 2</h1>
原创文章,作者:chenxu@magedu.com,如若转载,请注明出处:http://www.178linux.com/75732