This article is a mirror article of machine translation, please click here to jump to the original article.

View: 13112|Reply: 1

[Tips] Python flask project deployment process

[Copy link]
Posted on 8/31/2018 4:56:03 PM | | |
Project deploymentRelevant environment installation1. Update source(Modify the source)    sudo apt-get update2. mysqlInstallation    apt-get install mysql-server    apt-get install libmysqlclient-dev3. redisInstallation    #Install dependencies    sudo apt-get update    sudo apt-get install gcc    sudo apt-get install build-essential tcl    #Installationredis    sudo apt-get install redis-server4.Install the virtual environment    pip install virtualenv    pip install virtualenvwrapper5.dispositionvirtualenvwrapper   1.Make it installedvirtualenvwrapperEffective, edit~/.bashrcfile        export WORKON_HOME=$HOME/.virtualenvs        export PROJECT_HOME=$HOME/workspace        source /usr/local/bin/virtualenvwrapper.sh    2.Make the edited file effective        source ~/.bashrc6.Install the dependency packageUse the following command to generate the dependencies in the current virtual environment to a file with the version number    pip freeze > requirements.txtEnter the virtual environment Bulk install dependency packages    pip install -r requirements.txtIn installationFlask-MySQLdbThe dependency package may not be installed, run the following command to install the dependency package    sudo apt-get build-dep python-mysqldbNginxsudo apt-getinstall nginxOperation and stop/etc/init.d/nginx start #initiate/etc/init.d/nginx stop  #Stop itConfiguration filesEdit the file:/etc/nginx/sites-available/default# If there are multiple servers, configure it here and modify itlocationnodeproxy_passupstream flask {        server 127.0.0.1:5000;        server 127.0.0.1:5001; }server {        #Monitoring80ports        listen 80 default_server;        listen [::]:80 default_server;        root /var/www/html;        index index.html index.htm index.nginx-debian.html;        server_name _;        location / {                #request forwarded togunicornserver                proxy_pass http://127.0.0.1:5000;                #Request forwarded to multiple requestsgunicornserver                # proxy_pass http://flask;                #Set the request header and pass the header information to the server                proxy_set_header Host $host;                #Set the request header to pass the original requestipTo givegunicornserver                proxy_set_header X-Real-IP $remote_addr;        }}MySQL installationsudo apt-getinstall mysql-server
I don't know if the mysql default password applies
1. Ubuntu check the default password sudo cat /etc/mysql/debian.cnf2. Log in with the default account and change the root password update mysql.userset authentication_string=password('mysql') whereuser='root'3. sudo mysql -uroot -p, enter password 4. Update password updateuserset password=password("mysql") whereuser="root";        update mysql.userset authentication_string=password('mysql') whereuser='root'; 5. If you need sudo login to vim /etc/mysql/my.cnf and add [mysqld] skip-grant-tablesredis installationsudo apt-getinstall redis-serverNginx uninstall and installadoptedCLanguage writing implements diversion, forwarding, and load balancing
  • Remove nginx, -purge includes the configuration file
    sudo apt-get --purge remove nginx
  • Remove all unused packages
    sudo apt-get autoremove
  • List the software related to nginx and remove it
    dpkg --get-selections|grep nginx
    sudo apt-get --purge remove nginx
    sudo apt-get --purge remove nginx-common
    sudo apt-get --purge remove nginx-core
  • Check the process that nginx is running and kill it if there is
    ps -ef |grep nginx
    sudo kill -9 XXX
  • Global lookup for files related to nginx
    sudo find / -name nginx*
    sudo rm -rf file
  • Delete all files listed
    sudo rm -rf file
  • Reinstall nginx
    sudo apt-get update
    sudo apt-get install nginx
  • Other content of Nginx
    • Test if the nginx configuration is correct
      sudo nginx -t
    • nginx restarted
      sudoservicenginx restart
    nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/ms.recipe_box.com.conf:2
    Delete the /etc/nginx/sites-available/default file and restart the service
    Nginx Performance Abnormal: Suggest Restarting Nginx Service** sudo service Nginx restart**

Gunicorn installation1. Gunicorn (Green Unicorn) is an HTTP server for Python WSGI2. Ported from Ruby's Unicorn project3. This Gunicorn server is compatible with various web frameworks and implements very simple, lightweight resource consumption4. Gunicorn is launched directly with commands and does not require writing a configuration fileInstallation
  • Installation
    pip install gunicorn
  • View options
    gunicorn -h
  • Run

# -w:Indicates a process (worker-b: indicates bindingipaddress and port number (bindgunicorn -w 2 -b 127.0.0.1:5000Run file name:FlaskProgram instance namepip upgrade
install sudo apt-get install python3-pip
wgethttps://bootstrap.pypa.io/get-pip.py--no-check-certificate
pythonget-pip.py
Upgrade sudo pip3 install --upgrade pip
Uninstall sudo apt-get remove python3-pip
Additional content
Tencent Cloud (ubuntu16.04) cannot upgrade pip workaround
  • Try updating the source
    sudo apt-get update
  • Modify the source sudo vim /etc/apt/sources.list
    debhttp://mirrors.aliyun.com/ubuntu/trusty-security main restricted universe multiverse # disabled on upgrade to xenial
    debhttp://mirrors.aliyun.com/ubuntu/trusty-updates main restricted universe multiverse # disabled on upgrade to xenial
    debhttp://mirrors.aliyun.com/ubuntu/xenial-proposed main restricted universe multiverse #Not for humans during development stage of release xenial
    debhttp://mirrors.aliyun.com/ubuntu/trusty-backports main restricted universe multiverse # disabled on upgrade to xenial
    deb-srchttp://mirrors.aliyun.com/ubuntu/xenial main restricted universe multiverse # disabled on upgrade to xenial
    deb-srchttp://mirrors.aliyun.com/ubuntu/trusty-security main restricted universe multiverse # disabled on upgrade to xenial
    deb-srchttp://mirrors.aliyun.com/ubuntu/trusty-updates main restricted universe multiverse # disabled on upgrade to xenial deb-srchttp://mirrors.aliyun.com/ubuntu/xenial-proposed main restricted universe multiverse #Not for humans during development stage of release xenial
    deb-srchttp://mirrors.aliyun.com/ubuntu/trusty-backports main restricted universe multiverse # disabled on upgrade to xenial

Then execute
  • Update source sudo apt-get update
  • Update system sudo apt-get upgrade









Previous:See I want to post. Let's have a wave of Python
Next:About sharing code links
 Landlord| Posted on 8/31/2018 4:57:42 PM |
e...... It's a bit awkward not to support MD..... Put the link https://blog.csdn.net/zzw19951261/article/details/80981936
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com