keepalived實現haporxy負載均衡機高可用

来源:https://www.cnblogs.com/Their-own/archive/2022/10/10/16774214.html
-Advertisement-
Play Games

keepalived實現haporxy負載均衡機高可用 環境說明 | 系統信息 | 主機名 | IP | 服務 | | | | | | | centos8 | master | 192.168.111.141 | haproxykeepalived | | centos8 | backup | 19 ...


keepalived實現haporxy負載均衡機高可用

目錄

環境說明

系統信息 主機名 IP 服務
centos8 master 192.168.111.141 haproxy
keepalived
centos8 backup 192.168.111.142 haproxy
keepalived
centos8 RS1 192.168.111.143 httpd
centos8 RS2 192.168.111.144 nginx

1.首先部署好web界面

RS1配置

//修改名字
[root@localhost ~]# hostnamectl set-hostname RS1
[root@localhost ~]# bash
[root@RS1 ~]# 

//關閉防火牆和selinux
[root@RS1 ~]# setenforce 0
[root@RS1 ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@RS1 ~]# systemctl disable --now firewalld
[root@RS1 ~]# reboot

//配置yum源
[root@RS1 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@RS1 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

//安裝httpd服務,主頁內容為web1
[root@RS1 ~]# dnf -y install httpd
[root@RS1 ~]# echo "web1" > /var/www/html/index.html
[root@RS1 ~]# systemctl enable --now httpd.service 
[root@RS1 ~]# ss -anlt
State   Recv-Q  Send-Q   Local Address:Port   Peer Address:Port  Process  
LISTEN  0       128            0.0.0.0:22          0.0.0.0:*                        
LISTEN  0       128                  *:80                *:*              
LISTEN  0       128               [::]:22             [::]:*                     
[root@RS1 ~]# curl 192.168.111.143
web1

RS2配置

//修改名字
[root@RS1 ~]# hostnamectl set-hostname RS2
[root@RS1 ~]# bash
[root@RS2 ~]# 

//關閉防火牆和selinux
[root@RS2 ~]# setenforce 0
[root@RS2 ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@RS2 ~]# systemctl disable --now firewalld
[root@RS2 ~]# reboot

//配置yum源
[root@RS2 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@RS2 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
 
 //安裝nginx服務,主頁內容為web2
[root@RS2 ~]# dnf -y install nginx
[root@RS2 ~]# echo "web2" > /usr/share/nginx/html/index.html 
[root@RS2 ~]# systemctl enable --now nginx.service 
[root@RS2 ~]# ss -anlt
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@RS2 ~]# curl 192.168.111.144
web2

2.在部署haproxy負載均衡

master端

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

//關閉防火牆和selinux
[root@master ~]# setenforce 0
[root@master ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@master ~]# systemctl disable --now firewalld
[root@master ~]# reboot

//配置yum源
[root@master ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.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 ~]# useradd -rMs /sbin/nologin haproxy

//安裝依賴包
[root@master ~]# dnf -y install make gcc pcre-devel bzip2-devel openssl-devel systemd-devel wget vim

//下載haproxy壓縮包
[root@master ~]# wget https://src.fedoraproject.org/repo/pkgs/haproxy/haproxy-2.6.0.tar.gz/sha512/7bb70bfb5606bbdac61d712bc510c5e8d5a5126ed8827d699b14a2f4562b3bd57f8f21344d955041cee0812c661350cca8082078afe2f277ff1399e461ddb7bb/haproxy-2.6.0.tar.gz

//解壓並安裝
[root@master ~]# tar -xf haproxy-2.6.0.tar.gz
[root@master ~]# cd haproxy-2.6.0
[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

//複製命令到/usr/sbin目錄下
[root@master haproxy-2.6.0]# cp haproxy /usr/sbin/
[root@master haproxy-2.6.0]# cd

//修改內核參數
[root@master ~]# vim /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1

[root@master ~]# sysctl -p
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1

//修改配置文件
[root@master ~]# mkdir /etc/haproxy
[root@master ~]# vim /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.111.143:80
    server web02 192.168.111.144:80

//編寫service文件,並啟動服務
[root@master ~]# vim /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 ~]# systemctl daemon-reload
[root@master ~]# systemctl start haproxy
[root@master ~]# ss -anlt
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                           [::]:22                         [::]:*                    

//查看負載均衡效果
[root@master ~]# curl 192.168.111.141
web1
[root@master ~]# curl 192.168.111.141
web2
[root@master ~]# curl 192.168.111.141
web1
[root@master ~]# curl 192.168.111.141
web2

backup端

//修改名字
[root@localhost ~]# hostnamectl set-hostname backup
[root@localhost ~]# bash
[root@backup ~]# 

//關閉防火牆和selinux
[root@backup ~]# setenforce 0
[root@backup ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@backup ~]# systemctl disable --now firewalld
[root@backup ~]# reboot

//配置yum源
[root@backup ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@backup ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

//創建用戶
[root@backup ~]# useradd -rMs /sbin/nologin haproxy
 
//下載依賴包
[root@backup ~]# dnf -y install make gcc pcre-devel bzip2-devel openssl-devel systemd-devel wget vim
 
//下載haproxy壓縮包
[root@backup ~]# wget https://src.fedoraproject.org/repo/pkgs/haproxy/haproxy-2.6.0.tar.gz/sha512/7bb70bfb5606bbdac61d712bc510c5e8d5a5126ed8827d699b14a2f4562b3bd57f8f21344d955041cee0812c661350cca8082078afe2f277ff1399e461ddb7bb/haproxy-2.6.0.tar.gz
 
//解壓並安裝
[root@backup ~]# tar -xf haproxy-2.6.0.tar.gz
[root@backup ~]# cd haproxy-2.6.0
[root@backup 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@backup haproxy-2.6.0]# make install PREFIX=/usr/local/haproxy

//複製命令到/usr/sbin目錄下
[root@backup haproxy-2.6.0]# cp haproxy /usr/sbin/
[root@backup haproxy-2.6.0]# cd

//修改內核參數
[root@backup ~]# vim /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1
 
[root@backup ~]# sysctl -p
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1

//修改配置文件
[root@backup ~]# mkdir /etc/haproxy
[root@backup ~]# vim /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.111.143:80
    server web02 192.168.111.144:80

//編寫service文件,並啟動服務
[root@backup ~]# vim /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@backup ~]# systemctl daemon-reload 
[root@backup ~]# systemctl start haproxy.service 
[root@backup ~]# ss -anlt
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                           [::]:22                         [::]:*                        

//查看負載均衡效果
[root@backup ~]# curl 192.168.111.142
web1
[root@backup ~]# curl 192.168.111.142
web2
[root@backup ~]# curl 192.168.111.142
web1
[root@backup ~]# curl 192.168.111.142
web2

//backup端的負載均衡器最好關掉
[root@backup ~]# systemctl stop haproxy

3.開始部署keepalived高可用

master端

//首先安裝keepalived
[root@master ~]# dnf -y install keepalived
 
//編輯配置文件,並啟動服務
[root@master ~]# mv /etc/keepalived/keepalived.conf{,.bak}
[root@master ~]# vim /etc/keepalived/keepalived.conf 
! Configuration File for keepalived
 
global_defs {
   router_id lb01
}
 
vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        192.168.111.250
    }
}
 
virtual_server 192.168.111.250 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP
 
    real_server 192.168.111.141 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
 
    real_server 192.168.111.142 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}
