环境:
  1.CentOS 7.2 64位
  2.SQL Server 2016 Enterprise 64位
  3.Python 3.6.5 64位
  4.root用户

要求:
  按照顺序部署

1.Windows Server 2016 Datacenter 64位 操作系统下安装数据库

2.CentOS 7.2 下  Python环境搭建

 yum -y install gcc gcc-c++ zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel tree
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz && tar xf Python-3.6.5.tar.xz
cd Python-3.6. && ./configure --prefix=/opt/python365 --enable-shared && make && make install
/opt/python365/bin/python3. -V && ln -sf /opt/python365/bin/python3. /usr/local/bin/python3 && ln -sf /opt/python365/bin/pip3. /usr/local/bin/pip3
pip3 -V && pip3 install virtualenv && ln -sf /opt/python365/bin/virtualenv /usr/local/bin/virtualenv && pip3 install virtualenvwrapper
pip3 -V && pip3 install ipython && ln -sf /opt/python365/bin/ipython3 /usr/local/bin/ipython
echo "PS1=\"[\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[33;40m\]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> \[\e[36;40m\]\w\[\e[0m\]]\\\\$ \n\"" >> /etc/bashrc
echo "set nu" >> /etc/vimrc
echo "export WORKON_HOME=~/envs" >> /etc/bashrc
echo "export VIRTUALENVWRAPPER_HOOK_DIR=~/envs" >> /etc/bashrc
echo "export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3" >> /etc/bashrc
echo "source /opt/python365/bin/virtualenvwrapper.sh" >> /etc/bashrc

3.安装ODBC for SQL Server

 # 安装ODBC for SQL Server 驱动
# 实际上是安装如下三个包
# https://packages.microsoft.com/rhel/7/prod/unixODBC-2.3.7-1.rh.x86_64.rpm
# https://packages.microsoft.com/rhel/7/prod/msodbcsql-13.1.9.2-1.x86_64.rpm
# https://packages.microsoft.com/rhel/7/prod/unixODBC-devel-2.3.7-1.rh.x86_64.rpm
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
yum remove unixODBC-utf16 unixODBC-utf16-devel
ACCEPT_EULA=Y yum -y install msodbcsql && yum -y install unixODBC-devel # 安装连接数据库的工具,一般项目上用不到,可不安装
ACCEPT_EULA=Y yum install mssql-tools && ln -sf /opt/mssql-tools/bin/bcp /usr/local/bin/bcp && ln -s /opt/mssql-tools/bin/sqlcmd /usr/local/bin/sqlcmd # 以下是Django的settings.py中数据库配置
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'db',
'USER': 'user',
'PASSWORD': 'pwd',
'HOST': 'ip',
'PORT': '',
'OPTIONS': {
'driver': 'ODBC Driver 13 for SQL Server',
},
},
} DATABASE_CONNECTION_POOLING = True

4.安装uwsgi和uwsgitop(查看uwsgi状态的工具,如果使用securecrt 连接centos,终端需设置成 xterm)

 pip install uwsgi uwsgitop && ln -sf /opt/python365/bin/uwsgi /usr/local/bin/uwsgi && ln -sf /opt/python365/bin/uwsgitop /usr/local/bin/uwsgitop
# uwsgi 配置如下:
[uwsgi]
#用户属组ID
gid=
#用户ID
uid=
#启用主进程
master=true
#主进程以root用户启动
master-as-root=true
#4个进程
processes=
#每个进程启用5个线程
threads=
#停止运行后清理动态生成的文件
vacuum=true
#修改当前工作路径,即项目根目录
chdir=/srv/www/
#wsgi文件路径,可以是相对路径(相对chdir),可以是绝对路径
wsgi-file=www/wsgi.py
#采用unixsocket通信
socket=%(chdir)uwsgi.sock
#采用unixsocket通信时,文件权限
chmod-socket=
#配合uwsgitop使用,命令:uwsgitopuwsgi.stats查看uWSGI运行状态
stats=%(chdir)uwsgi.stats
#uwsgi --[reload|stop] uwsgi.pid
pidfile=%(chdir)uwsgi.pid
#以后台模式运行,并且将日志写入文件
daemonize=%(chdir)uwsgi.log
#设置日志文件最大为10MB,最后一次日志输出超过这个值则分割
log-maxsize=
#打印日志添加日期时间前缀
log-date=%%F%%H:%%M:%%S
#禁用请求日志,只记录交互日志和错误日志,请求日志可在nginx中记录
disable-logging=true
#请求日志添加内存和虚拟内存信息,disable-logging是false时生效
#memory-report=true
#Python启用线程,由于GIL的限制,可能没啥用,未测试
enable-threads=true
#socket监听数,不能超过系统中net.core.somaxconn值
listen=
#主进程死了,其它进程一起死
no-orphans=true
#进程请求总数累计超过这个值则重启,用reload-on-as和reload-on-rss替换
#max-requests=
#(单位:MB)进程虚拟内存超过限制则重启
reload-on-as=
#(单位:MB)进程物理内存超过限制则重启
reload-on-rss=
#超时重启进程
harakiri=
#超时重启进程后打印日志
harakiri-verbose=true
#(单位:B)
buffer-size=
#(单位:B)
post-buffering=
#(单位:B)限制HTTP请求体60MB
limit-post=
#静态文件路由
static-map=/static=%(chdir)static
static-map=/media=%(chdir)media

