IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> keepalived+nginx高可用 脑裂监控 -> 正文阅读

[系统运维]keepalived+nginx高可用 脑裂监控

主机名ip
master192.168.220.10
backup192.168.220.30

准备工作

# 修改master主机名
[root@localhost ~]# hostnamectl set-hostname master
[root@localhost ~]# bash

# 关闭防火墙
[root@master ~]# systemctl disable --now firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@master ~]# setenforce 0
[root@master ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
#修改backup主机名
[root@localhost ~]# hostnamectl set-hostname backup
[root@localhost ~]# bash

# 关闭防火墙和selinux
[root@backup ~]# systemctl disable --now firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@backup ~]# setenforce 0
[root@backup ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config

安装并配置nginx

#master主机nginx配置
[root@master ~]# yum install nginx -y
[root@master ~]# cd /usr/share/nginx/html/
[root@master html]# ls
404.html  50x.html  index.html  nginx-logo.png  poweredby.png
[root@master html]# mv index.html{,.bak}
[root@master html]# echo 'master' > index.html
[root@master html]# cat index.html
master
[root@master ~]# systemctl start nginx.service   //开启nginx

浏览器访问
在这里插入图片描述

#backup主机配置
[root@backup ~]# yum install nginx -y
[root@backup ~]# cd /usr/share/nginx/html/
[root@backup html]# mv index.html{,.bak}
[root@backup html]# echo 'backup' > index.html
[root@backup html]# cat index.html
backup
[root@backup html]# systemctl start nginx.service    //启动nginx

浏览器访问
在这里插入图片描述

安装并配置keepalived

为主安装配置keepalived

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

[root@master ~]# cd /etc/keepalived/
[root@master keepalived]# mv keepalived.conf{,.bak}   //备份配置原配置文件
 
[root@master keepalived]# cat keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id lb01
}

vrrp_instance VI_1 {
    state MASTER     //设置为主
    interface ens33   //必须和本机网卡名相同
    virtual_router_id 51  //虚拟路由id要和备一致
    priority 100          //定义优先级,按优先级来决定主备角色,优先级越大越优先
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass wangqing
    }
    virtual_ipaddress {
        192.168.220.250    //要使用的ip
    }
}

virtual_server 192.168.220.250 80 {     //虚拟路由ip 监听端口号为80(需要对其他服务进行高可用就改为指定服务的端口号)
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.220.10 80 {   //主ip地址
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }

    real_server 192.168.220.30 80 {   //备IP地址
        weight 1keepa
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

#启动keepalived
[root@master ~]# systemctl start keepalived.service 
[root@master ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:d2:6d:a2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.220.10/24 brd 192.168.220.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.220.250/32 scope global ens33    //当keepalived启动后 会生成vip
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed2:6da2/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

为备安装配置keepalived

[root@backup ~]# yum install keepalived -y
[root@backup ~]# cd /etc/keepalived/
[root@backup keepalived]# mv keepalived.conf{,.bak}
[root@backup keepalived]# cat keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id lb02
}

vrrp_instance VI_1 {
    state BACKUP   //修改为backup
    interface ens33
    virtual_router_id 51
    priority 90    //修改优先级 因为是备 所以优先级更低
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass wangqing
    }
    virtual_ipaddress {
        192.168.220.250
    }
}

virtual_server 192.168.220.250 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.220.10 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }

    real_server 192.168.220.30 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

#启动keepalived
[root@backup ~]# systemctl start keepalived.service 
[root@backup ~]# ip a  //因为优先级低 所以没有vip
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:8c:8e:d5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.220.30/24 brd 192.168.220.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe8c:8ed5/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

浏览器上使用vip进行访问 可以访问到master
在这里插入图片描述

使备主机获得vip并访问到对应网站

关闭master主机的keepalived服务