[root@master ~]# systemctl enable --now keepalived

//通過虛擬IP訪問
[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:50:34:72 brd ff:ff:ff:ff:ff:ff
    inet 192.168.111.141/24 brd 192.168.111.255 scope global dynamic noprefixroute ens33
       valid_lft 1500sec preferred_lft 1500sec
    inet 192.168.111.250/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe50:3472/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@master ~]# curl 192.168.111.250
web1
[root@master ~]# curl 192.168.111.250
web2
[root@master ~]# curl 192.168.111.250
web1
[root@master ~]# curl 192.168.111.250
web2

backup端

//首先安裝keepalived
[root@backup ~]# dnf -y install keepalived
 
//編輯配置文件,並啟動服務
[root@backup ~]# mv /etc/keepalived/keepalived.conf{,.back}
[root@backup ~]# vim /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 123456
    }
    virtual_ipaddress {
        192.168.111.250
    }
}
 
virtual_server 192.168.111.250 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP
 
    real_server 192.168.111.141 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
 
    real_server 192.168.111.142 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}
[root@backup ~]# systemctl enable --now keepalived

4.編寫腳本

master端

[root@master ~]# mkdir /scripts
[root@master ~]# cd /scripts/
[root@master scripts]# vim check_haproxy.sh
#!/bin/bash
haproxy_status=$(ps -ef|grep -Ev "grep|$0"|grep '\bhaproxy\b'|wc -l)
if [ $haproxy_status -lt 1 ];then
    systemctl stop keepalived
