keepalived+LVS高可用部署

目录

一.两台设备(2.130和2.133)作为调度器,前主后备

1.部署keepalived

2.修改配置文件准备启动

3.配置keepalived的系统日志并启动

二.模拟调度器掉点和web服务进程丢失

1.调度器掉点

2.当类似于httpd这种网站服务掉点

三.以三种健康检查方式引入演示LVS+keepalived

1.TCP_CHECK

2.HTTP_GET|SSL_GET

3.MISC


一.两台设备(2.130和2.133)作为调度器,前主后备

1.部署keepalived

链接:百度网盘 请输入提取码百度网盘为您提供文件的网络备份、同步和分享服务。空间大、速度快、安全稳固,支持教育网加速,支持手机端。注册使用百度网盘即可享受免费存储空间icon-default.png?t=N7T8https://pan.baidu.com/s/1T0JmFUrKHe0I4htpniGYeg 提取码:dp1j

如下是两台设备都要做的,所以设备hostname有所不同但不影响

[root@localhost ~ ]# tar xvf keepalived-2.2.8.tar.gz -C /usr/local/src/
[root@localhost ~ ]# yum install -y openssl-devel
[root@localhost ~ ]# cd /usr/local/src/keepalived-2.2.8/
[root@localhost keepalived-2.2.8]# yum install -y gcc gcc-c++ make openssl-devel
[root@localhost keepalived-2.2.8]# ./configure --prefix=/usr/local/keepalived \
> --sysconfdir=/etc --sbindir=/usr/sbin --bindir=/usr/bin 
#指定安装、系统配置目录等,有需要的可以自己修改
[root@localhost keepalived-2.2.8]# make && make install  #编译安装
[root@main keepalived-2.2.8]# tree /etc/keepalived/
/etc/keepalived/
├── keepalived.conf.sample
└── samples
    ├── keepalived.conf.conditional_conf
    ├── keepalived.conf.fwmark
    ├── keepalived.conf.HTTP_GET.port
    ├── keepalived.conf.inhibit
    ├── keepalived.conf.IPv6
    ├── keepalived.conf.misc_check
    ├── keepalived.conf.misc_check_arg
    ├── keepalived.conf.PING_CHECK
    ├── keepalived.conf.quorum
    ├── keepalived.conf.sample
    ├── keepalived.conf.SMTP_CHECK
    ├── keepalived.conf.SSL_GET
    ├── keepalived.conf.status_code
    ├── keepalived.conf.track_interface
    ├── keepalived.conf.UDP_CHECK
    ├── keepalived.conf.virtualhost
    ├── keepalived.conf.virtual_server_group
    ├── keepalived.conf.vrrp
    ├── keepalived.conf.vrrp.localcheck
    ├── keepalived.conf.vrrp.lvs_syncd
    ├── keepalived.conf.vrrp.routes
    ├── keepalived.conf.vrrp.rules
    ├── keepalived.conf.vrrp.scripts
    ├── keepalived.conf.vrrp.static_ipaddress
    ├── keepalived.conf.vrrp.sync
    ├── sample.misccheck.smbcheck.sh
    └── sample_notify_fifo.sh
​
1 directory, 28 files
[root@main keepalived-2.2.8]# tree /usr/local/keepalived/
/usr/local/keepalived/
└── share
    ├── doc
    │   └── keepalived
    │       └── README
    ├── man
    │   ├── man1
    │   │   └── genhash.1
    │   ├── man5
    │   │   └── keepalived.conf.5
    │   └── man8
    │       └── keepalived.8
    └── snmp
        └── mibs
​
9 directories, 4 files
[root@main keepalived-2.2.8]# cat /usr/lib/systemd/system/keepalived.service 
[Unit]
Description=LVS and VRRP High Availability Monitor
After=network-online.target syslog.target 
Wants=network-online.target 
Documentation=man:keepalived(8)
Documentation=man:keepalived.conf(5)
Documentation=man:genhash(1)
Documentation=https://keepalived.org
​
[Service]
Type=forking
PIDFile=/run/keepalived.pid
KillMode=process
EnvironmentFile=-/etc/sysconfig/keepalived
ExecStart=/usr/sbin/keepalived  $KEEPALIVED_OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
​
[Install]
WantedBy=multi-user.target
[root@main keepalived-2.2.8]# vim /etc/sysconfig/keepalived 
[root@main keepalived-2.2.8]# tail -1 /etc/sysconfig/keepalived 
KEEPALIVED_OPTIONS="-D -d -S 0"
[root@main keepalived-2.2.8]# vim /etc/rsyslog.conf 
[root@main keepalived-2.2.8]# systemctl restart rsyslog.service 
#服务脚本,但是启动还无法正常完成,继续往下看

