打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ubuntu环境部署项目

先安装 apt-get中 需要安装的包,然后再安装 pip中的包

apt-get中需要安装的包:

sudo apt-get install python3.6-dev

sudo apt-get install mysql-server

sudo apt-get install mysql-client

 sudo apt-get install redis-server

 安装 nginx:  https://www.cnblogs.com/EasonJim/p/7806879.html

部署虚拟环境

现在非虚拟环境下安装好python3.6

sudo pip install virtualenv   #安装虚拟环境需要的包

virtualenv -p /usr/bin/python3.6 venv  #创建带有python3.6的虚拟环境(自动包含pip对应版本)

virtualenv -p /usr/bin/python2.7 venv  #创建带有python2.7的虚拟环境(自动包含pip对应版本,安装supervisor时需要)

cd venv   #进入到虚拟环境的目录

source bin/activate  #进入虚拟环境 成功后,命令行开头 有 (venv)

安装pip的包

pip install -r file.txt   #安装pip相关包,先进入虚拟环境

安装supervisor

./bin/pip2.7 install supervisor  #通过pip2.7安装 superviosr(因为supervisor不支持python3)

echo_supervisord_conf > supervisord.conf  #生成superviosr配置文件   https://blog.csdn.net/wr166/article/details/79051725   在python2的环境下用supervisor来运行python3的web项目

vi supervisor.conf #打开后,输入相关配置

supervisord -c supervisord.conf  #通过配置文件启动supervisor服务

 deactivate  #退出虚拟环境        # https://blog.csdn.net/charlie_heng/article/details/60573688    supervisor 在python3下的简易解决方案

 

防火墙/端口 开启和关闭

开启防火墙: ufw enable

关闭防火墙:ufw disable

开启防火墙的端口 :ufw allow 端口号; 如:ufw allow 5000

关闭防火墙的端口:ufw deny 端口号;

重启防火墙:ufw reload

查看防火墙端口的状态: ufw status

测试远程主机的端口是否开启:  telnet 192.168.1.103 80

 

启动服务并外网可以访问:

supervisor 中的配置文件:

[program:fws] #项目名
directory= /home/ubuntu/fws  #项目位置
environment = PATH='home/ubuntu/venv/bin'  #环境
command= /home/ubuntu/venv/bin/python3.6 run.py #运行命令
autostart = true #自动启动
startsecs = 1
autorestart = true #自动重启
stopasgroup = true 
killasgroup = true
user = ubuntu
stdout_logfile = /home/ubuntu/fws/logs/supevisor.log #输出日志
stderr_logfile = /home/ubuntu/fws/logs/supevisor_err.log #错误日志

run.py文件内容:

from fws import appif __name__ == '__main__':app.run(host='10.104.136.123',port=5000)   #host为内网地址,端口号要检查外网是否可以访问

nginx配置内容:

worker_processes  1;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    log_format  main escape=json  '$remote_addr - $remote_user [$time_local] "$request" '                      '$status $body_bytes_sent "$http_referer" '                      '"$http_user_agent" "$http_x_forwarded_for" "$request_body"';    access_log  /home/ubuntu/fws/logs/nginx.log  main;    error_log  /home/ubuntu/fws/logs/nginx_err.log;    sendfile        on;    keepalive_timeout  65;    server {        listen        8080;        location / {                proxy_pass http://10.104.136.123:5000;                proxy_set_header X-Real-Ip $remote_addr;        }        location ^~ /index.html {                alias /home/web/fws/fws/static/dist/;        }        location /static {                alias /home/web/fws/fws/static/;        }    }}

 

然后启动 supervisor,和nginx即可

 

 

其他相关命令记录

pip list --format freeze   # pip 列表

pip install -r file.txt   #pip批量安装 

pip -V   #查看对应的python编译版本

whereis python3.6   #查看安装路径

https://www.cnblogs.com/yjlch1016/p/8641910.html       Ubuntu怎样安装Python3.6,pip

https://blog.csdn.net/San_South/article/details/80715682      Ubuntu16.04上pip报错ModuleNotFoundError: No module named 'pip._internal'

 https://blog.csdn.net/wangtaoking1/article/details/51554959      安装Python mysqlclient出现“OSError: mysql_config not found”错误

https://blog.csdn.net/meteor_s/article/details/79115360             Error记录--ImportError: No module named apt_pkg

 error: command 'x86_64-linux-gnu-gcc' failed with exit status 1     需要根据python版本安装对应的python-dev包,如apt-get install pyton3.6-dev

 

来源:http://www.icode9.com/content-3-28391.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
在Ubuntu下配置舒服的Python开发环境
【Python】Ubuntu 18.04 安装 python3.7
ubuntu16.04 install pip pip3
Linux Ubuntu 20.04 LTS 一键安装 Python3 不同版本的方法
从零开始,用Python打造你的个人服务器!
jupyter notebook安装
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服