keepalived+LVS高可用部署

news2024/11/24 12:38:47

目录

一.两台设备(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

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【A-008】基于SSH的员工信息管理系统(含论文)

员工信息管理系统主要功能如下&#xff1a; (1)员工方面&#xff1a; ①人事管理&#xff1a;能够看到自己的基本信息&#xff0c;对自己的合同进行下载&#xff0c;可以看公司的培训信息&#xff1b; ②招聘管理&#xff1a;查看企业的招聘信息&#xff0c;包括应聘者&#x…

基于SpringBoot和Vue的学生笔记共享平台的设计与实现

今天要和大家聊的是一款基于SpringBoot和Vue的学生笔记共享平台的设计与实现 &#xff01;&#xff01;&#xff01; 有需要的小伙伴可以通过文章末尾名片咨询我哦&#xff01;&#xff01;&#xff01; &#x1f495;&#x1f495;作者&#xff1a;李同学 &#x1f495;&…

【Qt】常用控件(输入类)

目录 一、Line Edit二、Text Edit三、ComBo四、DateTimeEdit五、Slider 一、Line Edit QLineEdit 用来表示单行输入框&#xff0c;可以输入一段文本&#xff0c;但是不能换行。 属性说明test输入框中的文本inputMask输入内容格式约束maxLength最大长度frame是否添加边框echoM…

AES加密解密算法

一&#xff0c;AES算法概述 AES属于分组加密&#xff0c;算法明文长度固定为128位&#xff08;单位是比特bit&#xff0c;1bit就是1位&#xff0c;128位等于16字节&#xff09; 而密钥长度可以是128、192、256位 当密钥为128位时&#xff0c;需要循环10轮完成加密&#xff0…

OpenEuler华为欧拉系统安装教程及联网配置

OpenEuler简介 openEuler是一款开源操作系统。当前openEuler内核源于Linux&#xff0c;支持鲲鹏及其它多种处理器&#xff0c;能够充分释放计算芯片的潜能&#xff0c;是由全球开源贡献者构建的高效、稳定、安全的开源操作系统&#xff0c;适用于数据库、大数据、云计算、人工智…

人脸检测项目 | 基于C++在英特尔+ARM-CPU上部署人脸检测算法_推理速度可达1000fps

项目应用场景 面向在英特尔ARM CPU 平台部署轻量级的人脸检测算法&#xff0c;要求人脸检测算法的速度是能够达到实时的的场景&#xff0c;项目采用 C 开发&#xff0c;支持跨平台移植到包括 Linux、Windows 等 项目效果&#xff1a; 项目细节 > 具体参见项目 README.md (1…

【LeetCode: 330. 按要求补齐数组 + 贪心 + 构造区间】

&#x1f680; 算法题 &#x1f680; &#x1f332; 算法刷题专栏 | 面试必备算法 | 面试高频算法 &#x1f340; &#x1f332; 越难的东西,越要努力坚持&#xff0c;因为它具有很高的价值&#xff0c;算法就是这样✨ &#x1f332; 作者简介&#xff1a;硕风和炜&#xff0c;…

linux进程退出之exit与_exit

linux进程退出之exit与_exit _exitexit流程清理函数atexit()函数&#xff1a;on_exit()函数&#xff1a; _exit /* Terminate program execution with the low-order 8 bits of STATUS. */ /** status参数定义了进程的终止状态&#xff0c;父进程可以通过wait&#xff08;&am…

使用open3d分离背景和物体点云

一、代码 方法简单介绍 RANSAC&#xff08;随机采样一致性&#xff09;是一种常用的分割算法&#xff0c;通常用于从点云中分割出最大的平面&#xff08;如地面、墙壁等&#xff09;。RANSAC速度相对较快&#xff0c;特别是当点云数据量不是很大时。在物体与背景之间存在明显…

蓝桥杯 本质上升序列

题目描述: 小蓝特别喜欢单调递增的事物。 在一个字符串中&#xff0c;如果取出若干个字符&#xff0c;将这些字符按照在字符串中的顺序排列后是单调递增的&#xff0c;则成为这个字符串中的一个单调递增子序列。 例如&#xff0c;在字符串 lanqiao 中&#xff0c;如果取出字符…

蓝桥杯省赛刷题——题目 2656:刷题统计

刷题统计OJ链接&#xff1a;蓝桥杯2022年第十三届省赛真题-刷题统计 - C语言网 (dotcpp.com) 题目描述 小明决定从下周一开始努力刷题准备蓝桥杯竞赛。他计划周一至周五每天做 a 道题目&#xff0c;周六和周日每天做 b 道题目。请你帮小明计算&#xff0c;按照计划他将在第几…

Segger Embedded Studio IDE使用体验——默认的Section和Linker的设置

Segger Embedded Studio IDE使用体验之一——默认的Section和Linker的设置 一、简介二、操作2.1 编译后代码分析2.1.1 符号浏览器2.1.2 读取elf文件和map文件 2.2 调试2.2.1 查看变量2.2.2 设置供电 2.3 运行环境设置2.3.1 编译器2.3.2 汇编器2.3.3 包含其他文件2.3.4 .bss和.d…

iOS问题记录 - App Store审核新政策:隐私清单 SDK签名(持续更新)

文章目录 前言开发环境问题描述问题分析1. 隐私清单 & SDK签名1.1. 隐私清单 - 数据使用声明1.2. 隐私清单 - 所用API原因描述1.3. SDK签名 2. 即将发布的第三方SDK要求 解决方案最后 前言 前段时间用Flutter开发的iOS App提交了新版本&#xff0c;结果刚过两分钟就收到了…

基于springboot实现旅游网站系统项目【项目源码+论文说明】计算机毕业设计

基于springboot实现旅游网站系统演示 摘要 随着科学技术的飞速发展&#xff0c;各行各业都在努力与现代先进技术接轨&#xff0c;通过科技手段提高自身的优势&#xff0c;旅游网站当然也不能排除在外&#xff0c;随着旅游网站的不断成熟&#xff0c;它彻底改变了过去传统的旅游…

魔改一个过游戏保护的CE

csdn审核不通过 网易云课堂有配套的免费视频 int0x3 - 主页 文章都传到github了 Notes/外挂/魔改CE at master MrXiao7/Notes GitHub 为什么要编译自己的CE 在游戏逆向的过程中&#xff0c;很多游戏有保护&#xff0c;我们运行原版CE的时候会被检测到 比如我们开着CE运…

【AXIS】AXI-Stream FIFO设计实现(四)——异步时钟

前文介绍了几种同步时钟情况下的AXI Stream FIFO实现方式&#xff0c;一般来说&#xff0c;FIFO也需要承担异步时钟域模块间数据传输的功能&#xff0c;本文介绍异步AXIS FIFO的实现方式。 如前文所说&#xff0c;AXI-Stream FIFO十分类似于FWFT异步FIFO&#xff0c;推荐参考前…

AtCoder Beginner Contest 347 (ABCDEF题)视频讲解

A - Divisible Problem Statement You are given positive integers N N N and K K K, and a sequence of length N N N, A ( A 1 , A 2 , … , A N ) A(A_1,A_2,\ldots,A_N) A(A1​,A2​,…,AN​). Extract all elements of A A A that are multiples of K K K, divi…

2-HDFS常用命令及上传下载流程

HDFS NameNode 安全模式(safemode) 当NameNode被重启的时候&#xff0c;自动进入安全模式 在安全模式中&#xff0c;NameNode首先会触发edits_inprogress文件的滚动。滚动完成之后&#xff0c;更新fsimage文件 更新完成之后&#xff0c;NameNode会将fsimage文件中的元数据加…

新闻管理系统(源码+文档)

新闻管理系统&#xff08;小程序、ios、安卓都可部署&#xff09; 文件包含内容程序简要说明含有功能项目截图客户端新闻详情新闻首页分类退出登录个人中心拨打客服热线注册界面个人资料新闻评论成功 管理端用户管理分类管理新闻管理 文件包含内容 1、搭建视频 2、流程图 3、开…

特征融合篇 | 利用RT-DETR的AIFI去替换YOLOv8中的SPPF(附2种改进方法)

前言:Hello大家好,我是小哥谈。RT-DETR模型是一种用于目标检测的深度学习模型,它基于transformer架构,特别适用于实时处理序列数据。在RT-DETR模型中,AIFI(基于注意力的内部尺度特征交互)模块是一个关键组件,它通过引入注意力机制来增强模型对局部和全局信息的处理能力…