keepalived部署高可用


keepalived是什么?

Keepalived 软件起初是专为LVS负载均衡软件设计的,用来管理并监控LVS集群系统中各个服务节点的状态,后来又加入了可以实现高可用的VRRP功能。因此,Keepalived除了能够管理LVS软件外,还可以作为其他服务(例如:Nginx、Haproxy、MySQL等)的高可用解决方案软件。

Keepalived软件主要是通过VRRP协议实现高可用功能的。VRRP是Virtual Router RedundancyProtocol(虚拟路由器冗余协议)的缩写,VRRP出现的目的就是为了解决静态路由单点故障问题的,它能够保证当个别节点宕机时,整个网络可以不间断地运行。

所以,Keepalived 一方面具有配置管理LVS的功能,同时还具有对LVS下面节点进行健康检查的功能,另一方面也可实现系统网络服务的高可用功能。

keepalived高可用故障转移的原理

Keepalived 高可用服务之间的故障切换转移,是通过 VRRP (Virtual Router Redundancy Protocol ,虚拟路由器冗余协议)来实现的。

在 Keepalived 服务正常工作时,主 Master 节点会不断地向备节点发送(多播的方式)心跳消息,用以告诉备 Backup 节点自己还活看,当主 Master 节点发生故障时,就无法发送心跳消息,备节点也就因此无法继续检测到来自主 Master 节点的心跳了,于是调用自身的接管程序,接管主 Master 节点的 IP 资源及服务。而当主 Master 节点恢复时,备 Backup 节点又会释放主节点故障时自身接管的IP资源及服务,恢复到原来的备用角色。

那么,什么是VRRP呢?
VRRP ,全 称 Virtual Router Redundancy Protocol ,中文名为虚拟路由冗余协议 ,VRRP的出现就是为了解决静态踣甶的单点故障问题,VRRP是通过一种竞选机制来将路由的任务交给某台VRRP路由器的。

keepalived部署

master配置

//关闭防火墙与selinux
[root@master yum.repos.d]# systemctl  stop firewalld
[root@master yum.repos.d]# cat /etc/sysconfig/selinux 
SELINUX=disabled
//配置网络源
[root@master yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@slave yum.repos.d]# yum -y install epel-release vim wget gcc gcc-c++
安装keepalived
[root@master yum.repos.d]# dnf -y install keepalived
安装nginx
[root@master ~]# dnf -y install nginx
//修改网页访问内容
[root@master ~]# cd /usr/share/nginx/html/
[root@master html]# mv index.html{,.bak}
[root@master html]# ls
404.html  50x.html  index.html.bak  nginx-logo.png  poweredby.png
[root@master html]# echo 'liu' > index.html
[root@master html]# systemctl  start nginx
[root@master html]# systemctl  enable nginx
[root@master html]# ss -atnl
State   Recv-Q  Send-Q    Local Address:Port     Peer Address:Port  Process  
LISTEN  0       128             0.0.0.0:80            0.0.0.0:*              
LISTEN  0       128             0.0.0.0:22            0.0.0.0:*              
LISTEN  0       128                [::]:80               [::]:*              
LISTEN  0       128                [::]:22               [::]:*  
//配置keepalived
[root@master keepalived]# cat keepalived.conf 
! Configuration File for keepalived

global_defs {
   router_id ly1
}

vrrp_instance LY_1 {
    state MASTER
    interface ens33
    virtual_router_id 02
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass liuyang
    }
    virtual_ipaddress {
        192.168.34.190
    }
}

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

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

    real_server 192.168.34.131 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}
//开启keepalived
[root@master ~]# systemctl  start keepalived
[root@master ~]# systemctl  enable keepalived
查看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: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:40:e9:e5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.34.129/24 brd 192.168.34.255 scope global dynamic noprefixroute ens160
       valid_lft 1238sec preferred_lft 1238sec
    inet 192.168.34.191/32 scope global ens160			//vip地址
       valid_lft forever preferred_lft forever
    inet6 fe80::9fb7:6eb1:f172:7121/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
