需求:nginx负载的2他机器,有一台可能会因为更新出现404 403诸如此类错误,如果发现,就将请求转发到其他机器,保证用户访问正常,恢复后再加入负载队列。并重启nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#!/bin/bash #nginx状态监测 #byshooter url1=http://192.168.6.192:8088 url2=http://192.168.6.198:5555 check_http_one(){ status_one=$(curl -m 5 -s -I $url1 | grep HTTP | awk '{print $2}') } check_http_two(){ status_two=$(curl -m 5 -s -I $url2 | grep HTTP | awk '{print $2}') } check_http_one check_http_two if [ "$status_one" != "200" ];then sed -i '/192.168.6.192/s/^/#&/' /usr/local/nginx/conf/conf.d/www.shooter.com.conf else sed -i '/192.168.6.192/s/^#//' /usr/local/nginx/conf/conf.d/www.shooter.com.conf fi if [ "$status_two" != "200" ];then sed -i '/192.168.6.198/s/^/#&/' /usr/local/nginx/conf/conf.d/www.shooter.com.conf else sed -i '/192.168.6.198/s/^#//' /usr/local/nginx/conf/conf.d/www.shooter.com.conf fi /usr/local/nginx/sbin/nginx -s reload > /dev/null |
- 本文固定链接: https://www.yoyoask.com/?p=2092
- 转载请注明: shooter 于 SHOOTER 发表