2.修改配置文件准备启动

(1)这是主设备

[root@main keepalived]# pwd
/etc/keepalived
[root@main keepalived]#  cp keepalived.conf.sample keepalived.conf #修改此文件,这里只放了修改了的部分
[root@main keepalived]# cat keepalived.conf
! Configuration File for keepalived
​
global_defs {
   #notification_email {
   #  acassen@firewall.loc
   #  failover@firewall.loc
   #  sysadmin@firewall.loc   #这些觉得暂时用不上可以先不管
   #}
   #notification_email_from Alexandre.Cassen@firewall.loc
   #smtp_server 192.168.2.130
   #smtp_connect_timeout 30
   router_id 1    #router_id,主备两个双设备需要不一致
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}
​
vrrp_instance VI_1 {
    state MASTER   #设定类型为master
    interface ens33   #通信网卡名称
    virtual_router_id 1   #虚拟router组id,主备需要一致
    priority 100    #优先级值,主高于备
    advert_int 1
    authentication {
        auth_type PASS  #身份验证,密码也需要主备一致
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.2.100   #要设定的VIP,主备一致
    }
}

(2)备设备

[root@serverc keepalived]# cat keepalived.conf
! Configuration File for keepalived
​
global_defs {
   #notification_email {
   #  acassen@firewall.loc
   #  failover@firewall.loc
   #  sysadmin@firewall.loc
   #}
   #notification_email_from Alexandre.Cassen@firewall.loc
   #smtp_server 192.168.200.1
   #smtp_connect_timeout 30
   router_id 2   #主备不一致
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}
​
vrrp_instance VI_1 {
    state BACKUP   #设定为BACKUP
    interface ens33   #通信网卡名称
    virtual_router_id 1   #组id一致
    priority 80   #优先级要低于主
    advert_int 1
    nopreempt    #非抢占模式
    authentication {
        auth_type PASS   #主备一致
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.2.100   #VIP,主备一致
    }
}

3.配置keepalived的系统日志并启动

[root@main ~]# vim /etc/sysconfig/keepalived   #此文件是自动生成的,修改内容如下
KEEPALIVED_OPTIONS="-D -d -S 0"
[root@main ~]# vim /etc/rsyslog.conf
.# Save boot messages also to boot.log
local7.*                                                /var/log/boot.log
​
# Save keepalived messages also to keepalived.log
local0.*                                                /var/log/keepalived.log
#找准位置添加local0这行
#将这几行取消注释
$ModLoad imudp
$UDPServerRun 514
$ModLoad imtcp
$InputTCPServerRun 514
[root@main ~]# systemctl restart rsyslog.service keepalived.service
[root@main ~]# tail -5 /var/log/keepalived.log   #日志已经产生内容
Mar 27 20:01:48 main Keepalived_vrrp[33409]: Sending gratuitous ARP on ens33 for 192.168.2.100
Mar 27 20:01:48 main Keepalived_vrrp[33409]: Sending gratuitous ARP on ens33 for 192.168.2.100
Mar 27 20:01:48 main Keepalived_vrrp[33409]: Sending gratuitous ARP on ens33 for 192.168.2.100
Mar 27 20:01:48 main Keepalived_vrrp[33409]: Sending gratuitous ARP on ens33 for 192.168.2.100
Mar 27 20:01:48 main Keepalived_vrrp[33409]: Sending gratuitous ARP on ens33 for 192.168.2.100
​
[root@main ~]# ip a| grep ens33 -A3   #并且主设备上的VIP已经生成
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:5d:7f:b7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.130/24 brd 192.168.2.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.2.100/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::bf1e:b2a3:a943:8a6d/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

二.模拟调度器掉点和web服务进程丢失

