ubuntu environment deployment project

Install the packages that need to be installed in apt-get first, and then install the packages in pip

Packages that need to be installed in 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

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

Deploy virtual environment

Python 3.6 is now installed in a non-virtual environment

sudo pip install virtualenv #Install the packages required by the virtual environment

virtualenv -p /usr/bin/python3.6 venv #Create a virtual environment with python3.6 (automatically include the corresponding version of pip)

virtualenv -p /usr/bin/python2.7 venv #Create a virtual environment with python2.7 (automatically include the corresponding version of pip, required when installing supervisor)

cd venv #Enter the directory of the virtual environment

source bin/activate #After entering the virtual environment successfully, the command line starts with (venv)

Install pip package

pip install -r file.txt #Install pip related packages, first enter the virtual environment

Install supervisor

. /bin/pip2.7 install supervisor #Install superviosr via pip2.7 (because supervisor does not support python3)

echo_supervisord_conf> supervisord.conf #Generate superviosr configuration file https://blog.csdn.net/wr166/article/details/79051725 Use supervisor to run python3 web project in python2 environment

vi supervisor.conf #After opening, enter the relevant configuration

supervisord -c supervisord.conf #Start the supervisor service through the configuration file

deactivate #Exit the virtual environment # https://blog.csdn.net/charlie_heng/article/details/60573688 Supervisor's simple solution under python3

Firewall/port opening and closing

Turn on the firewall: ufw enable

Turn off the firewall: ufw disable

Open the firewall port: ufw allow port number; such as: ufw allow 5000

Close the firewall port: ufw deny port number;

Restart the firewall: ufw reload

View the status of the firewall port: ufw status

Test whether the port of the remote host is open: telnet 192.168.1.103 80

Start the service and access the external network:

Configuration file in supervisor:

[ program:fws] #Project name
directory= /home/ubuntu/fws #Project location
environment = PATH='home/ubuntu/venv/bin' #Environment
command= /home/ubuntu/venv/bin/python3.6 run.py #Run command
autostart = true #auto start
startsecs = 1
autorestart = true #automatic restart
stopasgroup = true 
killasgroup = true
user = ubuntu
stdout_logfile = /home/ubuntu/fws/logs/supevisor.log #output log
stderr_logfile = /home/ubuntu/fws/logs/supevisor_err.log #error log

The content of run.py file:

from fws import app

if __name__ =='__main__':
app.run(host='10.104.136.123',port=5000)   #host is the internal network address, the port number should be checked whether the external network can be accessed

Nginx configuration content:

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/;}}}

Then start supervisor, and nginx

Other related command records

pip list --format freeze # pip list

pip install -r file.txt #pip batch installation

pip -V #View the corresponding compiled version of python

whereis python3.6 #View the installation path

https://www.cnblogs.com/yjlch1016/p/8641910.html How to install Python 3.6 on Ubuntu, pip

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

https://blog.csdn.net/wangtaoking1/article/details/51554959 "OSError: mysql_config not found" error when installing Python mysqlclient

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

error: command'x86_64-linux-gnu-gcc' failed with exit status 1 You need to install the corresponding python-dev package according to the python version, such as apt-get install pyton3.6-dev

Recommended Posts

ubuntu environment deployment project
Django&MySQL environment deployment under Ubuntu 14.04
ubuntu16.04 deploy GPU environment
Production environment deployment of ubuntu Django + Uwsgi + Nginx
Ubuntu configuration development environment
Ubuntu development environment configuration
Python virtual environment: Ubuntu16.04
Ubuntu Touch environment setup
Ubuntu18.10 configure Java environment
[CentOS environment deployment] Java7/Java8 deployment under CentOS
ubuntu sets python2.5 environment variables
ubuntu14.0464 Ros environment install halcon13.01
Ubuntu deployment and experience Nexus3
ubuntu build python development environment
ubuntu builds common development environment
ubuntu offline installation python environment
Deploy JobConverter + Ibreoffice environment on Ubuntu
Ubuntu environment variables and ADB configuration
Ubuntu16.04 build php5.6 Web server environment
Docker ubuntu: install python-PIL-image environment on 14.04
Ubuntu 19.1 installation and configuration Chinese environment
CentOS deployment method of flask project
Install Hadoop system environment on Ubuntu 18.04
FFmpeg environment deployment record under centos7
PPTP environment deployment record under Centos
ubuntu Docker installation and deployment of Rancher
Ubuntu installation and deployment Redash operation notes (2020.08)
Build a LAMP development environment on Ubuntu 16.04
Centos-6.5 installation and deployment of LNMP environment
JDK environment variable configuration method under ubuntu
Build the C++ compilation environment under ubuntu
Configure Java development environment in Ubuntu20.04 LTS
Tencent Cloud ubuntu 16.04 ZenTao integrated environment construction
Installation and deployment of Nginx in Ubuntu
Steps to build LNMP environment on ubuntu 20.04
Build arm virtual operating environment on Ubuntu
Download OpenJDK11 source code in Ubuntu environment
Ubuntu Server builds Hyperledger Fabric 2.1 learning environment
Python and scrapy deployment in centos environment
Vagrant quickly builds Ubuntu virtual machine environment
GPU programming (1): CUDA8.0 environment construction under Ubuntu
Build a python development environment under Ubuntu
Configure Nginx + PHP 7.0 + MySQL environment under Ubuntu 16.04
Docker those things in the Ubuntu environment
Edit OpenJDK11 source code in Ubuntu environment
Deploy springboot project through docker under Ubuntu
Some Centos Python production environment deployment commands