5.安装nginx

 wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar -zxvf nginx-1.16..tar.gz
cd nginx-1.16./ && ./configure --prefix=/opt/nginx --with-http_ssl_module --with-http_gzip_static_module && make && make install
/opt/nginx/sbin/nginx -V && ln -sf /opt/nginx/sbin/nginx /usr/local/bin/nginx # nginx.conf配置如下:
pid logs/nginx.pid;
user chimoph chimoph; worker_processes ;
worker_rlimit_nofile ; events {
use epoll;
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; server_tokens off; sendfile on;
tcp_nopush on;
keepalive_timeout ; limit_conn_zone $binary_remote_addr zone=conn_ip:10m;
limit_req_zone $binary_remote_addr zone=req_ip:10m rate=5r/s;
limit_conn_log_level info;
limit_req_status ; gzip on;
gzip_vary on;
gzip_static on;
gzip_min_length 10k;
gzip_comp_level ;
gzip_http_version 1.0;
gzip_types *; log_format main '$time_iso8601|$http_x_forwarded_for|$remote_addr|$remote_user|'
'$request_length|$body_bytes_sent|$request_time|$upstream_response_time|'
'$status|"$request"|"$http_referer"|"$http_user_agent"'; server {
listen ;
server_name 192.168.70.110;
charset utf-;
client_max_body_size 60M; location /media {
alias /srv/www/media;
access_log logs/static.log main;
expires 30d;
} location /static {
alias /srv/www/static;
access_log logs/static.log main;
expires 30d;
} location / {
uwsgi_pass unix:///srv/www/uwsgi.sock;
include uwsgi_params;
access_log logs/access.log main;
limit_conn conn_ip ;
limit_req zone=req_ip burst=;
} error_page /50x.html;
location = /50x.html {
root html;
}
}
}

6.安装Redis

 wget http://download.redis.io/releases/redis-4.0.14.tar.gz
tar -zxvf redis-4.0..tar.gz && cd redis-4.0. && make && make PREFIX=/opt/redis install
/opt/redis/bin/redis-cli -v && ln -sf /opt/redis/bin/redis-cli /usr/local/bin/redis-cli
/opt/redis/bin/redis-server -v && ln -sf /opt/redis/bin/redis-server /usr/local/bin/redis-server # [redis.conf] 如下
dir /opt/redis/
loglevel notice
logfile redis.log
pidfile redis.pid
timeout
protected-mode yes
bind 127.0.0.1
port
tcp-backlog
tcp-keepalive
databases
daemonize yes
supervised no
save
save
save
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
maxclients
maxmemory 1gb
maxmemory-policy noeviction
slowlog-log-slower-than

7.启动

 redis-server /opt/redis/redis.conf && uwsgi /srv/www/uwsgi.ini && nginx

8.安装supervisor

 yum install epel-release && yum install -y supervisor && systemctl enable supervisord && systemctl start supervisord && systemctl status supervisord