fi

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

[root@master scripts]# chmod +x check_haproxy.sh notify.sh 
[root@master scripts]# ll
total 8
-rwxr-xr-x 1 root root 148 Oct 10 00:00 check_haproxy.sh
-rwxr-xr-x 1 root root 377 Oct 10 00:01 notify.sh

backup端

[root@backup ~]# mkdir /scripts
[root@backup ~]# cd /scripts/
[root@backup scripts]# scp [email protected]:/scripts/notify.sh .
[root@backup scripts]# ll
total 4
-rwxr-xr-x 1 root root 377 Oct 10 00:02 notify.sh

5.配置keepalived加入監控腳本的配置

master端

[root@master ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
 
global_defs {
   router_id lb01
}
 
vrrp_script haproxy_check {				//添加
    script "/scripts/check_haproxy.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 123456
    }
    virtual_ipaddress {
        192.168.111.250
    }
    track_script {			//添加
        haproxy_check
    }
    notify_master "/scripts/notify.sh master 192.168.111.250"
}
 
virtual_server 192.168.111.250 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP
 
    real_server 192.168.111.141 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
 
    real_server 192.168.111.142 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}
[root@master scripts]# systemctl restart keepalived

backup端

[root@backup ~]# vim /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 123456
    }
    virtual_ipaddress {
        192.168.111.250
    }
    notify_master "/scripts/notify.sh master 192.168.111.250"		//添加
    notify_backup "/scripts/notify.sh backup 192.168.111.250"
}
 
virtual_server 192.168.111.250 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP
 
    real_server 192.168.111.141 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
 
    real_server 192.168.111.142 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}
[root@backup ~]# systemctl restart keepalived

測試

模擬haproxy服務故障

//master端
[root@master ~]# curl 192.168.111.250
web1
[root@master ~]# curl 192.168.111.250
web2
[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:50:34:72 brd ff:ff:ff:ff:ff:ff
    inet 192.168.111.141/24 brd 192.168.111.255 scope global dynamic noprefixroute ens33
       valid_lft 1601sec preferred_lft 1601sec
    inet 192.168.111.250/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe50:3472/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@master ~]# systemctl stop haproxy