1.调度器掉点

(1)VIP分配在主设备时,访问到hell

(2)主设备服务器断开、keepalived服务失效

此时VIP备绑定去备设备上了,访问到的内容也变为nihao

[root@main ~]# systemctl stop keepalived.service
[root@serverc keepalived]# ip a | grep ens33 -A1
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:2b:95:b3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.133/24 brd 192.168.2.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.2.100/32 scope global ens33
       valid_lft forever preferred_lft forever

2.当类似于httpd这种网站服务掉点

使用脚本后台运行来保障httpd和keepalived持续运转

[root@main keepalived]# cat testhttpd.sh 
#!/bin/bash
while true; do
    httpdpid=$(ps -C httpd --no-header | wc -l)
    if [ ${httpdpid} -eq 0 ]; then
        systemctl start httpd
        sleep 10
        httpdpid=$(ps -C httpd --no-header | wc -l)
        if [ ${httpdpid} -eq 0 ]; then
            systemctl stop keepalived
        fi
    else
        systemctl restart httpd
    fi
    sleep 10
done
​
[root@main keepalived]# nohup ./testhttpd.sh &
[2] 49373
[root@main keepalived]# nohup: ignoring input and appending output to ‘nohup.out’
^C
[root@main keepalived]# jobs
[1]+  Stopped                 ֌  (wd: ~)
[2]-  Running                 nohup ./testhttpd.sh &
​
[root@main keepalived]# systemctl stop httpd  #手动停掉后过几秒又将其启动起来了
[root@main keepalived]# ps -C httpd
   PID TTY          TIME CMD
[root@main keepalived]# ps -C httpd
   PID TTY          TIME CMD
 51258 ?        00:00:00 httpd
 51259 ?        00:00:00 httpd
 51261 ?        00:00:00 httpd
 51262 ?        00:00:00 httpd
 51263 ?        00:00:00 httpd
 51264 ?        00:00:00 httpd
 51288 ?        00:00:00 httpd

三.以三种健康检查方式引入演示LVS+keepalived

主设备-192.168.2.130

备设备-192.168.2.133

VIP-192.168.2.100

RS1-192.168.2.131

RS2-192.168.2.132

1.TCP_CHECK

(1)主设备配置

[root@main keepalived]# cat keepalived.conf
! Configuration File for keepalived
​
global_defs {
   #notification_email {
   #  acassen@firewall.loc
   #  failover@firewall.loc
   #  sysadmin@firewall.loc
   #}
   #notification_email_from Alexandre.Cassen@firewall.loc
   #smtp_server 192.168.2.130
   #smtp_connect_timeout 30
   router_id 1
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}
​
vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 1
    mcast_src_ip 192.168.2.130
    priority 100
    advert_int 1
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.2.100
    }
}
​
virtual_server 192.168.2.100 80 {         #VIP
    delay_loop 6   #健康检查间隔时间
    lb_algo rr   #调度方式为rr
    lb_kind DR   #LVS模式为DR
    protocol TCP   #TCP协议
​
    real_server 192.168.2.131 80 {   #RIP1
        weight 1    #权重值
        TCP_CHECK {     #TCP_CHECK方式
            connect_timeout 3  #连接超时时间
            nb_get_retry 3   #重连次数
            connection_port 80   #检查端口
            delay_before_retry 3   #重连间隔时间
        }
    }
    real_server 192.168.2.132 80 {   #RIP2
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            connection_port 80
            delay_before_retry 3
        }
     }
}
[root@main keepalived]# systemctl restart keepalived.service

(2)备设备配置

[root@serverc keepalived]# cat keepalived.conf
! Configuration File for keepalived
​
global_defs {
   #notification_email {
   #  acassen@firewall.loc
   #  failover@firewall.loc
   #  sysadmin@firewall.loc
   #}
   #notification_email_from Alexandre.Cassen@firewall.loc
   #smtp_server 192.168.200.1
   #smtp_connect_timeout 30
   router_id 2
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}
​
vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 1
    priority 80
    advert_int 1
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.2.100
    }
}
​
virtual_server 192.168.2.100 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP
​
    real_server 192.168.2.131 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
        nb_get_retry 3
            connection_port 80
            delay_before_retry 3
        }
    }
    real_server 192.168.2.132 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            connection_port 80
            delay_before_retry 3
        }
     }
}
[root@serverc keepalived]# systemctl restart keepalived.service

