Linux下uwsgi配置

1.安装
  pip3 install uwsgi
2.新建配置文件
  mkdir /etc/uwsgi
  vim /etc/uwsgi/uwsgi.ini
3.往配置文件中写入内容
  [uwsgi]
  uid = root
  gid = root
  socket = 127.0.0.1:8111 # 项目启动的ip:端口
  master = true //启动主进程
  vhost = true //多站模式
  no-site = true //多站模式时不设置⼊⼝模块和⽂件
  workers = 2 // 进程数
  reload-mercy = 10 //平滑的重启
  vacuum = true //退出、重启时清理⽂件
  max-requests = 1000 //开启10000个进程后, ⾃动respawn下
  limit-as = 512 // 将进程的总内存量控制在512M
  buffer-size = 30000
  pidfile = /var/run/uwsgi8111.pid //pid⽂件,⽤于下⾯的脚本启动、停⽌该进程
  daemonize = /var/log/uwsgi8111.log
  pythonpath = /root/jiangsqobj/lib/python3.6/site-packages // 有虚拟环境就添加虚拟环境 没有就添加python安装路径

4.启动
  方法一
    1.启动
      uwsgi --ini /etc/uwsgi/uwsgi.ini
    2.测试是否启动
      netstat -ntpl
    3.查看进程号
      cat /var/run/uwsgi8111.pid
    4.杀死进程
      kill -9 81392
      killall -9 uwsgi
  方法二
    1.新建配置文件
      vim /etc/init.d/uwsgi
    2.写入启动脚本
      #!/bin/sh
      DESC="uwsgi daemon"
      NAME=uwsgi
      DAEMON=/usr/local/bin/uwsgi
      CONFIGFILE=/etc/uwsgi/${NAME}9090.ini
      PIDFILE=/var/run/$NAME.pid
      SCRIPTNAME=/etc/init.d/$NAME
      FIFOFILE=/tmp/uwsgififo
      set -e
      [ -x "$DAEMON" ] || exit 0
      do_start() {
      if [ ! -f $PIDFILE ];then
      $DAEMON $CONFIGFILE || echo -n "uwsgi running"
      else
      echo "The PID is exist..."
      fi
      }
      do_stop() {
      if [ -f $PIDFILE ];then
      $DAEMON --stop $PIDFILE || echo -n "uwsgi not running"
      rm -f $PIDFILE
      echo "$DAEMON STOPED."
      else
      echo "The $PIDFILE doesn't found"
      fi
      }
      do_reload() {
      if [ -p $FIFOFILE ];then
      echo w > $FIFOFILE
      else
      $DAEMON --touch-workers-reload $PIDFILE || echo -n "uwsgi
      can't reload"
      fi
      }
      do_status() {
      ps aux|grep $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
      ;;
      reload|graceful)
      echo -en "Reloading $NAME: \n"
      do_reload
      ;;
      *)
      echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2
      exit 3
      ;;
      esac
      exit 0
    3.启动
      /etc/init.d/uwsgi start
    4.查看
      netstat -ntpl
      /etc/init.d/uwsgi status
    5.关闭
      /etc/init.d/uwsgi stop

上一篇:CentOS 7安装Redis


下一篇:CentOS安装redis