主从模型的ipvs高可用集群实验
一.实验拓图
二.实验环境
本实验是keepalived+lvs-dr的高可用负载均衡实验
本实验是在虚拟机上完成,因此如上拓扑图需要准备至少四台虚拟机
1.各节点的时间同步
使用yum安装chrony包,使用nat命令同步时间
2.关闭服务主机的iptables和selinux
三.实验步骤:
1.在VS1和VS1上安装keepalived
yum install keepalived y
2.配置文件
#vim /etc/keepalived/keepalived.conf
global_defs { ###通告的邮件用户
notification_email {
root@localhost
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id nodel1
vrrp_mcast_group4 224.0.101.50 ###同一个组播域
}
vrrp_instance VI_1 {
state MASTER ###当前物理设备在虚拟器设备的状态 MASTER或者BACKUP
interface eth1
virtual_router_id 51
priority 100 ###当前物理节点在虚拟路由器中的优先级
advert_int 1 ###对外通知时间间隔
authentication { ###认证
auth_type PASS
auth_pass 1111
}
virtual_ipaddress { ###定义虚拟ip
172.18.18.80 dev eth1
}
notify_master “/etc/keepalived/notify.sh master” ###通知脚本调用
notify_backup “/etc/keepalived/notify.sh backup”
notify_fault “/etc/keepalived/notify.sh fault”
}
#vrrp_instance VI_2 {
# state BACKUP
# interface eth1
# virtual_router_id 52
# priority 98
# advert_int 1
# authentication {
# auth_type PASS
# auth_pass 2222
# }
# virtual_ipaddress {
# 172.18.18.90 dev eth1
# }
#}
virtual_server 172.18.18.80 80 { ###虚拟服务配置
delay_loop 3 ###服务轮询时间间隔
lb_algo wrr ###调用算法
lb_kind DR ###调用类型
protocol TCP
sorry_server 127.0.0.1 80
real_server 172.18.18.20 80 { ###Real Server 配置信息
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
}
}
real_server 172.18.18.30 80 {
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
}
}
}
3.Notify通知脚本配置
#!/bin/bash
#
contact=’root@localhost’
notify(){
mailsubject=”$(hostname) to be $1″
mailbody=”$(hostname) to be $1, vrrp transion,$(date).”
echo “$mailbody” | mail -s “$mailsubject” $contact
}
case $1 in
master)
notify master ;;
backup)
notify backup ;;
fault)
notify fault ;;
*)
echo “Usage: $(basename $0) master|backup|fault”
exit 1
;;
esac
4.启动keepalived配置
systemctl start keepalived.service
systemctl status keepalived
查看负载均衡配置
ipvsadm -ln
另一台节点主机同上配置
5.开始配置后端两台服务器的网络配置
网络配置的脚本
vim setparam.sh
#!/bin/bash
2 #
3 vip=”172.18.18.80″
4 iface=”lo:0″
5 case $1 in
6 start)
7 echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
8 echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
9 echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
10 echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
11 ip addr add $vip/32 dev lo label $iface
12 route add -host $vip dev $iface
13 ;;
14 stop)
15 ip addr flush dev lo label $iface
16 echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
17 echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
18 echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
19 echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
20 ;;
21 esac
运行脚本
setparam.sh start
另一台服务器同上
6.启动httpd服务
systemctl start httpd
7.测试
以上就是该实验的一些基础步骤。
原创文章,作者:xialingfeng,如若转载,请注明出处:http://www.178linux.com/76084