ubuntu环境部署项目
安装python3.6
第一步:sudo add-apt-repository ppa:jonathonf/python-3.6
如果报错为:sudo: add-apt-repository: command not found
则执行:sudo apt-get install software-properties-common python-software-properties 之后,再次执行上一步
第二步:apt-get update
第三步:apt-get install python3.6
python3.6版本的pip安装
https://blog.csdn.net/xiaoming0018/article/details/83146191
先安装 apt-get中 需要安装的包,然后再安装 pip中的包
apt-get中需要安装的包:
sudo apt-get install python3.6-dev
sudo apt-get install mysql-server
service mysql start
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对应版本,一定要指定python运行版本)
virtualenv -p /usr/bin/python2.7 venv #创建带有python2.7的虚拟环境(自动包含pip对应版本,安装supervisor时需要,后续对supervisor的操作,也要在此环境中)
cd venv #进入到虚拟环境的目录
source bin/activate #进入虚拟环境 成功后,命令行开头 有 (venv)
安装pip的包
pip install -r file.txt #安装pip相关包(linux系统中去掉pywin32的包安装命令,并且出现 successfully字样 才是安装成功),先进入虚拟环境
在安装 pip install mysqlclient 报错如下:
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-sr_0u6nl/mysqlclient/setup.py", line 16, in <module>
metadata, options = get_config() File "/
先安装 apt-get install libmysqlclient-dev
安装supervisor
如果 调换了python版本的优先级,把python3.6设置为最高优先级,在使用pip2.7命令时,如果报错如下:
root@zhimeng:/usr/bin# pip2
Traceback (most recent call last):
File "/usr/bin/pip2", line , in <module>
load_entry_point('pip==8.1.1', 'console_scripts', 'pip2')()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line , in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line , in load_entry_point
raise ImportError("Entry point %r not found" % ((group, name),))
ImportError: Entry point ('console_scripts', 'pip2') not found
则 打开错误提示中的“/usr/bin/pip2”文件,把文件中第一行的“#!/usr/bin/python”改为“#!/usr/bin/python2” 即可
原文网址如下:https://blog.csdn.net/llf_cloud/article/details/80160494
./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 中的配置文件(修改后,一定要 supervisorctl reload 命令 进行 重载配置文件):
[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 app if __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即可
gunicorn在 supervisor中启动的方式():
[program:oly] directory = /data/wwwroot/project
# 如果指定gunicorn为虚拟环境,则gunicorn路径为虚拟环境路径
# command =/data/wwwroot/olympus/venv/bin/gunicorn -w 4 -b 0.0.0.0:5000 -t 160 manage:app
user = root
startsecs = autorestart =true
redirect_stderr =true stdout_logfile_maxbytes = 50MB
stdout_logfile_backups =
stdout_logfile=/data/wwwlogs/olympus/olympus_supervisor.log loglevel=info
linux系统,mysql开启远程连接(先保证安全组和防火墙对应的3306端口开启) :https://www.cnblogs.com/chenjw-note/p/5887908.html
netstat -tunlp |grep 端口号,用于查看指定的端口号的进程情况,如查看8000端口的情况,netstat -tunlp |grep 8000
其他相关命令记录
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
ubuntu环境部署项目的更多相关文章
- Linux环境部署项目引起Out of Memory Error: PermGen Space的解决方案
1. 背景 前几天,在搭建项目时遇到到一些问题,现在整理记录一下. Linux环境:Red Hat Enterprise Linux Server release 6.4: # 查看命令cat /et ...
- Vue项目上线环境部署,项目优化策略,生成打包报告,及上线相关配置
Node.js简介 Node.js是一个基于Chrome V8引擎的JavaScript运行环境,用来方便快速地搭建易于扩展的网络应用.Node.js使用了一个事件驱动.非阻塞式I/O的模型,使其轻量 ...
- NodeJS项目迁移兼Ubuntu下NodeJS环境部署
前言 之前做的几个项目都托管在阿里云服务器,但是最近要到期了.想着到底要不要续期,毕竟100/月.后面看着阿里云有个活动,800/三年.果断买下.环境部署折腾了一天,其中也遇到几个坑. 目录 一.安装 ...
- Linux Ubuntu从零开始部署web环境及项目 -----部署项目 (三)
上一篇讲了如何在linux搭建web环境,这边将如何部署项目. 1,打包项目包 2,上传项目包 将.war项目包通过xftp上传到tomcat目录wabapps目录下 3,启动项目 通过xshell命 ...
- 分布式版本库——Windows下Git的环境部署以及在GitHub上开源自己的项目
分布式版本库--Windows下Git的环境部署以及在GitHub上开源自己的项目 这几天着实忙的焦头烂额,可惜不是搞技术,今天周日,难得闲下来,写篇大家都想学习的Git教程,其实廖雪峰老师的网站已经 ...
- Linux:Ubuntu下部署Web运行环境
Linux:Ubuntu下部署Web运行环境 本次博客将会从三部分内容详述Ubuntu系统下Web运行环境的配置: 依次是:FTP服务器的搭建.MYSQL数据库的搭建.JDK的安装等. 参考文章如下: ...
- ubuntu Django + Uwsgi + Nginx 的生产环境部署
一.概述 使用runserver可以使我们的django项目很便捷的在本地运行起来,但这只能在局域网内访问,如果在生产环境部署django,就要多考虑一些问题了.比如静态文件处理,安全,效率等等,本篇 ...
- Ubuntu部署项目
一.Ubuntu目录结构 目录 说明 bin 存放二进制可执行文件(ls,cat,mkdir等) .exe== boot 存放用于系统引导时使用的各种文件 开机引导 dev 用于存放设备文件 打印机啥 ...
- jenkins+git+maven搭建自动化部署项目环境
简介 折腾了两个晚上,趁着今晚比较有空,把jenkins+git+maven搭建自动化部署项目环境搭建的过程记录一下,这里我把github作为git的远程仓库(https://github.co ...
随机推荐
- java.lang.NoSuchMethodError: com.opensymphony.xwork2.config.ConfigurationManager.addConfigurationPro
java.lang.NoSuchMethodError: com.opensymphony.xwork2.config.ConfigurationManager.addConfigurationPro ...
- Python学习之路基础篇--05Python基础+列表和元组
1 list # 增 city = ["wuhan", "shanghai", "chongqing", "changsha&qu ...
- Unity数据类型转XML/Json-封装函数直接调用(Chinar)
Unity将数据直接转XML/Json文件 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar ...
- SQLI DUMB SERIES-18
(1)对username和password无论怎么输入,都没有回显,再看题目,POST - Header Injection - Uagent field - Error based (基于错误的用户 ...
- 一起学python-语法
1.print 输出 2.定义变量:就是给变量赋一个值 name ='haha' print (name) 3.注释代码:# 注释快捷键:Ctrl +/ 4.单双引号: 如果字符串里面有单引号,外面就 ...
- .singleton.php 文件 (单例模式可被继承 代码实例)
<?phpnamespace lib;abstract class Singleton{ //设置一个私有的静态属性作为中间变量 private static $instancePool = [ ...
- VritualBox安装CentOS及安装增强工具图文教程
一 VM VirtualBox VirtualBox可在官网https://www.virtualbox.org/下载,完全免费. 二 安装CentOS系统(以CentOS6.9为例) 1.Cen ...
- 我在web前端路上的第一个脚印
这是我的第一篇博客,希望记录下我在路上见到的风景,也和大家一起分享.
- 使用JBolt新建Maven版工程步骤
一.打开新建对话框 在左侧右键new中可以找到JFinal创建工程的菜单 JBoltHome页面也有快捷按钮用来弹出创建工程对话框. 二.填写Maven和其他信息配置 填写工程name 主包名 下面有 ...
- robot framework中的返回值
1.若想要再setup中有返回值,给后续的操作使用 A)在setup的关键词中需要的返回值,设置为global variable或者suit variable:如下图:但是在编译器中,会报错,但是执行 ...