博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx带宽资源调度脚本
阅读量:6446 次
发布时间:2019-06-23

本文共 5461 字,大约阅读时间需要 18 分钟。

#!/bin/env bash

#Usage: total web pv.

#add crontab

#0 * * * * /usr/local/scripts/download_create_nginx.sh

#add /etc/hosts 10.200.0.20 opscenter.dalegames.com

#http://opscenter.dalegames.com/backend/idcdataapi.php?get

#Created by cs.zhang <liangliang.yu@dalegames.com> 2013-01-09

#Last Modified:


#get nginx weight

idc_api=`curl -s http://opscenter.dalegames.com/backend/idcdataapi.php?get`


#get download data(download1=SHT01,download2=JHT,download3=dnion)

echo ${idc_api} | sed 's/<br>/\n/g' > nginx_weight

download1=`sed -n "/SHT01/p" nginx_weight | awk -F":" '{print $2}'`

download2=`sed -n "/JHT/p" nginx_weight | awk -F":" '{print $2}'`

download3=`sed -n "/dnion/p" nginx_weight | awk -F":" '{print $2}'`


cat > /usr/local/nginx/conf/vhosts/alldownload.dalegames.com.conf << "EOF"

upstream download_control {

   server 127.0.0.1:81 weight=ngxdownload1 max_fails=2 fail_timeout=5s;

   server 127.0.0.1:82 weight=ngxdownload2 max_fails=2 fail_timeout=5s;

   server 127.0.0.1:83 weight=ngxdownload3 max_fails=2 fail_timeout=5s;


   check interval=3000 rise=2 fall=5 timeout=1000;

}


server {

    server_name alldownload.dalegames.com;

    listen 80;


    proxy_set_header Host $host;

    proxy_set_header X-Real-IP  $remote_addr;

    proxy_set_header X-Forwarded-For  $remote_addr;

    access_log /home/logs/nginx/alldownload.dalegames.com.access.log main;

    error_log  /home/logs/nginx/alldownload.dalegames.com.error.log error;


    location / {

        valid_referers none blocked *.dalegames.com *.dalegames.net *.dalegames.cn;

        if ($invalid_referer){

                return 403;

        }

        proxy_pass http://download_control;

        }


    location ~* \.svn/ {

        deny all;

        }


}


server {

    server_name _;

    listen 81;


    proxy_set_header Host $host;

    proxy_set_header X-Real-IP  $remote_addr;

    proxy_set_header X-Forwarded-For  $remote_addr;


    location / {

        rewrite ^(.*)$ http://download1.dalegames.com$1 break; #SHT01

        }

}


server {

    server_name _;

    listen 82;


    proxy_set_header Host $host;

    proxy_set_header X-Real-IP  $remote_addr;

    proxy_set_header X-Forwarded-For  $remote_addr;


    location / {

        rewrite ^(.*)$ http://download2.dalegames.com$1 break; #JHT

        }

}


server {

    server_name _;

    listen 83;


    proxy_set_header Host $host;

    proxy_set_header X-Real-IP  $remote_addr;

    proxy_set_header X-Forwarded-For  $remote_addr;


    location / {

        rewrite ^(.*)$ http://download3.dalegames.com$1 break; #dnion

        }

}


EOF


sed -i -e "s/ngxdownload1/${download1}/" /usr/local/nginx/conf/vhosts/alldownload.dalegames.com.conf

sed -i -e "s/ngxdownload2/${download2}/" /usr/local/nginx/conf/vhosts/alldownload.dalegames.com.conf

sed -i -e "s/ngxdownload3/${download3}/" /usr/local/nginx/conf/vhosts/alldownload.dalegames.com.conf


service nginx configtest

if [ $? -ne 0 ]; then echo "Error: nginx conf fault!"; exit 127; fi

service nginx reload


exit 0

#!/bin/env bash
#Usage: total web pv.
#add crontab
#0 * * * * /usr/local/scripts/download_create_nginx.sh
#add /etc/hosts 10.200.0.20 opscenter.dalegames.com
#http://opscenter.dalegames.com/backend/idcdataapi.php?get
#Created by cs.zhang <liangliang.yu@dalegames.com> 2013-01-09
#Last Modified:

