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

相关推荐
再学一丢丢18 小时前
Keepalived+LVS+nginx高可用架构
nginx·架构·lvs
Cloud_.2 天前
用Nginx实现负载均衡与高可用架构(整合Keepalived)
nginx·架构·负载均衡·keepalived
cnskylee2 天前
【Keepalived】Keepalived-2.3.3明确结束对CentOS 7的支持
centos·keepalived·2.3.2·2.3.3
xxc_my2 天前
LVS的三种工作模式简述
服务器·网络·lvs
Kendra9193 天前
Keepalive+LVS+Nginx+NFS高可用架构
nginx·架构·lvs
棕生3 天前
架构师面试(二十三):负载均衡
nginx·负载均衡·lvs·架构师面试·rpc连接池·vip+keepalive
RememberLey4 天前
lvs-net+nfs的配置
开发语言·php·lvs
重启就好5 天前
【LVS】负载均衡群集部署(DR模式)
服务器·负载均衡·lvs
Z字小熊饼干爱吃保安5 天前
使用LVS的 NAT 模式实现 3 台RS的轮询访问
运维·服务器·lvs
柳如烟@5 天前
LVS-NAT 负载均衡与共享存储配置
linux·负载均衡·lvs