//keepalived通过脚本来监控nginx负载均衡机的状态
[root@master ~]# mkdir /scripts
[root@master ~]# cd /scripts
[root@master scripts]# vim ly_check_n.sh
[root@master scripts]# cat ly_check_n.sh
#!/bin/bash 
nginx_status=$(ps -ef |grep \bnginx\b |grep -v grep |wc -l)
if [ $nginx_status -lt 1 ];then
	systemctl stop keepalived
fi
[root@master scripts]# chmod +x ly_check_n.sh
[root@master scripts]# vim notify.sh
[root@master scripts]# cat notify.sh
#!/bin/bash
case "$1" in
  master)
        nginx_status=$(ps -ef|grep -Ev grep | grep \bnginx\b|wc -l)
        if [ $nginx_status -lt 1 ];then
            systemctl start nginx
        fi
        sendmail
  ;;
  backup)
        nginx_status=$(ps -ef|grep -Ev grep|grep '\bnginx\b'|wc -l)
        if [ $nginx_status -gt 0 ];then
            systemctl stop nginx
        fi
  ;;
esac
[root@master scripts]# chmod +x notify.sh
//配置keepalived加入监控脚本的配置
[root@master ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id ly1
}
vrrp_script nginx_check {
    script "/scripts/ly_check_n.sh"
    interval 1
    weight -20
}

vrrp_instance LY_1 {
    state MASTER
    interface ens160
    virtual_router_id 02
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass liuyang
    }
    virtual_ipaddress {
        192.168.34.191
    }
     track_script {
        nginx_check
    }
    notify_master "/scripts/notify.sh master 192.168.34.191"
    notify_backup "/scripts/notify.sh backup 192.168.34.191"
}

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

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

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

测试是否能访问到nginx

slave配置

//关闭防火墙与selinux
[root@slave ~]# systemctl  stop firewalld
[root@slave ~]# cat /etc/sysconfig/selinux 
SELINUX=disabled
//配置网络源
[root@slave ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
//安装所需的依赖包
[root@slave ~]# yum -y install epel-release vim wget gcc gcc-c++
安装keepalived与nginx
[root@slave ~]# dnf -y install keepalived
[root@slave ~]# dnf -y install nginx
修改nginx访问页面
[root@slave ~]# cd /usr/share/nginx/html/
[root@slave html]# mv index.html{,.bak}
[root@slave html]# echo 'yang' > index.html
[root@slave html]# ls
404.html  index.html      nginx-logo.png
50x.html  index.html.bak  poweredby.png
[root@slave html]# systemctl  start nginx
[root@slave html]# systemctl  enable nginx
//查看是否有vip
[root@slave ~]# 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: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:9a:86:3b brd ff:ff:ff:ff:ff:ff
    inet 192.168.34.131/24 brd 192.168.34.255 scope global dynamic noprefixroute ens160
       valid_lft 1359sec preferred_lft 1359sec
    inet6 fe80::dec5:1788:109a:67f8/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
在slave上编写脚本
[root@slave scripts]# cat ly_check_n.sh 
#!/bin/bash 
nginx_status=$(ps -ef |grep \bnginx\b |grep -v grep |wc -l)
if [ $nginx_status -lt 1 ];then
	systemctl stop keepalived
fi
[root@slave scripts]# cat notify.sh 
#!/bin/bash
case "$1" in
  master)
        nginx_status=$(ps -ef|grep -Ev grep | grep \bnginx\b|wc -l)
        if [ $nginx_status -lt 1 ];then
            systemctl start nginx
        fi
        sendmail
  ;;
  backup)
        nginx_status=$(ps -ef|grep -Ev grep|grep '\bnginx\b'|wc -l)
        if [ $nginx_status -gt 0 ];then
            systemctl stop nginx
        fi
  ;;
esac
[root@slave scripts]# chmod +x ly_check_n.sh
[root@slave scripts]# chmod +x notify.sh

