部署python django程序

it2022-05-09  39

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

安装python3

安装python3 之前博客写过

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

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

首先创建一个空目录

python3 -m venv DIR

在linux 启动虚拟环境是

source bin/activate

pip3安装各种Python包

pip3 install -r requirements.txt

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

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

pip freeze > FILENAME.txt

 

退出虚拟环境

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安装uwsgipip3 install uwsgi安装nginxyum 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 /etc/yum.repos.d/nginx.repo with the following contents:在这个文件下写入 [nginx] name=nginx repo baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/ gpgcheck=0 enabled=1

 

标红部分要根据你的操作系统版本来改Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “6” or “7”, for 6.x or 7.x versions, respectively.翻译是:将用rhel 或者centos 来替代'OS' ,这个取决于你的发行版,用6或者7来替代 “OSRELEASE”这个取决于是6.x 还是7.x 改完之后保存退出再执行命令 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:

VersionSupported Platforms6.xx86_64, i3867.4+x86_64, ppc64le

Debian:

VersionCodenameSupported Platforms8.xjessiex86_64, i3869.xstretchx86_64, i386

Ubuntu:

VersionCodenameSupported Platforms14.04trustyx86_64, i386, aarch64/arm6416.04xenialx86_64, i386, ppc64el, aarch64/arm6417.04zestyx86_64, i386

SLES:

VersionSupported Platforms12x86_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

 

也可以写成配置文件

 

转载于:https://www.cnblogs.com/yuyang26/p/7993934.html


最新回复(0)