部署python django程序

在一台新的服务器上x须要先安装python3  ,git , 等html

安装python3

安装python3 以前博客写过python

建立虚拟环境,我用的是venv

https://docs.python.org/3/library/venv.htmlmysql

首先建立一个空目录linux

python3 -m venv DIR

在linux 启动虚拟环境是nginx

source bin/activate

pip3安装各类Python包git

pip3 install -r requirements.txtsql

note: requirements.txt 这个文件名不必定非是这个,只要内容符合要求就行django

关于生成这个文件  的命令是vim

pip freeze > FILENAME.txtcentos

 

退出虚拟环境

deactivate

linux安装mysql

参考

 http://www.runoob.com/mysql/mysql-install.html

yum install -y mysql

yum install -y mysql-server

yum install -y devel

启动

service mysqld start



部署nginx 和uwsgi

安装uwsgi
pip3 install uwsgi

安装nginx
yum install nginx
在执行这个命令后发现错误信息, no valid packages nginx
red hat/centos 发行版下,看过望山各类答案仍是找不到
故记录一下
求助于nginx 官网

https://nginx.org/en/linux_packages.html#stable

按照官网的命令,
先建立一个文件
vim /etc/yum.repos.d/nginx.repo

uwsgi 连接  https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html


To set up the yum repository for RHEL/CentOS, create the file named with the following contents:
在这个文件下写入/etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1

 

标红部分要根据你的操做系统版原本改
Replace “” with “” or “”, depending on the distribution used,
and “” with “” or “”, for 6.x or 7.x versions, respectively.
翻译是:
将用rhel 或者centos 来替代'OS' ,这个取决于你的发行版,用6或者7来替代 “”
这个取决因而6.x 仍是7.x
改完以后保存退出
再执行命令OSrhelcentosOSRELEASE67OSRELEASE
yum install nginx

就大功告成了

Currently, nginx packages are available for the following distributions and versions:

关于版本,可经过uname命令来看 

[root@host yuyang]# uname -r
4.13.7-1.el6.elrepo.i686
[root@host yuyang]# uname -v
#1 SMP Sat Oct 14 11:42:10 EDT 2017
[root@host yuyang]# uname -i
i386

 

RHEL/CentOS:

Version Supported Platforms
6.x x86_64, i386
7.4+ x86_64, ppc64le

Debian:

Version Codename Supported Platforms
8.x jessie x86_64, i386
9.x stretch x86_64, i386

Ubuntu:

Version Codename Supported Platforms
14.04 trusty x86_64, i386, aarch64/arm64
16.04 xenial x86_64, i386, ppc64el, aarch64/arm64
17.04 zesty x86_64, i386

SLES:

Version Supported Platforms
12 x86_64



关于部署django几点注意点:
  settings.py ALLOWED_HOST 须要设置 * 或者对应ip
DEBUG 改为False
  settings 设置STATIC_ROOT
在启动uwsgi前,收集静态文件,命令是python manage.py collectstatic ,这个命令回见django里面的静态文件全收集到STATIC_ROOT 所指定的目录下


以前一夜failed to open python.py 这个bug 是由于 --chdir --wsgi-file 的文件路径写的不对,写重复了。

启动有mysql 的django 项目,报 nomudule package MySQLdb 须要
pip3 install mysqlclient

 

在deug设置为false 后静态文件是从STATIC_ROOT 下面找的
uwsgi --http :9003 --chdir /root/s5/deploy1 --wsgi-file deploy1/wsgi.py --master --processes 1 --threads 2 --static-map /static=/root/s5/xxxxxx

 

也能够写成配置文件
相关文章
相关标签/搜索