nginx带宽资源调度脚本

简介:
#!/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

相关文章
|
7月前
|
应用服务中间件 Shell 开发工具
nginx+shell脚本实现一键启用与关闭停机维护页面
nginx+shell脚本实现一键启用与关闭停机维护页面
134 0
|
Ubuntu 应用服务中间件 Shell
用shell脚本部署nginx
用shell脚本部署nginx
163 2
|
6月前
|
Ubuntu 应用服务中间件 Linux
Linux Centos7 ubuntu 安装nginx,脚本一键安装nginx
Linux Centos7 ubuntu 安装nginx,脚本一键安装nginx
134 2
|
7月前
|
网络协议 应用服务中间件 nginx
nginx 302 301 设置 url 转跳 nginx 资源重定向 nginx tcp 和 http 转发
nginx 代理后端网站,和 网站资源目录重定向到其他连接地址
211 3
|
6月前
|
应用服务中间件 nginx Windows
windows系统bat批处理 管理nginx启动 nginx脚本管理bat脚本管理生命周期windows一键nginx启动
windows系统bat批处理 管理nginx启动 nginx脚本管理bat脚本管理生命周期windows一键nginx启动
122 0
|
7月前
|
弹性计算 应用服务中间件 Shell
一键编译安装Nginx脚本
【4月更文挑战第30天】
183 1
|
7月前
|
弹性计算 应用服务中间件 Shell
编写nginx 启动脚本
【4月更文挑战第29天】
61 1
|
存储 算法 应用服务中间件
Nginx之带宽限制解读
Nginx之带宽限制解读
|
7月前
|
前端开发 应用服务中间件 nginx
使用nginx-http-concat资源请求合并功能 优化网站响应
使用nginx-http-concat资源请求合并功能 优化网站响应
77 0
|
7月前
|
运维 应用服务中间件 Shell
Nginx安装与虚拟主机配置shell脚本
Nginx安装与虚拟主机配置shell脚本
55 0