(3)节点执行lvs-dr脚本服务,来进行绑定VIP和添加通信路由,这步可以手动做,参考前面lvs-dr集群的文章

[root@servera ~]# vim /etc/init.d/lvs-dr
[root@servera ~]# cat /etc/init.d/lvs-dr   #VIP等需要自己更改
#!/bin/bash
LOCK=/var/lock/ipvsadm.lock
VIP=192.168.2.100
. /etc/rc.d/init.d/functions
start() {
    PID=`ifconfig | grep lo:130 | wc -l`
    if [ $PID -ne 0 ];
    then
        echo "The LVS-DR-RIP Server is already running !"
    else
        /sbin/ifconfig lo:130 $VIP netmask 255.255.255.255 broadcast $VIP up
        /sbin/route add -host $VIP dev lo:130
        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/ens33/arp_ignore
        echo "2" >/proc/sys/net/ipv4/conf/ens33/arp_announce
        echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
        echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
        /bin/touch $LOCK
        echo "starting LVS-DR-RIP server is ok !"
    fi
}
stop() {
    /sbin/route del -host $VIP dev lo:130
    /sbin/ifconfig lo:130 down >/dev/null
    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/ens33/arp_ignore
    echo "0" >/proc/sys/net/ipv4/conf/ens33/arp_announce
    echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
    echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
    rm -rf $LOCK
    echo "stopping LVS-DR-RIP server is ok !"
}
status() {
    if [ -e $LOCK ];
    then
        echo "The LVS-DR-RIP Server is already running !"
    else
        echo "The LVS-DR-RIP Server is not running !"
    fi
}
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    status)
        status
        ;;
    *)
        echo "Usage: $1 {start|stop|restart|status}"
        exit 1
esac
exit 0
​
[root@servera ~]# systemctl daemon-reload
[root@servera ~]# service lvs-dr start
[root@servera ~]# route -n   #通信路由添加成功
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.2.1     0.0.0.0         UG    100    0        0 ens33
192.168.2.0     0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.2.100   0.0.0.0         255.255.255.255 UH    0      0        0 lo
[root@servera ~]# ip a| grep lo   #环回创建成功
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
    inet 192.168.2.100/32 brd 192.168.2.100 scope global lo:130
    inet 192.168.2.131/24 brd 192.168.2.255 scope global noprefixroute ens33

(4)主设备上查看VIP是否创建成功

[root@main keepalived]# ip a | grep ens33 -A1
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:5d:7f:b7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.130/24 brd 192.168.2.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.2.100/32 scope global ens33
       valid_lft forever preferred_lft forever
[root@main keepalived]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.2.100:80 rr
  -> 192.168.2.131:80             Route   1      0          0         
  -> 192.168.2.132:80             Route   1      0          0      

(5)进行测试

负载均衡测试

[root@localhost ~]# for ((i=1;i<=10;i++));do curl 192.168.2.100;done
10.0.0.12
10.0.0.11
10.0.0.12
10.0.0.11
10.0.0.12
10.0.0.11
10.0.0.12
10.0.0.11
10.0.0.12
10.0.0.11

节点131上httpd服务掉点,具体可以通过watch ipvsadm -Ln来查看节点剔除和恢复过程

[root@localhost ~]# for ((i=1;i<=10;i++));do curl 192.168.2.100;done
10.0.0.12
10.0.0.12
10.0.0.12
10.0.0.12
10.0.0.12
10.0.0.12
10.0.0.12
10.0.0.12
10.0.0.12
10.0.0.12

主调度器设备130掉点

[root@main keepalived]# systemctl stop keepalived.service
[root@serverc keepalived]# ip a | grep ens33 -A1
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:2b:95:b3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.133/24 brd 192.168.2.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.2.100/32 scope global ens33
       valid_lft forever preferred_lft forever
[root@localhost ~]# for ((i=1;i<=10;i++));do curl 192.168.2.100;done
10.0.0.11
10.0.0.12
10.0.0.11
10.0.0.12
10.0.0.11
10.0.0.12
10.0.0.11
10.0.0.12
10.0.0.11
10.0.0.12
#负载均衡正常

