uwsgi文件配置
- uWSGI支持名为”uwsgi”协议
- uWSGI启动一个单一的进程和一个单一的线程,可以用
--processes
选项添加更多的进程,或者使用 --threads
选项添加更多的线程 (或者可以同时添加)。进程分为master进程,worker进程。
- uwsgitop配置详情:https://github.com/unbit/uwsgitop,我没有配成功,报_curse model错误。
[uwsgi]
# 项目目录
chdir=/data/ip-flow
# 指定IP端口,docker容器内部运行的端口
socket = 127.0.0.1:8001
# 指定项目的application
module = ip_flow.wsgi:application
# 启用主进程,当进程挂掉会再spawn一个(以下三个指标,实现“并发”)
master = true
# 进程个数
processes = 8
# 每个进程中的线程个数/workers
threads = 2
# 一个工作进程最大请求数
max-requests=5000
# 实现“监控”
stats = 127.0.0.1:9191
# 设置日志目录
daemonize = /data/ip-flow/logs/uwsgi.log
# 当文件改变时,优雅的重启uWSGI
touch-reload = /data/ip-flow/wsgi.txt
服务器上的启动脚本
#!/usr/bin/env bash
docker_name=ip-flow
project_path=/home/code/ip-flow
port=8001
image=xiaochonghao/django1.11.1:v2
echo "git tag" $1
echo "project path" ${project_path}
echo "docker name" ${docker_name}
echo "port" ${port}
echo "image" ${image}
cd ${project_path}
git pull
git checkout $1
echo "restart ip-flow service....."
echo "ensure old service start______________________________________"
docker ps
echo 'stop and rm old service'
echo "stop docker " ${docker_name}
docker stop ${docker_name}
echo "docker rm" ${docker_name}
docker rm ${docker_name}
echo "start new service"
docker run -d --name ${docker_name} -p ${port}:80 -v ${project_path}:/data/ip-flow ${image} /bin/sh -c 'sh /data/ip-flow/bin/run.sh;'
docker ps
docker container 启动命令
#!/bin/bash
dev_mode=test
if [ $# -ge 1 ]; then
if [ $1 != 'hk' ] && [ $1 != 'jp' ] && [ $1 != 'test' ]; then
echo 'usage: sh run_task.sh [hk|jp|test]'
exit
fi
if [ $1 == 'hk' ]; then
dev_mode=_hk
elif [ $1 == 'jp' ]; then
dev_mode=_jp
else
dev_mode=""
fi
fi
cat > /etc/nginx/conf.d/default.conf <<EOF
upstream backend {
server 127.0.0.1:8001;
}
server {
listen 80;
server_name localhost;
location / {
# 传递给每一个请求给绑定到8001端口并使用uwsgi协议的服务器
include /etc/nginx/uwsgi_params;
uwsgi_pass backend;
}
# cannot set as '/static/', or will conflict with front
# in the end '/' must be added
location /static/ {
alias /data/ip-flow/static/;
autoindex on;
}
}
EOF
echo "dev_mode=${dev_mode}"
uwsgi --ini /data/ip-flow/bin/uwsgi${dev_mode}.ini
nginx -c /etc/nginx/nginx.conf
tail -f /data/ip-flow/bin/uwsgi${dev_mode}.ini
网友评论