nginx带宽资源调度脚本
2016-10-21 19:05
393 查看
#!/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
#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
相关文章推荐
- 脚本之家因服务器资源紧张 换了ip并升级了带宽
- nginx静态服务器静态资源发布脚本
- 使用shell脚本进行服务器系统监控——页面调度与交换空间监控
- 在Linux使用脚本实现TC控制少数人的下载带宽,如果是网管,正好用得着。
- 一个脚本学习资源下载站pcjc8.com
- 脚本引擎资源
- nginx启动脚本
- 迅雷API接口_通过脚本调用迅雷自动下载资源
- 优化asp.net ajax的脚本资源下载
- nginx的启动脚本
- Nginx 启动、停止服务的脚本
- JavaScript脚本资源分类
- 关于使用脚本请求服务器端资源无法缓存的问题
- ILOG JViews Gantt(甘特图应用)- 交互式的资源计划和进程调度显示
- 传奇自动刷怪脚本,节省服务器资源
- 对于Asp.Net 2.0中脚本资源的研究(1)
- 在MastPage中引用脚本资源
- 在Web Control中用资源保存java script脚本
- ASP.NET AJAX 资源脚本压缩的秘密
- 方便用户共享资源,在域内通过脚本给域内计算机映射网络驱动器(打印机)