Centos下python3环境的部署
1.Yum源
检测yum是否完好
Yum list
当遇到以下问题
1.Yum 进程没有关闭
错误:1
Yum 源没有配置
2.配置yum源:
https://www.linuxidc.com/Linux/2017-08/146364.htm
错误:2
Pid 进程id
Kill -9 pid 13972杀死进程
3.安装python需要的依赖包
Yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
Unix系统默认安装了python
Centos 6 安装 python2.6版本
Centos 7 安装 python2.7版本
我们需要的版本是python 3.6.2,在centos上进行python2和3并存
4.下载python 3.6.2的包
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
补充:
协议:网络上数据传输的约定规则
Tcp 面向连接的协议,有校验的数据包
Udp 无连接
可容忍丢包率
http 常规的http
https 加密的http
ftp 文件传输
Ssh 远程空开
Sftp 基于ssh的文件传输
Smtp 协议
5.解压安装包
tar -xvJf Python-3.6.2.tar.xz
6.编译安装
需要切入解压后的项目
./configure prefix=/usr/local/python3
Make && make install
7.配置软连接(环境变量)
软连接 --> 快捷方式
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
测试:
以后我们运行python3的脚本需要编程 python3 *.py
8.安装python的扩展包
yum install python-devel
安装python 开发包
Pymysql
Pillow
Django==2.1.5
django-ckeditor
pip3 install pymysql && pip3 install pillow && pip3 install django==2.1.5 &&pip3 install django-ckeditor
9、Python uwsgi
Python 的web项目,本身很难和Apache或者Nginx进行结合,为了让python web项目更加方便的被部署,开发出了uwsgi。
安装:
Pip3 install uwsgi
创建软连接
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi
使用:
我们迁移我们的项目Qshop
复制我们的项目到虚拟机
cp -r /root/Desktop/Qshop/ /opt/Qshop
我们需要清除pycharm的配置文件,初始的导入文件
测试项目
python3 manage.py runserver 0.0.0.0:8000
注意:
Systemctl stop firewalld 关闭防火墙
用uwsgi启动django
uwsgi --http 10.10.16.229:8000 --file Qshop/wsgi.py --static-map=/static=static
uwsgi 模块名称
--http 协议
10.10.16.229:8000 主机端口
--file uwsgi要使用的解析文件,一般django自己创建
--static 静态目录
上面我们采用的是命令的方式使用uwsgi启动django,但是,不够完美。我们可以构造配置文件进行操作。
配置内容如下
[uwsgi]
chdir=/opt/OurBlog #项目目录
module=OurBlog.wsgi:application #指定项目的application
socket=/opt/script/uwsgi.sock #指定sock的文件路径
workers=5 #进程个数
pidfile=/opt/script/uwsgi.pid
http=192.168.2.69:8000 #指定IP端口
static-map=/static=/opt/OurBlog/static #指定静态文件
uid=root #用户
gid=root #组
master=true #启用主进程
vacuum=true #自动移除unix Socket和pid文件当服务停止的时候
enable-threads=true #启用线程
thunder-lock=true #序列化接受的内容,如果可能的话
harakiri=30 #设置自中断时间
post-buffering=4096 #设置缓冲
daemonize=/opt/script/uwsgi.log #设置日志目录
1、创建uwsgi文件的配置文件目录和文件
2、编写内容
启动uwsgi
授权
杀死进程重启
- Python uwsgi+nginx部署
wget -c https://nginx.org/download/nginx-1.12.2.tar.gz
解压 tar -zxvf nginx-1.12.2.tar.gz
编译安装
./configure \
make && make install
Nginx
/usr/local/nginx
创建软连接
Nginx通讯uwsgi
修改Nginx的配置文件
备份配置文件
开始配置
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; 日志的格式
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name Qshop; 服务的名称
charset utf-8; 编码格式
access_log logs/host.access.log main; 访问日志
gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text/json image/jpeg image/gif image/png application/octet-stream; 访问内容的类型
error_log /var/log/nginx/error.log error; 错误日志,默认没有,需要手动创建
location / {
include uwsgi_params; 加载uwsgi_params
uwsgi_connect_timeout 30; 连接的超时时间 不要加冒号不要加冒号不要加冒号
uwsgi_pass unix:/opt/script/uwsgi.sock; uwsgi.sock通讯的文件地址
}
location = /static/{
alias /opt/Qshop/static; 静态文件的目录
index index.html index.htm;
}
杀死当前状态下的所有Nginx服务
Pkill -9 nginx
从新启动
访问网站: