keepalived+lVS(dr)高可用集群

keepalived+lVS(dr)高可用集群

规划

服务器名称 IP 描述
master keepalived+lvs VIP:192.168.238.100 DIP:192.168.238.151 keepalived的master节点和lvs负载均衡
backup keepalived+lvs VIP:192.168.238.100 DIP:192.168.238.152 keepalived的备份节点和lvs负载均衡
server1 VIP:192.168.238.100 RIP:192.168.238.153 web服务器
server2 VIP:192.168.238.100 RIP:192.168.238.154 web服务器

配置主机名

sh 复制代码
hostnamectl set-hostname master   #151执行
hostnamectl set-hostname backup   #152执行
hostnamectl set-hostname server1   #153执行
hostnamectl set-hostname server2   #154执行

四台机器都配置dns还有 关闭防火墙、关闭selinux

sh 复制代码
cat > /etc/hosts << EOF
192.168.238.151 master
192.168.238.152 backup
192.168.238.153 server1
192.168.238.154 server2
EOF

#关闭防火墙
systemctl disable firewalld --now
#关闭selinux
sed -i '/^SELINUX/s/enforcing/disabled/g' /etc/selinux/config
setenforce 0

四台机器都配置时间同步

sh 复制代码
yum -y install ntpdate bash-completion* net-tools wget

crontab -e
*/1 * * * * /usr/sbin/ntpdate ntp.aliyun.com

151和152安装keepalived 和ipvsadm

sh 复制代码
yum -y install keepalived
cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak

yum -y install ipvsadm

151执行

sh 复制代码
cat > /etc/keepalived/keepalived.conf << EOF
global_defs {
router_id LVS_master #主和从要有单独的route_id
}
vrrp_instance VI_1 {
state MASTER #主为MASTER 从为BACKUP
interface ens33 #指定配机网卡的设备名
virtual_router_id 51 #指定虚拟路由主从要一致
priority 100 #指定优先级主优先高 从做先级低
advert_int 1 #心跳检测时间间隔
authentication { #keepalived内通信认证方式
auth_type PASS
auth_pass 1111
}
virtual_ipaddress { #指定绑定的vip
192.168.238.100
}
}
EOF

152执行

sh 复制代码
cat > /etc/keepalived/keepalived.conf << EOF
global_defs {
router_id LVS_backup #主和从要有单独的route_id
}
vrrp_instance VI_1 {
state BACKUP #主为MASTER 从为BACKUP
interface ens33 #指定配机网卡的设备名
virtual_router_id 51 #指定虚拟路由主从要一致
priority 80 #指定优先级主优先高 从做先级低
advert_int 1 #心跳检测时间间隔
authentication { #keepalived内通信认证方式
auth_type PASS
auth_pass 1111
}
virtual_ipaddress { #指定绑定的vip
192.168.238.100
}
}
EOF

151和152启动keepalived

sh 复制代码
systemctl start keepalived

151和152查看系统是否支持ipvs

sh 复制代码
lsmod |grep ip_vs

151和152配置LVS负载均衡

sh 复制代码
ipvsadm -C
ipvsadm -A -t 192.168.238.100:80 -s rr
ipvsadm -a -t 192.168.238.100:80 -r 192.168.238.153:80 -g
ipvsadm -a -t 192.168.238.100:80 -r 192.168.238.154:80 -g

server1和server2安装httpd

复制代码
yum -y install httpd
echo "server1" > /var/www/html/index.html   #server1执行
echo "server2" > /var/www/html/index.html   #server2执行
systemctl start httpd

server1和server2编写配置虚拟IP脚本 vim lvs.sh

sh 复制代码
#!/bin/bash
#description : start realserver
VIP=192.168.238.100
case "$1" in
start)
echo " start LVS of REALServer"
/usr/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
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
;;
stop)
/usr/sbin/ifconfig lo:0 down
echo "close LVS Directorserver"
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: $0 {start|stop}"
exit 1
esac

执行

sh 复制代码
source lvs.sh start

在152上测试

相关推荐
可爱又迷人的反派角色“yang”6 小时前
LVS+Keepalived群集
linux·运维·服务器·前端·nginx·lvs
Q鑫6 天前
LVS/Nginx/Haproxy+keepalived负载均衡集群工作原理
nginx·负载均衡·lvs
yifengyiyufjq7 天前
基于 CentOS 7 搭建 LVS 负载均衡(NAT 模式)搭建指南
centos·负载均衡·lvs
Aiden1212110 天前
LVS+Keepalived
lvs
可可苏饼干13 天前
LVS服务器
linux·运维·笔记·学习·lvs
zz-zjx13 天前
LVS NAT/DR 模式 负载均衡Keepalive 高可用+DR
网络协议·tcp/ip·lvs
ttthe_MOon13 天前
LVS-NAT 模式负载均衡集群部署与配置指南
运维·负载均衡·lvs
xingyue_S14 天前
LVS负载均衡群集(二)-- DR模式
运维·负载均衡·lvs
weixin_5377658015 天前
【负载均衡】LVS DR模式详解
服务器·负载均衡·lvs
weixin_5377658016 天前
【LVS高可用】Keepalived配置详解
lvs