[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:50:34:72 brd ff:ff:ff:ff:ff:ff
    inet 192.168.111.141/24 brd 192.168.111.255 scope global dynamic noprefixroute ens33
       valid_lft 1591sec preferred_lft 1591sec
    inet6 fe80::20c:29ff:fe50:3472/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

//backup端
[root@backup ~]# systemctl start haproxy    //前面把服務關了這裡啟動一下
[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:07:42:65 brd ff:ff:ff:ff:ff:ff
    inet 192.168.111.142/24 brd 192.168.111.255 scope global dynamic noprefixroute ens33
       valid_lft 947sec preferred_lft 947sec
    inet 192.168.111.250/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe07:4265/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@backup ~]# curl 192.168.111.250
web1
[root@backup ~]# curl 192.168.111.250
web2
[root@backup ~]# curl 192.168.111.250
web1
[root@backup ~]# curl 192.168.111.250
web2

啟動master端的haproxy服務

//master端
[root@master scripts]# systemctl start haproxy
[root@master scripts]# systemctl restart keepalived
[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:50:34:72 brd ff:ff:ff:ff:ff:ff
    inet 192.168.111.141/24 brd 192.168.111.255 scope global dynamic noprefixroute ens33
       valid_lft 1223sec preferred_lft 1223sec
    inet 192.168.111.250/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe50:3472/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

//backup端
[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:07:42:65 brd ff:ff:ff:ff:ff:ff
    inet 192.168.111.142/24 brd 192.168.111.255 scope global dynamic noprefixroute ens33
       valid_lft 1632sec preferred_lft 1632sec
    inet6 fe80::20c:29ff:fe07:4265/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1.什麼是WebFlux? WebFlux不需要Servlet API,在完全非同步且無阻塞,並通過Reactor項目實現了Reactor Streams規範。 WebFlux可以在資源有限的情況下提高系統的吞吐量和伸縮性。 WebFlux除支持Restful Web服務外,還可以用於提供動態HTML ...
  • 作為軟體工程經理,我也會遇到人情世故的難題。最近一位團隊成員提出了離職申請,是因為個人的原因,而且很直接。 1、收到離職申請 我知道他會離職,我很少有措手不及的時候,所以我早就有預感,事實證明我的預感沒錯。幾周前,我就有一種感覺:“該來的遲早會來。”他們提出的問題、他們的疑慮以及他們有時會莫名離開辦 ...
  • 1.使用map()進行函數映射 ✅ Exp1:將字元串數組中的小寫字母轉為大寫字母。 測試數組為 oldlist = ['life', 'is', 'short', 'i', 'choose', 'python']。 方法一 newlist = [] for word in oldlist: new ...
  • 1.需要保證電腦中安裝了protobuf安裝教程 2.如果出現報錯請看博客protobuf報錯問題解決 3.demo地址:demo 簡介: rpc微服務,grpc是一種開源的高性能RPC框架,能夠運行在任何環境中,最初由谷歌進行開發,它使用HTTP2作為傳輸協議。grpc讓客戶端可以像調用本地方法一 ...
  • 使用EF Core的Code First,在設計階段,直接使用Database.EnsureCreated()和EnsureDeleted()可以快速刪除、更新最新的數據結構。由於沒有什麼數據,刪除的風險非常低。但是對於已經投入生產的資料庫,這個方法就絕對不可行了。 考慮以下場景: 項目已經上線,一 ...
  • 一、大家是否有這個需求 1.跨品種查詢 :比如 MYSQL和一個SQLSERVER進行聯表查詢 ,或者SQLITE和MYSQL進行聯表查詢 2.跨伺服器查詢 : A伺服器和B伺服器查詢 如果想同時支持1和2 相信很多人都沒有比較好的解決方案 我的設計是通過多庫架構來實現多庫操作 二、 多庫架構ORM ...
  • 一、概念 委托的本質也是一種類型,類似於Class這樣。作用是將一個方法作為參數傳遞給另一個方法,關鍵字是delegate 二、委托的定義使用步驟 第一步聲明委托: public delegate int myDelegate(int a, int b); 1、聲明一個委托類型,可以用訪問修飾符修飾 ...
  • keepalived高可用(haporxy) keepalived高可用的介紹可以參考keepalived高可用(nginx) 環境 |系統信息| 主機名 |IP |服務| | : | : | : | : | |centos8| master| 192.168.222.250| haproxy,ke ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...