flask--Ali Cloud Deployment

Source: Internet
Author: User
Tags documentation pack aliyun
flask– Aliyun ECS deployed on Flask background

Principle: Fast, do not toss, try to in the shortest possible time, let the Web run up. ECS Configuration

CPU 1 Cores
Memory 1G
System CentOS 7.0 64-bit deployment background

Ubuntu specific deployment, settings, and commands that were previously played only in your local virtual machine

Flask + MySQL + uwsgi + supervisor + Nginx MySQL

In fact, the first thing I Aliyun ECS on is the Ubuntu system. But MySQL doesn't fit either on the Update_source script on the Ali help document or on its own. Always prompt for the lack of a dependency pack, then install the dependency pack yourself, and there is a lack of others. Submitted to find Aliyun sales, Ali after the sale of my IP and password, and then they are also uncertain, and finally they and I said,MySQL is a third-party software, they can only friendship assistance, can not provide more help.

Finally, I found the correct way to install the eyes on the Internet. Due to the system's dependency on the package, to replace the Apt-get installation with aptitude, a command solves my busy day.
I thought I could finally breathe a breath. But Aliyun's python environment in Ubuntu is a problem. python Environment

Linux I still like to use pyenv, convenient.

It says there's something wrong with Aliyun Ubuntu python. The first is that when PYENV is installed, it is not possible to switch python, which is always the system's own python. If this is the case, I can also change virtualenv to manage the Python version. However, the system's own Python3 PIP is not installed. The two days have come down really to collapse. Then I found that Aliyun is able to change the system, I decisively changed the system is said to be stable, complete documentation of the CentOS. Then the weather was clear and it was a pleasant journey. Pyenv
Relatively simple, the documentation is also complete. Main reference:
PYENV official GitHub
Raspberry Pie (Ubuntu15.04) installs multiple versions of Python

One thing to note is that you need to add a-l parameter when you restart the shell.

Deploying code with GIT
Use the GitHub, then SSH

Pip Install-r requirements/dev.txt

Environment variables

echo ' Export sqlalchemy_database_uri= ' ... "' >> ~/.BASHRC ...
Configure Uwsgi

Pip install UWSGI configuration start Uwsgi
Config.ini

[Uwsgi]

# Uwsgi started with the address and port
socket = 127.0.0.1:8001 

# extranet Access port, if directly with Uwsgi extranet, here because of the use of nginx, so commented out
# http=: 5000

# Point to Site Directory
chdir =/home/www/ 

# python launcher file
wsgi-file = manage.py 

# Python program to start Application variable name
# a PP is a variable in the manage.py program file, the type of which is flask application class
callable = App 

# processor number
processes = 4

# thread Count 
  
   threads = 2

#状态检测地址
stats = 127.0.0.1:9191
  

The startup command is under the configuration folder: Uwsgi config.ini
But I am ready to use supervisor, so the start command is for testing only.

UWSGI Official documents
Aliyun Deployment flask + WSGI + Nginx detailed
NGINX+UWSGI installation and configuration of the-dba Louvre configuration Supervisor

Installation
Yum Install Supervisor
In the global configuration file/etc/supervisord.conf, add:

[Program:cm-web]
# Launch Command entry
command=uwsgi/root/myweb/cm-web/config.ini

# Command Program directory
directory=/root/myweb/cm-web
#运行命令的用户名
user=root

autostart=true
autorestart=true
#日志地址
stdout_logfile=/root/myweb/ Cm-web/uwsgi_supervisor.log
Supervisord//    start Supervisor
supervisorctl   //Open command-line 

command line: Help   //view command

Line: status  // View status

or  

supervisorctl status  //view state  

supervisorctl Stop [process name]   //Stops

supervisorctl start [ Process name]

Supervisor-python Process Management Tools
Supervisor Configuration Nginx on Demand

Yum Install Nginx
To add to the configuration file/usr/local/nginx/conf/nginx.conf:

server {
        listen       ;
        SERVER_NAME  public network IP;


        #charset Koi8-r;

        #access_log  logs/host.access.log  main;

        Location/{
            include  uwsgi_params;
            Uwsgi_pass 127.0.0.1:8001;  # point to the internal address applied by UWSGI, all requests will be forwarded to UWSGI processing
            uwsgi_param uwsgi_chdir  /root/myweb/cm-web; # point to Site root
            uwsgi_param Uwsgi_script Manage:app;  # Specify startup program
        }

Finally reboot Nginx

Nginx, reboot, Close command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.