2.HTTP_GET|SSL_GET

以genhash来生成检查摘要信息

[root@main keepalived]# genhash -s 192.168.2.131 -p 80 -u /index.html
db1dd528b0e0c9a347eda778aec00559
[root@main keepalived]# genhash -s 192.168.2.132 -p 80 -u /index.html
27d4c8a485f28559e9b1737702b40225
​
#如下配置
virtual_server 192.168.2.100 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP
​
    real_server 192.168.2.131 80 {
        weight 1
#        TCP_CHECK {
#            connect_timeout 3
#            nb_get_retry 3
#            connection_port 80
#            delay_before_retry 3
#        }
        HTTP_GET {
            url {
                path /index.html
                digset 2d4074c5771f087dd468d1960185f1f5
            }
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }   
    }
    real_server 192.168.2.132 80 {
        weight 1
#        TCP_CHECK {
#            connect_timeout 3
#            nb_get_retry 3
#            connection_port 80
#            delay_before_retry 3
#        }
        HTTP_GET {
            url {
                path /index.html
                digset 2d4074c5771f087dd468d1960185f1f5  #基于页面后端hash值
                #status 200   #基于返回状态码
            }   
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}
#重启keepalived后测试

测试

[root@localhost ~]# for ((i=1;i<=10;i++));do curl 192.168.2.100;done   #负载均衡
10.0.0.12
10.0.0.11
10.0.0.12
10.0.0.11
10.0.0.12
10.0.0.11
10.0.0.12
10.0.0.11
10.0.0.12
10.0.0.11
[root@localhost ~]# for ((i=1;i<=10;i++));do curl 192.168.2.100;done  #节点1掉点
10.0.0.12
10.0.0.12
10.0.0.12
10.0.0.12
10.0.0.12
10.0.0.12
10.0.0.12
10.0.0.12
10.0.0.12
10.0.0.12
​
​
[root@main keepalived]# systemctl stop keepalived.service   #主设备掉点,负载均衡正常
[root@serverc keepalived]# ip a |grep ens33 -A1
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:2b:95:b3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.133/24 brd 192.168.2.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.2.100/32 scope global ens33
       valid_lft forever preferred_lft forever
[root@localhost ~]# for ((i=1;i<=10;i++));do curl 192.168.2.100;done
10.0.0.11
10.0.0.12
10.0.0.11
10.0.0.12
10.0.0.11
10.0.0.12
10.0.0.11
10.0.0.12
10.0.0.11
10.0.0.12

3.MISC

利用健康测试脚本来测试httpd服务

real_server 192.168.2.131 80 {
        weight 1
        MISC_CHECK {
            misc_path "/etc/keepalived/test.sh 192.168.2.131"
            misc_timeout 3
​
        }
#        TCP_CHECK {
#            connect_timeout 3
#            nb_get_retry 3
#            connection_port 80
#            delay_before_retry 3
#        }
#        HTTP_GET {
#           url {
#                path /index.html
#                digset 2d4074c5771f087dd468d1960185f1f5
#               status 200
#            }
#            connect_port 80
#           connect_timeout 3
#           nb_get_retry 3
#            delay_before_retry 3
#        }
    }
[root@main keepalived]# cat test.sh    #只针对200状态码
#!/bin/bash
if [ $# -ne 1 ]
then
    echo "You should supply an url parameter."
    exit 1
else
    n=`curl -I "$1" 2> /dev/null | grep "200 OK" | wc -l`
    if [ $n -eq 1 ]
    then
        exit 0
    else
        exit 1
    fi
fi
​
[root@main keepalived]# cat test.sh   #可以使用nmap来做,yum install -y nmap
#!/bin/bash
if [ $# -ne 1 ]
then
        echo "You should supply an url parameter."
        exit 1
else
        ip_and_path=$1
        ip=$(echo "$ip_and_path" | sed 's/.*\/\/\([0-9.]*\).*/\1/')
        n=$(nmap -p80 "$ip" | awk '/^80\/tcp/ {print $2}')
        if [ $n == 'open' ]
        then
                exit 0
        else
                exit 1
        fi
fi

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/505637.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【从前端入门到全栈】前端框架之核心概念

大家好&#xff0c;我是江辰&#xff0c;从前端入门到全栈是我全新系列文章&#xff0c;从去年一直囔囔着要写&#xff0c;今年总算开始了&#xff01;预计在10篇左右。知识面从 前端&#xff0c;后端&#xff0c;运维&#xff0c;脚本等&#xff0c;都有涉及&#xff0c;主打一…

Spark-Scala语言实战(9)

之前的文章中&#xff0c;我们学习了如何在spark中使用RDD方法的flatMap,take,union。想了解的朋友可以查看这篇文章。同时&#xff0c;希望我的文章能帮助到你&#xff0c;如果觉得我的文章写的不错&#xff0c;请留下你宝贵的点赞&#xff0c;谢谢。 Spark-Scala语言实战&am…

数据分析web可视化神器---streamlit框架,无需懂前端也能搭建出精美的web网站页面

✨✨ 欢迎大家来到景天科技苑✨✨ &#x1f388;&#x1f388; 养成好习惯&#xff0c;先赞后看哦~&#x1f388;&#x1f388; 所属的专栏&#xff1a;数据分析系统化教学&#xff0c;零基础到进阶实战 景天的主页&#xff1a;景天科技苑 文章目录 Streamlit什么是streamli…

基于springboot+vue实现的学校田径运动会管理系统

作者主页&#xff1a;Java码库 主营内容&#xff1a;SpringBoot、Vue、SSM、HLMT、Jsp、PHP、Nodejs、Python、爬虫、数据可视化、小程序、安卓app等设计与开发。 收藏点赞不迷路 关注作者有好处 文末获取源码 技术选型 【后端】&#xff1a;Java 【框架】&#xff1a;spring…

CommunityToolkit.Mvvm----配置

一、介绍&#xff1a; CommunityToolkit.Mvvm 包&#xff08;又名 MVVM 工具包&#xff0c;以前称为 Microsoft.Toolkit.Mvvm&#xff09;是一个现代、快速和模块化的 MVVM 库。 它是 .NET 社区工具包的一部分&#xff0c;围绕以下原则生成&#xff1a; 独立于平台和运行时 - …

MySQL MHA高可用配置以及故障切换

目录 什么是 MHA 什么是 MHA MHA&#xff08;MasterHigh Availability&#xff09;是一套优秀的MySQL高可用环境下故障切换和主从复制的软件。 MHA 的出现就是解决MySQL 单点的问题。解决主从架构中的主服务器的单点问题 MySQL故障切换过程中&#xff0c;MHA能做到0-30秒内自动…

计算机网络:数据链路层 - 封装成帧 透明传输 差错检测

计算机网络&#xff1a;数据链路层 - 封装成帧 & 透明传输 & 差错检测 数据链路层概述封装成帧透明传输差错检测 数据链路层概述 从数据链路层来看&#xff0c;主机 H1 到 H2 的通信可以看成是在四段不同的链路上的通信组成的&#xff0c;所谓链路就是从一个节点到相邻…

python distribute是什么

Python的包管理工具常见的有easy_install, setuptools, 还有pip, distribute&#xff0c;那麽这几个工具有什么关系呢&#xff0c;看一下下面这个图就明白了&#xff1a; 可以看到distribute是setuptools的替代方案&#xff0c;pip是easy_install的替代方案。 Distribute提供一…

古代书法名家墨迹范本,中国法书碑帖图片合集

一、图片描述 在书法作品里&#xff0c;什么是法书&#xff1f;这是书法用语&#xff0c;又称法帖&#xff0c;学习书法可以作为楷模的范本&#xff0c;以及对古代名家墨迹的敬称&#xff0c;或以此誉称表达对书法作者的尊重之意&#xff0c;法书墨迹是最能反映古代书法艺术面…

Windows-安装infercnv包(自备)

目录 安装基础 ①安装JAGS a,找到适配版本 b&#xff0c;install for me only安装路径 ②安装"rjags"包 ③安装inferCNV 安装基础 版本&#xff1a; R version 4.2.2 (2022-10-31 ucrt) -- "Innocent and Trusting"安装的JAGS版本为JAGS 4.3.1 首…

Nginx_简介 + Linux系统下详细安装教程指路

安装教程指路 可参看该视频【尚硅谷Nginx教程&#xff08;亿级流量nginx架构设计&#xff09;】 https://www.bilibili.com/video/BV1yS4y1N76R/?p2&share_sourcecopy_web&vd_source4c2f33f3ba1a0dd45bfdf574befd0069 的p2-p7。从安装centos虚拟机到在虚拟机上安装ng…

考研数学|听完一遍汤家凤基础,1800都没思路,怎么办?

看了我这篇回答&#xff0c;保证你可以顺利的做1800题&#xff01; 如果你听了汤家凤老师的课&#xff0c;但是做题没思路&#xff0c;请不要担心&#xff0c;也不要急着换老师&#xff0c;你很有可能是方法错了。 请你反思一下&#xff1a; 1、你是不是听完课立刻就去做题。…

Qt QWebSocket讲解

QWebSocket 是 Qt 框架中用于处理 WebSocket 通信的类。WebSocket 是一种在单个 TCP 连接上进行全双工通信的协议。这使得客户端和服务器之间可以进行实时交互&#xff0c;而无需频繁地建立和关闭连接。 QWebSocket 的基本使用 创建 QWebSocket 对象&#xff1a; 你可以创建一个…

LoRa物联网行业解决方案 1

1 行业应用 智慧停车 智能抄表 智慧牧场 智能生产 智能物流 智能健康 2 物联网智慧农场项目需求 3 为什么选lora&#xff1f; 4 设计 5 模块性能参数 sx1278 lora扩频无线模块 SEMTECH公司SX1278芯片 LoRa 扩频技术 通信距离10000米 SPI通信接口 mcu选型 硬件平台介绍 …

【Java多线程】7——阻塞队列线程池

7 线程池 ⭐⭐⭐⭐⭐⭐ Github主页&#x1f449;https://github.com/A-BigTree 笔记仓库&#x1f449;https://github.com/A-BigTree/tree-learning-notes 个人主页&#x1f449;https://www.abigtree.top ⭐⭐⭐⭐⭐⭐ 如果可以&#xff0c;麻烦各位看官顺手点个star~&#x…

卷积篇 | 引入可改变核卷积AKConv:具有任意采样形状和任意数目参数的卷积核

前言:Hello大家好,我是小哥谈。可改变核卷积(AKConv)是一种深度学习中的卷积神经网络(CNN)结构,它可以根据需要自适应地改变其卷积核。AKConv相对于传统的卷积神经网络,具有更高的灵活性和适应性,可以在不同的任务和数据集上实现更好的性能。🌈 目录 🚀1…

【SpringBoot】-- Spring Validation参数校验框架

SPringle Validation是Spring提供的一个参数校验框架&#xff0c;使用预定义的注解完成参数校验。 一、自定义参数校验 1、引入Spring Valiation依赖 <!-- validation依赖--><dependency><groupId>org.springframework.boot</groupId><arti…

提升 RAG 效果的实践

提升 RAG 效果的实践 0. 引言1. 测试数据2. cohere/embed-multilingual-v3.0 的几组测试结果2-1. 第1组测试2-2. 第2组测试 3. BAAI/bge-m3 的几组测试结果3-1. 第1组测试 0. 引言 AI 大语言模型的主要应用方式之一就是 RAG&#xff0c;接下来计划陆续分享工作中提升 RAG 效果…

数据库之迁移常规操作(Mongodb篇)

一、部署mongodb数据库。 注&#xff1a;采用docker容器进行安装 部署详情参考此文 》》https://blog.csdn.net/u014642921/article/details/136022683 二、在admin用户创建testdb文档插入两条数据 admin> db.testdb.insertMany([{name:"1",age:1,addr:"…

【IP组播】PIM-SM的RP、RPF校验

目录 一&#xff1a;PIM-SM的RP 原理概述 实验目的 实验内容 实验拓扑 1.基本配置 2.配置IGP 3.配置PIM-SM和静态RP 4.配置动态RP 5.配置Anycast RP 二&#xff1a; RPF校验 原理概述 实验目的 实验内容 实验拓扑 1.基本配置 2.配置IGP 3.配置PIM-DM 4.RPF校…