#get nginx weight
idc_api=`curl -s http://opscenter.dalegames.com/backend/idcdataapi.php?get`

#get download data(download1=SHT01,download2=JHT,download3=dnion)
echo ${idc_api} | sed 's/<br>/\n/g' > nginx_weight
download1=`sed -n "/SHT01/p" nginx_weight | awk -F":" '{print $2}'`
download2=`sed -n "/JHT/p" nginx_weight | awk -F":" '{print $2}'`
download3=`sed -n "/dnion/p" nginx_weight | awk -F":" '{print $2}'`

cat > /usr/local/nginx/conf/vhosts/alldownload.dalegames.com.conf << "EOF"
upstream download_control {


   server 127.0.0.1:81 weight=ngxdownload1 max_fails=2 fail_timeout=5s;
   server 127.0.0.1:82 weight=ngxdownload2 max_fails=2 fail_timeout=5s;
   server 127.0.0.1:83 weight=ngxdownload3 max_fails=2 fail_timeout=5s;

   check interval=3000 rise=2 fall=5 timeout=1000;
}

server {

    server_name alldownload.dalegames.com;
    listen 80;

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For  $remote_addr;
    access_log /home/logs/nginx/alldownload.dalegames.com.access.log main;
    error_log  /home/logs/nginx/alldownload.dalegames.com.error.log error;

    location / {

        valid_referers none blocked *.dalegames.com *.dalegames.net *.dalegames.cn;
        if ($invalid_referer){

                return 403;
        }
        proxy_pass http://download_control;
        }

    location ~* \.svn/ {

        deny all;
        }

}

server {

    server_name _;
    listen 81;

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For  $remote_addr;

    location / {

        rewrite ^(.*)$ http://download1.dalegames.com$1 break; #SHT01
        }
}

server {

    server_name _;
    listen 82;

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For  $remote_addr;

    location / {

        rewrite ^(.*)$ http://download2.dalegames.com$1 break; #JHT
        }
}

server {

    server_name _;
    listen 83;

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For  $remote_addr;

    location / {

        rewrite ^(.*)$ http://download3.dalegames.com$1 break; #dnion
        }
}

EOF

sed -i -e "s/ngxdownload1/${download1}/" /usr/local/nginx/conf/vhosts/alldownload.dalegames.com.conf
sed -i -e "s/ngxdownload2/${download2}/" /usr/local/nginx/conf/vhosts/alldownload.dalegames.com.conf
sed -i -e "s/ngxdownload3/${download3}/" /usr/local/nginx/conf/vhosts/alldownload.dalegames.com.conf

service nginx configtest
if [ $? -ne 0 ]; then echo "Error: nginx conf fault!"; exit 127; fi
service nginx reload

exit 

本文转自  亮公子  51CTO博客,原文链接:http://blog.51cto.com/iyull/1864388

转载地址:http://mivwo.baihongyu.com/

你可能感兴趣的文章
Machine Learning 机器学习笔记
查看>>
前端面试之webpack面试常见问题
查看>>
微信小程序wepy框架资源汇总
查看>>
自定义input上传图片组件
查看>>
正则表达式在iOS开发中的应用
查看>>
简单、快速生成文档的工具 EasyDoc 版本 2.0.1 发布
查看>>
MYSQL分区
查看>>
非顺序数据结构——字典
查看>>
python奇遇记:隐藏的python功能
查看>>
dgate新特性:EventBusBridge Mock
查看>>
卡尔曼滤波
查看>>
Angular中的动态组件加载
查看>>
vue.js 移动端音乐app(一) 基础组件 scroll
查看>>
java高并发之从零到放弃(二)
查看>>
ngModule中的entryComponents是什么?
查看>>
mint-ui之三级联动
查看>>
Vue 2.5 is coming
查看>>
【ElasticSearch】ElasticSearch安装IK中文分词器
查看>>
部署web项目的过程记录,包括laravel,redis,mongodb,workerman的配置过程
查看>>
你需要了解的一些web前端常见概念整理
查看>>