使用vip访问


keepalived高可用

haproxy负载均衡部署

环境说明

主机名 ip地址 服务 系统信息
master 192.168.34.128 haproxy keepalived centos8
slave 192.168.34.130 haproxy keepalived centos8
httpd 192.168.34.131 nginx centos8
nginx 192.168.34.135 httpd centos7

master主机配置

//安装haproxy
[root@master ~]# yum -y install  haproxy
//安装所需的包
[root@master ~]# yum -y install make gcc pcre-devel bzip2-devel openssl-devel systemd-devel
//下载安装包
[root@master ~]#  wget https://src.fedoraproject.org/repo/pkgs/haproxy/haproxy-2.6.0.tar.gz/sha512/7bb70bfb5606bbdac61d712bc510c5e8d5a5126ed8827d699b14a2f4562b3bd57f8f21344d955041cee0812c661350cca8082078afe2f277ff1399e461ddb7bb/haproxy-2.6.0.tar.gz
//创建haproxy用户
[root@master ~]# useradd -rMs /sbin/nologin haproxy
//解压和安装haproxy
[root@master ~]# tar xf haproxy-2.6.0.tar.gz 
[root@master ~]# cd haproxy-2.6.0
[root@master haproxy-2.6.0]# make clean
[root@master haproxy-2.6.0]#  make -j $(grep 'processor' /proc/cpuinfo |wc -l)   TARGET=linux-glibc   USE_OPENSSL=1   USE_ZLIB=1   USE_PCRE=1  USE_SYSTEMD=1
[root@master haproxy-2.6.0]# make install PREFIX=/usr/local/haproxy
[root@master haproxy-2.6.0]# cp haproxy /usr/sbin/
//设置linux内核参数
[root@master ~]# vim /etc/sysctl.conf 
[root@master ~]# sysctl  -p
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1
//修改haproxy配置文件
[root@master haproxy-2.6.0]# cat /etc/haproxy/haproxy.cfg
global
    daemon
    maxconn 256
 
defaults
    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms
 
frontend http-in
    bind *:80
    default_backend servers
 
backend servers
    server web01 192.168.34.131:80
    server web02 192.168.34.135:80

[root@master haproxy-2.6.0]# cat /usr/lib/systemd/system/haproxy.service
[Unit]
Description=haproxy Load Balancer
After=syslog.target network.target

[Service]
ExecStartPre=/usr/local/haproxy/sbin/haproxy -f /etc/haproxy/haproxy.cfg   -c -q
ExecStart=/usr/local/haproxy/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg  -p /var/run/haproxy.pid
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target
//添加此行内容
[root@master haproxy-2.6.0]#  vim /etc/rsyslog.conf
local0.*                                                /var/log/haproxy.log
[root@master ~]# systemctl daemon-reload 
[root@master ~]#  systemctl start haproxy.service 
进行测试
[root@master ~]# curl 192.168.34.137
nginx
[root@master ~]# curl 192.168.34.137
httpd
[root@master ~]# curl 192.168.34.137
nginx
[root@master ~]# curl 192.168.34.137
httpd

slave主机配置

