一、安装python3.6
1、安装依赖
yum install openssl
yum install openssl-devel
yum install gcc
yum -y install zlib*
2、下载python3
# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
3、在/usr/local/python3目录下安装
mkdir -p /usr/local/python3
解压
tar -zxvf Python-3.6.1.tgz
编译安装
# cd Python-3.6.1
# ./configure --prefix=/usr/local/python3
# make
# make install
4、python3软链
# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
5、添加环境变量
export PATH="$PATH:$HOME/bin:/usr/local/python3/bin"
6、测试
python3 -V
yum install python3-pip
pip3 -V
更新
pip3 install --upgrade pip
二、安装uwsgi
1、安装
sudo yum install build-essential python-dev zlib1g-dev libssl-dev
yum install python3-devel
pip3 install uwsgi
2、解压
tar xvzf uwsgi-2.0.18.tar.gz
3、 软链
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi3
三、安装flask
1、新建项目
mkdir project
cd project
虚拟环境
python3 -m venv venv
激活
. venv/bin/activate
2、安装
pip3 install Flask
3、新建一个测试页
touch index.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return '1test-Hello, World!to li xiaomi'
vi index.py
4、设置flask_app
export FLASK_APP=index.py
5、启动
flask run --host=0.0.0.0
6、同级目录下新建uwsgiconfig.ini文件
[uwsgi]
# htmlWeb.py文件所在目录
chdir = /usr/local/python3/project
callable = app
# flask文件名
wsgi-file= index.py
# 进程数
processes = 5
# 使用3993端口
http = 0.0.0.0:5000
# 日志输出目录
daemonize = /usr/local/python3/project/flask.log
pidfile = project-master.pid
py-autoreload=1
7、uwsgi的重启
a、
先杀死再重启
killall -s INT uwsgi
uwsgi --reload project-master.pid
b、在配置文件中(uwsgiconfig.ini)中添加py-autoreload=1,保存python文件后自动重启
四、安装nginx
1、安装依赖
yum install gcc-c++
yum install pcre
yum install pcre-devel
yum install zlib
yum install zlib-devel
yum install openssl
yum install openssl-devel
yum install epel-release
yum install nginx
2、查看目录
which nginx
/usr/sbin/nginx
启动
/usr/sbin/nginx
3、查找配置文件目录
whereis nginx
/etc/nginx
upstream pyt {
#53
#
#server 10.66.180.35:7005 weight=8;
# 155
server 127.0.0.1:5000 weight=1;
# 165
#server 219.148.37.134:7005 weight=1;
#server 10.29.168.199:9000 weight=2;
#server 10.30.149.73:9000 weight=2;
}
server {
listen 8072;
server_name pyt.foodszs.cn;
#charset koi8-r;
#access_log /data/logs/host.access.log main;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://pyt;
index index.html index.htm;
}
}