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上测试

相关推荐
yangfeipancc6 小时前
LVS介绍
lvs
2401_8712133011 小时前
lvs负载均衡
运维·负载均衡·lvs
TianyaOAO11 小时前
lvs介绍和DR模式
服务器·网络·lvs
学Linux的语莫3 天前
负载均衡,高可用,监控服务搭建总结
linux·服务器·分布式·ceph·lvs
马立杰5 天前
LVS能否实现两台服务器的负载均衡
linux·lvs
林清海笙9 天前
【射频IC进阶实践教程】2.6 LNA版图设计及DRC/LVS验证
网络·射频工程·集成电路·lvs·射频ic·射频电路设计·ic设计教程
马立杰11 天前
LVS的DR模式是否依赖内核的数据包转发
linux·lvs
酒醉的胡铁12 天前
keepalived 高可用离线配置
keepalived
马立杰13 天前
LVS默认的工作模式支持哪些负载均衡算法?
linux·服务器·lvs
学Linux的语莫14 天前
LVS-DR工作模式简介(相对nat性能更高)
linux·运维·服务器·ansible·lvs