树莓派USB map遍历 xml arraylist scripting Pure CSS jq解析json web前端毕业设计题目 bootstrap时间轴 kb转mb mysql增删改查语句 java手机验证码 重置hosts python教学 python中index的用法 python基础教程免费 python调用自定义函数 python中集合 python路径设置 javaswitch语句 java中的数据结构 javascript实例 xp画图工具 acmecadconverter lol设置 3dmax插件神器 dota改键工具 福昕阅读器绿色版 汽车配件查询软件 spss20安装教程 eagle软件 backtrack4 三星打印机怎么加墨 清华天河 exe文件反编译 方正美黑简体 ps测量长度 迅捷屏幕录像工具 resample idt声卡补丁
当前位置: 首页 > 学习教程  > 编程语言

Django部署

2020/10/8 19:43:54 文章标签:

在Centos7上面安装 一、首先安装git 1、首先安装依赖环境 yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc xmlto docbook2x autoconf yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils…

在Centos7上面安装

一、首先安装git

1、首先安装依赖环境

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc xmlto docbook2x autoconf
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
yum  install autoconf
yum install gcc
yum install perl-ExtUtils-MakeMaker package
yum install autoconf

2、创建连接

ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi

3、删除掉已经存在的git

yum remove git

4、下载git包

wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.8.3.tar.gz
tar -zxvf git-2.8.3.tar.gz
cd git-2.8.3
./configure prefix=/usr/local/git/
make && make install

二、安装python3.x

1、安装python3运行环境的包

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

2、下载python3的程序包,并安装

wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
tar -xvJf  Python-3.6.3.tar.xz
cd Python-3.6.3
./configure prefix=/usr/local/python3
make && make install

安装完后才能后python3就会出现在/usr/local/python3路径下了

3、实现python2和python3共存

移除原来python2的软链接,创建python3软链接

rm /usr/bin/python
ln -s /usr/local/python3/bin/python3 /usr/bin/python

因为执行yum需要python2版本,所以我们还要修改yum的配置,执行:

vi /usr/bin/yum

把#! /usr/bin/python修改为#! /usr/bin/python2
同理

vi /usr/libexec/urlgrabber-ext-down 

文件里面的#! /usr/bin/python 也要修改为#! /usr/bin/python2

三、安装pip3

1、安装依赖环境

yum  -y  install  zlib-devel  bzip2-devel  openssl-devel  ncurses-devel  sqlite-devel  readline-devel  tk-devel  gdbm-devel db4-devel   libpcap-devel xz-devel

2、安装setuptools
下载安装包

 wget  --no-check-certificate  https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz

解压

tar -zxvf setuptools-19.6.tar.gz

切换目录

 cd setuptools-19.6

安装

python setup.py build
python setup.py install

移除软链接

 rm -rf /usr/bin/pip

设置软链接

     ln   -s   /usr/local/python3/bin/pip3    /usr/bin/pip

pip -V为python3.6版本的

四、安装各种包和mysqlclient

安装下面两个文件防止mysqlclient在安装过程中抱错

yum install  mysql-devel  
yum install python3-devel

安装各种包

pip install Django 
pip install PyMySQL 
pip install Scrapy 
pip install beautifulsoup4 
pip install bs4 
pip install lxml 
pip install numpy 
pip install requests 
pip install simplejson
pip install urllib3
pip install musqlclient

五、安装MySQL

下载mysql源安装包

wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

安装mysql源

yum localinstall mysql57-community-release-el7-8.noarch.rpm
yum install mysql-devel

安装MySQL

yum install mysql-community-server

启动MySQL服务

systemctl start mysqld

查看MySQL的启动状态

systemctl status mysqld

开机启动

systemctl enable mysqld

修改root本地登录密码

grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
set password for 'root'@'localhost'=password('!2Qw32sd'); 

注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误

配置默认编码为utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'

导入django和mysql数据库
导入django项目

sudo su root
mkdir project
cd project
git clone https://gitee.com/dafeige/django-restframework-demo.git

此时,我的数据库文件路径是:project/django-restframework-demo/tutorial/test_python.sql,由于需要将此sql文件导入到mysql数据中,需要给此文件加权限:

chmod 777 project/django-restframework-demo/tutorial/test_python.sql

导入sql数据库文件,进入数据库

mysql -u root -p

导入sql文件

create database test_python;
use test_python;
source project/django-restframework-demo/tutorial/test_python.sql;

部署django工程,进入到工程中

sudo su root
cd project/django-restframework-demo/tutorial
python manage.py runserver 0.0.0.0:80 &

六、安装uwsgi

python -m pip install uwsgi

七、安装nginx

1、下载相关组件

wget http://nginx.org/download/nginx-1.10.2.tar.gz
wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
wget http://zlib.net/zlib-1.2.11.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz

安装c++编译环境

yum install gcc-c++

2、安装Nginx及相关组件

openssl安装

tar zxvf openssl-fips-2.0.10.tar.gz
 cd openssl-fips-2.0.10
./config && make && make install

跳转回上级目录 cd …

pcre安装

tar zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure && make && make install

跳转回上级目录 cd …

zlib安装

tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure && make && make install

跳转回上级目录 cd …

nginx安装

tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure && make && make install

3、启动Nginx

先找一下nginx安装到什么位置上了

whereis nginx

进入nginx目录并启动

cd usr/local/nginx

报错了,error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory,按照下面方式解决
1.用whereis libpcre.so.1命令找到libpcre.so.1在哪里
2.用ln -s /usr/local/lib/libpcre.so.1 /lib64命令做个软连接就可以了
3.用sbin/nginx启动Nginx
4.用ps -aux | grep nginx查看状态

whereis libpcre.so.1
ln -s /usr/local/lib/libpcre.so.1 /lib64
sbin/nginx
ps -aux | grep nginx 

进入Linux系统的图形界面,打开浏览器输入localhost会看到下图,说明nginx启动成功

参考资料:

1、centos7+django+python3+mysql+阿里云部署项目全流程:https://blog.csdn.net/a394268045/article/details/79288718
2、阿里云服务器Centos7.3下安装python3.6.5及pip3:https://blog.csdn.net/LeonTom/article/details/81289326
3、Nginx的安装:https://www.cnblogs.com/taiyonghai/p/6728707.html
4、从零开始配置阿里云服务器Centos7.4(一):安装python3:https://blog.csdn.net/weixin_41796432/article/details/79624280
5、如何把本地的Django项目部署到服务器(亲测):https://blog.csdn.net/qq_30501975/article/details/80423547
6、安装mysqlclient出现报错:https://blog.csdn.net/liufei0714/article/details/84899055


本文链接: http://www.dtmao.cc/news_show_250172.shtml

附件下载

相关教程

    暂无相关的数据...

共有条评论 网友评论

验证码: 看不清楚?