uWSGI 多进程有没有问题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uWSGI 多进程有没有问题相关的知识,希望对你有一定的参考价值。
参考技术A 环境: CentOS X64 6/ftp/python/2/pypi/distribute 方便安装Python的开发包 cd ~ wget https://pypi/packages/source/d/distribute/distribute-0/pypi/pip 安装pip的好处是可以pip list、pip uninstall 管理Python包, easy_install没有这个功能,只有uninstall easy_install pip pip --version 三:安装uwsgi uwsgi:https://pypi/pypi/uWSGI uwsgi参数详解:uwsgi-docs/en/latest/Options/download/nginx-1 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="uwsgi daemon" NAME=uwsgi9090 DAEMON=/usr/local/bin/uwsgi CONFIGFILE=/etc/$NAME.ini PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME set -e [ -x "$DAEMON" ] exit 0 do_start() $DAEMON $CONFIGFILE echo -n "uwsgi already running" do_stop() $DAEMON --stop $PIDFILE echo -n "uwsgi not running" rm -f $PIDFILE echo "$DAEMON STOPED." do_reload() $DAEMON --reload $PIDFILE echo -n "uwsgi can't reload" do_status() ps auxgrep $DAEMON case "$1" in status) echo -en "Status $NAME: n" do_status ;; start) echo -en "Starting $NAME: n" do_start ;; stop) echo -en "Stopping $NAME: n" do_stop ;; reloadgraceful) echo -en "Reloading $NAME: n" do_reload ;; *) echo "Usage: $SCRIPTNAME startstopreload" >&2 exit 3 ;; esac exit 0 然后在终端执行: -- 添加服务 chkconfig --add uwsgi9090 -- 设置开机启动 chkconfig uwsgi9090 on 七:设置nginx 找到nginx的安装目录,打开conf/nginx.conf文件,修改server配置 server listen 80; server_name localhost; location / include uwsgi_params; uwsgi_pass 127.0.0.1:9090; //必须和uwsgi中的设置一致 uwsgi_param UWSGI_SCRIPT demosite.wsgi; //入口文件,即wsgi.py相对于项目根目录的位置,“.”相当于一层目录 uwsgi_param UWSGI_CHDIR /demosite; //项目根目录 index index.html index.htm; client_max_body_size 35m; 设置nginx开机启动,在/ect/init.d/目录下新建nginx文件,内容如下: #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse # proxy and IMAP/POP3 proxy server # processname: nginx # config: /usr/local/nginx/conf/nginx.conf # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/opt/nginx-1.5.6/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/opt/nginx-1.5.6/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx start() [ -x $nginx ] exit 5 [ -f $NGINX_CONF_FILE ] exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval stop() echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval restart() configtest return $? stop sleep 1 start reload() configtest return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo force_reload() restart configtest() $nginx -t -c $NGINX_CONF_FILE rh_status() status $prog rh_status_q() rh_status >/dev/null 2>&1 case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q exit 0 $1 ;; restartconfigtest) $1 ;; reload) rh_status_q exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestarttry-restart) rh_status_q exit 0 ;; *) echo $"Usage: $0 startstopstatusrestartcondrestarttry-restartreloadforce-reloadconfigtest" exit 2 esac 然后在终端执行: -- 添加服务 chkconfig --add nginx -- 设置开机启动 chkconfig nginx on 八:测试 OK,一切配置完毕,在终端运行 service uwsgi9090 start service nginx start 在浏览器输入:127.0.0.1,恭喜你可以看到django的“It work”了~ 九:其他配置 防火墙设置 CentOS默认关闭外部对80、3306等端口的访问,所以要在其他计算机访问这台服务器,就必须修改防火墙配置,打开/etc/sysconfig/iptables 在“-A INPUT –m state --state NEW –m tcp –p –dport 22 –j ACCEPT”,下添加: -A INPUT m state --state NEW m tcp p dport 80 j ACCEPT -A INPUT m state --state NEW m tcp p dport 3306 j ACCEPT 然后保存,并关闭该文件,在终端内运行下面的命令,刷新防火墙配置: service iptables restart 安装mysqldb yum -y install mysql-devel easy_install-2.7 MySQL-python 注意红色部分,easy_install-2.7,否则它将默认安装到Python2.6环境内。CentOS7 uwsgi重启(通过shell脚本获取进程号并kill)
参考技术A uWSGI 通过 xxx.ini 启动后会在相同目录下生成一个 xxx.pid 的文件,里面只有一行内容是 uWSGI 的主进程的进程号。启动:
uwsgi --ini xxx.ini
重启:
uwsgi --reload xxx.pid
停止:
uwsgi --stop xxx.pid
以上是当前网上对于uwsgi重启操作的最常见的描述,但是笔者通过ini文件启动时发现并没有生成xxx.pid文件。于是自然的想法是通过shell脚本获取进程号并进行kill操作,脚本如下:
获取进程号的命令需要包含在``或$()之间,笔者在此过程中遇到过两个问题,描述如下:
中变量未加双引号,加上双引号该问题解决。
以上是关于uWSGI 多进程有没有问题的主要内容,如果未能解决你的问题,请参考以下文章