//安装haproxy
[root@slave ~]# yum -y install  haproxy
//安装所需的包
[root@slave ~]# yum -y install make gcc pcre-devel bzip2-devel openssl-devel systemd-devel
//下载安装包
[root@slave ~]#  wget https://src.fedoraproject.org/repo/pkgs/haproxy/haproxy-2.6.0.tar.gz/sha512/7bb70bfb5606bbdac61d712bc510c5e8d5a5126ed8827d699b14a2f4562b3bd57f8f21344d955041cee0812c661350cca8082078afe2f277ff1399e461ddb7bb/haproxy-2.6.0.tar.gz
//创建haproxy用户
[root@slave ~]# useradd -rMs /sbin/nologin haproxy
//解压和安装haproxy
[root@slave ~]# tar xf haproxy-2.6.0.tar.gz 
[root@slave ~]# cd haproxy-2.6.0
[root@slave haproxy-2.6.0]# make clean
[root@slave haproxy-2.6.0]#  make -j $(grep 'processor' /proc/cpuinfo |wc -l)   TARGET=linux-glibc   USE_OPENSSL=1   USE_ZLIB=1   USE_PCRE=1  USE_SYSTEMD=1
[root@slave haproxy-2.6.0]# make install PREFIX=/usr/local/haproxy
[root@slave haproxy-2.6.0]# cp haproxy /usr/sbin/
//设置linux内核参数
[root@slave ~]# vim /etc/sysctl.conf 
[root@slave ~]# sysctl  -p
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1
//修改haproxy配置文件
[root@slave haproxy-2.6.0]# cat /etc/haproxy/haproxy.cfg
global
    daemon
    maxconn 256
 
defaults
    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms
 
frontend http-in
    bind *:80
    default_backend servers
 
backend servers
    server web01 192.168.34.131:80
    server web02 192.168.34.135:80

[root@slave haproxy-2.6.0]# cat /usr/lib/systemd/system/haproxy.service
[Unit]
Description=haproxy Load Balancer
After=syslog.target network.target

[Service]
ExecStartPre=/usr/local/haproxy/sbin/haproxy -f /etc/haproxy/haproxy.cfg   -c -q
ExecStart=/usr/local/haproxy/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg  -p /var/run/haproxy.pid
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target
//添加此行内容
[root@slave haproxy-2.6.0]#  vim /etc/rsyslog.conf
local0.*                                                /var/log/haproxy.log
[root@slave ~]# systemctl daemon-reload 
[root@slave ~]#  systemctl start haproxy.service 
进行测试
[root@slave ~]# curl 192.168.34.137
nginx
[root@slave ~]# curl 192.168.34.137
httpd
[root@slave ~]# curl 192.168.34.137
nginx
[root@slave ~]# curl 192.168.34.137
httpd
//因为备机器不用做其他事情所以我们关掉其他服务
[root@slave ~]#  systemctl stop haproxy.service 

nginx主机配置

[root@httpd ~]# dnf -y install nginx
[root@httpd ~]# echo 'nginx' > /usr/share/nginx/html/index.html 
[root@httpd ~]# systemctl  restart nginx
[root@httpd ~]# systemctl enable nginx
[root@httpd ~]# ss -antl
State   Recv-Q  Send-Q    Local Address:Port     Peer Address:Port  Process  
LISTEN  0       128             0.0.0.0:80            0.0.0.0:*              
LISTEN  0       128             0.0.0.0:22            0.0.0.0:*              
LISTEN  0       128                [::]:80               [::]:*              
LISTEN  0       128                [::]:22               [::]:*              
[root@httpd ~]# curl 192.168.34.131
nginx

httpd主机配置

[root@nginx ~]# yum -y install httpd
[root@nginx ~]# echo 'httpd' > /var/www/html/index.html
[root@nginx ~]# systemctl  restart httpd
[root@nginx ~]# systemctl enable httpd
[root@nginx ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128        *:22                     *:*                  
LISTEN      0      100    127.0.0.1:25                     *:*                  
LISTEN      0      128       :::80                    :::*                  
LISTEN      0      128       :::22                    :::*                  
LISTEN      0      100      ::1:25                    :::*                  
[root@nginx ~]# curl 192.168.34.135
httpd

部署keepalived高可用

master配置

//安装所需的包
[root@master ~]# yum -y install epel-release vim wget gcc gcc-c++
//安装keepalived
[root@master ~]# dnf -y install keepalived
//配置备主机keepalived
[root@master keepalived]# cat keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id ly1
}

vrrp_instance LY_1 {
    state MASTER
    interface ens160
    virtual_router_id 02
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass liuyang
    }
    virtual_ipaddress {
        192.168.34.190
    }
}

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

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

    real_server 192.168.34.135 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}