[root@master ~]# systemctl stop keepalived.service   
[root@backup ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:8c:8e:d5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.220.30/24 brd 192.168.220.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.220.250/32 scope global ens33   //backup主机拥有了vip
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe8c:8ed5/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

浏览器访问vip 可以看到backup主机的对应网页
在这里插入图片描述

配置脚本

恢复环境

[root@master ~]# systemctl start keepalived.service    //正常情况下主的keepalived和nginx都是开启的
[root@backup ~]# systemctl stop nginx.service          //备的nginx是关闭的

为主编写脚本

#此脚本用于控制keepalived是否关闭,当主的nginx异常,而关闭时就自动关闭keepalived服务以便让备能获得vip
[root@master ~]# mkdir /scripts
[root@master ~]# cd /scripts/
[root@master scripts]# cat check_nginx.sh 
#!/bin/bash
nginx_status=$(ps -ef|grep -Ev "grep|$0"|grep '\bnginx\b'|wc -l)
if [ $nginx_status -lt 1 ];then
    systemctl stop keepalived
fi
# 控制
[root@master scripts]# cat notify.sh 
#此脚本用于检查主机是否为master和backup 来控制nginx是否关闭和开启
#!/bin/bash
VIP=$2
#sendmail (){    //可以注释掉这几行 此为异常时发送邮件 实验并不需要 所以删除也没事
#        subject="${VIP}'s server keepalived state is translate"
#        content="`date +'%F %T'`: `hostname`'s state change to master"
#        echo $content | mail -s "$subject" 1@qq.com
#}
case "$1" in
  master)
        nginx_status=$(ps -ef|grep -Ev "grep|$0"|grep '\bnginx\b'|wc -l)
        if [ $nginx_status -lt 1 ];then
            systemctl start nginx
        fi
        sendmail
  ;;
  backup)
        nginx_status=$(ps -ef|grep -Ev "grep|$0"|grep '\bnginx\b'|wc -l)
        if [ $nginx_status -gt 0 ];then
            systemctl stop nginx
        fi
  ;;
  *)
        echo "Usage:$0 master|backup VIP"
  ;;
esac

[root@master scripts]# chmod +x check_nginx.sh 
[root@master scripts]# chmod +x notify.sh 
[root@master scripts]# ll
总用量 8
-rwxr-xr-x. 1 root root 142 831 11:34 check_nginx.sh
-rwxr-xr-x. 1 root root 667 831 11:37 notify.sh

为备编写脚本

[root@backup ~]# mkdir /scripts
[root@backup ~]# cd /scripts/
[root@backup scripts]# cat notify.sh 
#!/bin/bash
VIP=$2
sendmail (){
        subject="${VIP}'s server keepalived state is translate"
        content="`date +'%F %T'`: `hostname`'s state change to master"
        echo $content | mail -s "$subject" 1470044516@qq.com
}
case "$1" in
  master)
        nginx_status=$(ps -ef|grep -Ev "grep|$0"|grep '\bnginx\b'|wc -l)
        if [ $nginx_status -lt 1 ];then
            systemctl start nginx
        fi
        sendmail
  ;;
  backup)
        nginx_status=$(ps -ef|grep -Ev "grep|$0"|grep '\bnginx\b'|wc -l)
        if [ $nginx_status -gt 0 ];then
            systemctl stop nginx
        fi
  ;;
  *)
        echo "Usage:$0 master|backup VIP"
  ;;
esac

[root@backup scripts]# chmod +x notify.sh 
[root@backup scripts]# ll
总用量 4
-rwxr-xr-x. 1 root root 662 831 11:43 notify.sh

配置keepalived加入监控脚本的配置

配置主keepalived

[root@master ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id lb01
}

vrrp_script nginx_check {            //这里添加
    script "/scripts/check_nginx.sh"
    interval 1
    weight -20
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass wangqing
    }
    virtual_ipaddress {
        192.168.220.250
    }
    track_script {     //添加
        nginx_check
    }
    notify_master "/scripts/notify.sh master 192.168.220.250"
}

virtual_server 192.168.220.250 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.220.10 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }

    real_server 192.168.220.30 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

[root@master ~]# systemctl restart keepalived.service    //重启keepalived

配置备keepalived

[root@backup ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id lb02
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass wangqing
    }
    virtual_ipaddress {
        192.168.220.250
    }
    notify_master "/scripts/notify.sh master 192.168.220.250"
    notify_backup "/scripts/notify.sh backup 192.168.220.250"
}

virtual_server 192.168.220.250 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.220.10 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
[root@backup ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id lb02
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass wangqing
    }
    virtual_ipaddress {
        192.168.220.250
    }
    notify_master "/scripts/notify.sh master 192.168.220.250"   //添加
    notify_backup "/scripts/notify.sh backup 192.168.220.250"
}

virtual_server 192.168.220.250 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.220.10 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }

    real_server 192.168.220.30 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}
[root@backup ~]# systemctl restart keepalived.service   //重启keepalived

实验

master主机服务状态