Django上线部署之uWSGI的更多相关文章

  1. [py]django上线部署-uwsgi+nginx+py3/django1.10

    https://github.com/lannyMa/django-uwsgi-nginx.git 单机调试启动-确保项目代码没问题 - 克隆代码进入项目 git clone https://gith ...

  2. Django【部署】uwsgi+nginx

    uwsgi 遵循wsgi协议的web服务器 uwsgi的安装 pip install uwsgi uwsgi的配置 项目部署时,需要把settings.py文件夹下的: DEBUG = FALSE A ...

  3. Django上线部署之IIS

    环境: 1.Windows Server 2016 Datacenter 64位 2.SQL Server 2016 Enterprise 64位 3.Python 3.6.0 64位 4.admin ...

  4. Django上线部署之Apache

    环境: 1.Windows Server 2016 Datacenter 64位 2.SQL Server 2016 Enterprise 64位 3.Python 3.6.0 64位 4.admin ...

  5. 第四百零二节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署,uwsgi安装和启动,nginx的安装与启动,uwsgi与nginx的配置文件+虚拟主机配置

    第四百零二节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署,uwsgi安装和启动,nginx的安装与启动,uwsgi与nginx的配置文件+虚拟主机配置 软件版本  uwsgi- ...

  6. 玩转Django2.0---Django笔记建站基础十二(Django项目上线部署)

    第十二章 Django项目上线部署 目前部署Django项目有两种主流方案:Nginx+uWsGI+Django或者Apache+uWSGI+Django.Nginx作为服务器最前端,负责接收浏览器的 ...

  7. 五步教你实现使用Nginx+uWSGI+Django方法部署Django程序

    Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式. 在这种方式中,我们的通常做法是,将nginx作为服务器最前端,它将接收WEB的所有请求,统一管理请求.ng ...

  8. debian完整部署 Nginx + uWSGI + Django

    手工部署一个Django服务器真心不容易,需要安装很多东西.从头开始搭建服务器,主要是为了梳理一下后续开发中一般为碰到的平台部署.对后续问题的解决有一定帮助. 通常部署有2中方式: 一种是使用现成提供 ...

  9. 学习VirtualEnv和Nginx+uwsgi用于django项目部署

    以下叙述中用到的操作系统:Linux CentOS 6.X. 最近几天了解一下VirtualEnv,Apache+Daemon mode,Nginx+uwsgi的概念,并且在项目中实验性部署了一下(目 ...

随机推荐

  1. struts2的action方法匹配以及通配符的使用

    1. ActionMethod:Action执行的时候并不一定要执行execute方法,可以在配置文件中配置action的时候用"method"属性来指定执行哪个方法,也可以在ur ...

  2. TensorFlow学习——入门篇

    本文主要通过一个简单的 Demo 介绍 TensorFlow 初级 API 的使用方法,因为自己也是初学者,因此本文的目的主要是引导刚接触 TensorFlow 或者 机器学习的同学,能够从第一步开始 ...

  3. python列表解析和生成器表达式

    列表解析作为动态创建列表的强大工具,值得学习. 列表解析技术之前的状况--函数式编程. lambda.filter(), map() enumerate, sorted, any, all, zip ...

  4. shell 单行多行注释

    1. 单行注释 众所周知,#  比如想要注释:echo “ni” # echo "ni" 2. 多行注释: 法一: : << ! 语句1 语句2 语句3 语句4 ! 法 ...

  5. Python3.5-20190503-廖老师-自我笔记

    列表和元组 list1 = [1,4,6,788,345,757]            tuple1 =      (345,234,567,878)         切记你的变量名不能和  hel ...

  6. Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

  7. restful风格接口类型和优点

    从事web开发工作有一小段时间,REST风格的接口,这样的词汇总是出现在耳边,然后又没有完全的理解,您是不是有和我相同的疑问呢?那我们一起来一探究竟吧! 就是用URL定位资源,用HTTP描述操作. 知 ...

  8. FORTRAN和C语言数组循环顺序

    对于数组 A(I,J,K) FORTRAN中的循环次序应该是 K J I C语言的循环次序应该是I J K

  9. 如何在MaxCompute上处理存储在OSS上的开源格式数据

    0. 前言 MaxCompute作为使用最广泛的大数据平台,内部存储的数据以EB量级计算.巨大的数据存储量以及大规模计算下高性能数据读写的需求,对于MaxCompute提出了各种高要求及挑战.处在大数 ...

  10. JS中的作用域及闭包

    1.JS中的作用域 在 es6 出现之前JS中只有全局作用域和函数作用域,没有块级作用域,即 JS 在函数体内有自己的作用域,但是如果不是在函数体的话就全部都是全局作用域.比如在 if.for 等有 ...