查看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: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:40:e9:e5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.34.137/24 brd 192.168.34.255 scope global dynamic noprefixroute ens160
       valid_lft 1792sec preferred_lft 1792sec
    inet 192.168.34.190/32 scope global ens160		//vip地址
       valid_lft forever preferred_lft forever
    inet6 fe80::9fb7:6eb1:f172:7121/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
使用vip来访问
[root@master ~]# curl 192.168.34.190
nginx
[root@master ~]# curl 192.168.34.190
httpd
[root@master ~]# systemctl  enable --now keepalived

//编写脚本
[root@master ~]# mkdir /scripts
[root@master scripts]# cd /scripts
[root@master scripts]# cat check_h.sh 
#!/bin/bash
haproxy_status=$(ps -ef |grep \bhaproxy\b |grep -v grep |wc -l)
if [ $haproxy_status -lt 1 ];then
    systemctl stop keepalived
fi
[root@master scripts]# cat notify.sh 
#!/bin/bash
VIP=$2
case "$1" in
  master)
        haproxy_status=$(ps -ef|grep -Ev grep | grep '\bhaproxy\b'|wc -l)
        if [ $haproxy_status -lt 1 ];then
            systemctl start haproxy
        fi
  ;;
  backup)
        haproxy_status=$(ps -ef|grep -v grep|grep '\bhaproxy\b'|wc -l)
        if [ $haproxy_status -gt 0 ];then
            systemctl stop haproxy

[root@master scripts]# scp /scripts/notify.sh 192.168.34.130:/scripts
root@192.168.34.130's password: 
notify.sh                                  100%  361   136.7KB/s   00:00    
配置keepalived加入监控脚本的配置  添加以下内容
vim /etc/keepalived/keepalived.conf 
vrrp_script haproxy_check {
    script "/scripts/check_h.sh"
    interval 1
    weight -20
}

    track_script {              
        haproxy_check
    }
    notify_master "/scripts/notify.sh master 192.168.34.190"
[root@master scripts]# systemctl  restart keepalived

slave配置

//安装所需的包
[root@master ~]# yum -y install epel-release vim wget gcc gcc-c++
//安装keepalived
[root@master ~]# dnf -y install keepalived
//配置备主机keepalived
[root@slave keepalived]# cat keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id ly2
}

vrrp_instance LY_1 {
    state MASTER
    interface ens160
    virtual_router_id 02
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass liuyang
    }
    virtual_ipaddress {
        192.168.34.190
    }
}

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

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

    real_server 192.168.34.135 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}
[root@slave ~]# systemctl  enable --now keepalived
[root@slave ~]# mkdir /scripts
//配置备keepalived
backup无需检测nginx是否正常,当升级为MASTER时启动nginx,当降级为BACKUP时关闭[root@slave ~]# vim /etc/keepalived/keepalived.conf			//添加以下内容
 notify_master "/scripts/notify.sh master 192.168.34.190"
[root@slave ~]# systemctl restart keepalived

手动模拟haproxy主服务器down机

//主
[root@master scripts]# systemctl  stop haproxy
[root@master scripts]# 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: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:40:e9:e5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.34.137/24 brd 192.168.34.255 scope global dynamic noprefixroute ens160
       valid_lft 1077sec preferred_lft 1077sec
    inet6 fe80::9fb7:6eb1:f172:7121/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
//备
[root@slave ~]# 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: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:57:dd:0b brd ff:ff:ff:ff:ff:ff
    inet 192.168.34.130/24 brd 192.168.34.255 scope global dynamic noprefixroute ens160
       valid_lft 1681sec preferred_lft 1681sec
    inet 192.168.34.190/32 scope global ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::8c36:5fa5:1ee:4ec6/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@slave ~]# curl 192.168.34.190
nginx
[root@slave ~]# curl 192.168.34.190
httpd
posted @ 2022-10-08 21:21  Tqing  阅读(68)  评论(0编辑  收藏  举报