[root@master ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset:>
   Active: active (running) since Wed 2022-08-31 12:54:46 CST; 8min ago
  Process: 4772 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 4769 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 4767 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/>

[root@master ~]# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor pr>
   Active: active (running) since Wed 2022-08-31 12:55:52 CST; 8min ago

backup主机服务状态

[root@backup ~]# systemctl status nginx.service 
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset:>
   Active: inactive (dead)

[root@backup ~]# systemctl status keepalived.service 
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor pr>
   Active: active (running) since Wed 2022-08-31 12:54:26 CST; 12min ago
  Process: 3652 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, s>

关闭主nginx服务

[root@master ~]# systemctl stop nginx.service 
[root@master ~]# ip a   //vip消失了
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:d2:6d:a2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.220.10/24 brd 192.168.220.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed2:6da2/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
#当主的nginx服务异常时 备抢占vip开启nginx服务
[root@backup ~]# systemctl status nginx.service 
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-08-31 13:13:59 CST; 12s ago
  Process: 48364 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 48362 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 48360 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)




[root@backup ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:8c:8e:d5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.220.30/24 brd 192.168.220.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.220.250/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe8c:8ed5/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

浏览器访问
在这里插入图片描述

注:正常情况下主的nginx和keepalived服务是开启的,备的nginx是关闭keeplived服务是开启的。当主的nginx服务异常时通过监控或者脚本用邮件发送告警信息给用户,当需要恢复主的服务时需要手动将主的nginx异常修复后并将nginx和keepalived服务重启,主就拥有了vip并可以正常访问到master

#开启nginx服务和keepalived服务
[root@master ~]# systemctl start nginx.service 
[root@master ~]# systemctl restart keepalived.service 


[root@master ~]# ip a   //重新获取到了vip
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:d2:6d:a2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.220.10/24 brd 192.168.220.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.220.250/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed2:6da2/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

通过浏览器访问vip
在这里插入图片描述

#此时备的nginx在vip被抢占后 通过脚本自动关闭nginx
[root@backup ~]# systemctl status nginx.service 
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

zabbix监控脑裂

主机ip
master192.168.220.10
zabbix192.168.220.20
backup192.168.220.30

监控出现异常的两种状态:

  • 正常情况下master主机nginx和keepalived为开启,backup主机keepalived为开启nginx为关闭,当master主机发生异常时backup主机通过脚本抢夺vip
  • 当出现脑裂时主备的两台主机都会有vip

所以只需要监控备主机的网卡是否有vip就可以达到zabbix监控脑裂

在backup主机安装zabbix的客户端,在192.168.220.20主机安装zabbix服务端用于使用web网页管理监控
详细步参考zabbix客户端服务端安装

编写脚本

在备主机上编写脚本

[root@backup scripts]# cat check_keepalived.sh 
#!/bin/bash

if [ `ip a show ens33 |grep 192.168.220.250|wc -l` -ne 0 ]   //网卡与本机网卡名一致,过滤vip
then
    echo "1"   //当过滤到时为1
else
    echo "0"  //否则为0
fi

[root@backup scripts]# ./check_keepalived.sh   //测试脚本
0

客户端测试脚本

[root@zabbix ~]# zabbix_get -s 192.168.220.30 -k check_keepalived
0

添加需要监控的主机
在这里插入图片描述

在这里插入图片描述

添加监控项

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

添加触发器

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

勾选所有级别警告
在这里插入图片描述

配置backup主机zabbix文件

[root@backup etc]# pwd
/usr/local/etc

[root@backup etc]# cat zabbix_agentd.conf  //在此文件最后添加
Server=192.168.220.20    //服务端ip
ServerActive=192.168.220.20  //服务端ip
Hostname=test   //主机名和文本界面的一致
UserParameter=check_keepalived,/bin/bash /scripts/check_keepalived.sh   //脚本参数


[root@backup ~]# pkill zabbix_agentd   //重启服务让其生效
[root@backup ~]# zabbix_agentd 

仪表盘查看
在这里插入图片描述

测试

让主备产生脑裂

[root@backup ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id lb02
}

vrrp_instance VI_1 {
    state BACKUP   
    interface ens33
    virtual_router_id 50   //正常情况下此处id主备一致 改为不一致就可以产生脑裂
    priority 90    
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass wangqing
    }
    virtual_ipaddress {
        192.168.220.250
    }
    notify_master "/scripts/notify.sh master 192.168.220.250"
    notify_backup "/scripts/notify.sh backup 192.168.220.250"
}

virtual_server 192.168.220.250 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.220.10 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }

    real_server 192.168.220.30 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

[root@backup ~]# systemctl restart keepalived.service 

查看vip

可以看到主备都产生的vip

[root@master ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:d2:6d:a2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.220.10/24 brd 192.168.220.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.220.250/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed2:6da2/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever


[root@backup ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:8c:8e:d5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.220.30/24 brd 192.168.220.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.220.250/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe8c:8ed5/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

查看仪表盘
发出了告警
在这里插入图片描述

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-09-04 01:48:04  更:2022-09-04 01:48:23 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 9:49:38-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码