keepalived高可用脚本配置自动切换+脑裂

本文介绍了如何在主备服务器上配置keepalived,实现httpd服务的高可用。通过监控脚本确保负载均衡机状态,并详细阐述了在主备服务器上安装httpd服务、在备服务器上安装并配置keepalived的过程。此外,还讲解了zabbix页面的部署,包括主机的添加、触发器设置和媒介配置,以确保在主服务器故障时能自动切换并发送通知。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境说明

系统信息 主机名 IP
rhel8 zabbix 192.168.236.136
rhel8 MASTER 192.168.236.131
rhel8 SLAVE 192.168.236.135
keepalived安装

配置主keepalived

//关闭防火墙与SELINUX
[root@MASTER ~]# systemctl stop firewalld
[root@MASTER ~]# systemctl disable firewalld
[root@MASTER ~]# setenforce 0
[root@MASTER ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config

//配置网络源
[root@MASTER ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
[root@MASTER ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@MASTER ~]# sed -i 's/\$releasever/8/g' /etc/yum.repos.d/CentOS-Base.repo
[root@MASTER ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@MASTER ~]# sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@MASTER ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*

//安装keepalived
[root@MASTER ~]# yum -y install keepalived

在主备机上分别安装httpd

在master上安装httpd

[root@MASTER ~]# yum -y install httpd
[root@MASTER ~]# echo "web1" > /var/www/html/index.html
[root@MASTER ~]# systemctl start httpd
[root@MASTER ~]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port     Peer Address:Port   
LISTEN   0        128              0.0.0.0:22            0.0.0.0:*      
LISTEN   0        128                    *:80                  *:*      
LISTEN   0        128                 [::]:22               [::]:*      
[root@MASTER ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

在slave上安装httpd

[root@SLAVE ~]# yum -y install httpd
[root@SLAVE ~]# echo "web2" > /var/www/html/index.html
[root@SLAVE ~]# systemctl  start httpd
[root@SLAVE ~]# ss -antl
State  Recv-Q Send-Q  Local Address:Port   Peer Address:Port                                                    
LISTEN 0      128           0.0.0.0:22          0.0.0.0:*                                                       
LISTEN 0      128                 *:80                *:*                                                       
LISTEN 0      128              [::]:22             [::]:*                         
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值