Django上线部署之uWSGI
环境:
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的更多相关文章
- [py]django上线部署-uwsgi+nginx+py3/django1.10
https://github.com/lannyMa/django-uwsgi-nginx.git 单机调试启动-确保项目代码没问题 - 克隆代码进入项目 git clone https://gith ...
- Django【部署】uwsgi+nginx
uwsgi 遵循wsgi协议的web服务器 uwsgi的安装 pip install uwsgi uwsgi的配置 项目部署时,需要把settings.py文件夹下的: DEBUG = FALSE A ...
- Django上线部署之IIS
环境: 1.Windows Server 2016 Datacenter 64位 2.SQL Server 2016 Enterprise 64位 3.Python 3.6.0 64位 4.admin ...
- Django上线部署之Apache
环境: 1.Windows Server 2016 Datacenter 64位 2.SQL Server 2016 Enterprise 64位 3.Python 3.6.0 64位 4.admin ...
- 第四百零二节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署,uwsgi安装和启动,nginx的安装与启动,uwsgi与nginx的配置文件+虚拟主机配置
第四百零二节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署,uwsgi安装和启动,nginx的安装与启动,uwsgi与nginx的配置文件+虚拟主机配置 软件版本 uwsgi- ...
- 玩转Django2.0---Django笔记建站基础十二(Django项目上线部署)
第十二章 Django项目上线部署 目前部署Django项目有两种主流方案:Nginx+uWsGI+Django或者Apache+uWSGI+Django.Nginx作为服务器最前端,负责接收浏览器的 ...
- 五步教你实现使用Nginx+uWSGI+Django方法部署Django程序
Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式. 在这种方式中,我们的通常做法是,将nginx作为服务器最前端,它将接收WEB的所有请求,统一管理请求.ng ...
- debian完整部署 Nginx + uWSGI + Django
手工部署一个Django服务器真心不容易,需要安装很多东西.从头开始搭建服务器,主要是为了梳理一下后续开发中一般为碰到的平台部署.对后续问题的解决有一定帮助. 通常部署有2中方式: 一种是使用现成提供 ...
- 学习VirtualEnv和Nginx+uwsgi用于django项目部署
以下叙述中用到的操作系统:Linux CentOS 6.X. 最近几天了解一下VirtualEnv,Apache+Daemon mode,Nginx+uwsgi的概念,并且在项目中实验性部署了一下(目 ...
随机推荐
- elasticsearch 深入 —— 结构化搜索
结构化搜索 结构化搜索(Structured search) 是指有关探询那些具有内在结构数据的过程.比如日期.时间和数字都是结构化的:它们有精确的格式,我们可以对这些格式进行逻辑操作.比较常见的操作 ...
- 一、WebApi模型验证实践项目使用
一.启语 前面我们说到,模型验证的原理(包含1.项目创建,2.模型创建,3.走通测试模型验证,4.在过滤器中处理返回json格式(非控制器内))-完全是新手理解使用的,新番理解 通常情况下,对于那些经 ...
- update all line start with -- to space
update all line start with -- to space ^--.*$
- 《Spring Boot实战》笔记 (六章)
6.1 基本配置 ........................................................................................... ...
- ubuntu 安装php xdebug
windows 安装xdebug https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html 一.下载 下载与PHP版兼容的Xdeb ...
- Java中的两种异常类型及其区别?
Java中的两种异常类型是什么?他们有什么区别? Throwable包含了错误(Error)和异常(Excetion两类) Exception又包含了运行时异常(RuntimeException, 又 ...
- python基础:8.正则表达式
1.概念 正则表达式是对字符串操作的一种逻辑公式,就是用事先定义好的一些特定字符.及这些特定字符的组合,组成一个“规则字符串”,这个“规则字符串”用来表达对字符串的一种过滤逻辑. re模块的常见方法: ...
- 25-Node.js学习笔记-express-app.locals对象
app.locals对象 将变量设置到app.locals对象下面,这个数据在所有的模板中都可以获取到 app.locals.users=[{ name:'柠檬不酸', age:20 },{ name ...
- pgrep,pidof工具的使用
博客pgrep,pidof工具的使用 最灵活:ps 选项 | 其它命令 按预定义的模式:pgreppgrep [options] pattern-u uid: effective user,生效者-U ...
- visual studio code的使用
1.添加代码片段 参考:https://blog.csdn.net/qq_36370731/article/details/83014439 2.在vscode上运行Git 先打开vscode内置的G ...