Deploy and run configuration

Running multiple instances tornado

  Page response is not particularly computationally intensive process

  Examples of use of a plurality of full CPU

  How to deal with multi-port

  Linux common application service configuration mode nginx and supervisord: + project using master configuration file configuration file

Use supervisor monitoring process tornado

Installation (if installed using pip pay attention to see whether you need to specify python2 version)

supervisor default only supports Python2

  sudo apt-get install supervisor

After activation virtualenv Python3 or execution, installation supervisor support Python3 version

pip install supervisor to install the latest version

Check the main configuration file deploy / supervisord.conf (If the directory does not exist you need to create)

Use main command generates a service profile

echo_supervisord_conf> deploy / supervisord.conf (if not deploy directory is established)

Check whether inculde configuration, it does not add

[the include] 
Files = Super / * conf

If you do not have permission to sudo generated by the current directory, then
sudo cp deploy / supervisord.conf /etc/supervisor/supervisord.conf past

increases Supervisor project running configuration files (such as name tudo_super.conf) to / etc / supervisor / super

# Add a group tornadoes

[group:tornadoes]

programs = tornado-5000,tornado-5001,tornado-5002

 

# Define three tornado process configuration

 

[program:tornado-5000]

directory = / home / pyvip / ws / tudo36 /; program startup directory

command = /home/pyvip/.virtualenvs/tudo36/bin/python /home/pyvip/ws/tudo36/app.py --port = 5000 --degbu = False; start command, and manually start command is the command line like, can not be replaced with a home where attention ~

autostart = true; automatically started when the start supervisord

startsecs = 5; no quit unexpectedly after starting five seconds, it is deemed to have been properly started

autorestart = true; automatic restart after abnormal exit procedure

startretries = 3; retries failed to start automatically, the default is 3

user = pyvip; start with which users

redirect_stderr = true; redirect stderr to stdout, default false

stdout_logfile_maxbytes = 20MB; stdout log file size, default 50MB

stdout_logfile_backups = 20; stdout log file backup Number

; Stdout log file, you need to pay attention to when not start properly when the specified directory does not exist, so the need to manually create the directory (supervisord automatically creates a log file)

stdout_logfile = /tmp/tornado_app_5000.log

loglevel = info

 

[program:tornado-5001]

directory = /home/pyvip/ws/tudo36/

command = /home/pyvip/.virtualenvs/tudo36/bin/python app.py --port=5001

autostart = true

startsecs = 5

autorestart = true

startretries = 3

user = pyvip

redirect_stderr = true

stdout_logfile_maxbytes = 20MB

stdout_logfile_backups = 20

stdout_logfile = /tmp/tornado_app_5001.log

loglevel = info

 

[program:tornado-5002]

directory = /home/pyvip/ws/tudo36/

command = /home/pyvip/.virtualenvs/tudo36/bin/python app.py --port=5002

autostart = true

startsecs = 5

autorestart = true

startretries = 3

user = pyvip

redirect_stderr = true

stdout_logfile_maxbytes = 20MB

stdout_logfile_backups = 20

stdout_logfile = /tmp/tornado_app_5002.log

loglevel = info

```

### start-up and management

 

##### Start supervisor

 

Be sure to start the daemon program (supervisord) to perform management operations, otherwise it will error (is recommended that you do not use sudo to run)

 

> Use the default main configuration file /etc/supervisor/supervisord.conf

> **sudo supervisord**

> Explicitly specify the main configuration file

> sudo supervisord -c /home/pyvip/working/supervisord.conf

> Use user user starts supervisord

> sudo supervisord -u user

 

##### View, operational process status

 

> ** (tornado) pyvip VIP @: ~ / ws / all $ sudo supervisorctl ** 

>  [sudo] password for pyvip:

> tornadoes:tornado-8000           RUNNING   pid 17652, uptime 0:00:28

> tornadoes:tornado-8001           RUNNING   pid 17653, uptime 0:00:28

> tornadoes:tornado-8002           RUNNING   pid 17654, uptime 0:00:28

 

> \ # Stops tornado-8001 server process

>  supervisor> stop tornadoes:tornado-8001

>  tornados:tornado-8001: stopped

 

> \ # Stops throughout the tornado server process group

>

> supervisor> stop tornadoes:

> tornadoes:tornado-8000: stopped

> tornadoes:tornado-8001: stopped

> tornadoes:tornado-8002: stopped

> supervisor> status

> tornadoes:tornado-8000           STOPPED   Jun 26 07:43 PM

> tornadoes:tornado-8001           STOPPED   Jun 26 07:43 PM

> tornadoes:tornado-8002           STOPPED   Jun 26 07:43 PM

 

##### supervisorctl Commands

 

> Stop one process, program_name is [program: x] where x

>  supervisorctl stop program_name

> Starts a process

>  supervisorctl start program_name

> Restart a process

>  supervisorctl restart program_name

> End all part of a process called groupworker this packet (start, restart empathy)

>  supervisorctl stop groupworker:

> End groupworker: name1 this process (start, restart empathy)

>  supervisorctl stop groupworker:name1

> Stop All process, note: start, restart, stop will not load the latest configuration files

>  supervisorctl stop all

> Load latest configuration file, stop the original process and press start new configuration, management of all processes

>  supervisorctl reload

> According to the latest configuration file, start a new configuration or changes to the process, there is no configuration changes and restart the process will not be affected

>  supervisorctl update

 

 

 

## use Nginx as a reverse proxy

 

### with tornado service use

 

![img](https://upload-images.jianshu.io/upload_images/1446087-de9c70d0e067384a.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/688) 

 

 

 

### to install and run

 

- Installation

  `sudo apt-get install nginx`

- detect the correct configuration file available

  `sudo nginx -t`

- Run

  `sudo nginx`

- After modifying or adding to the configuration file restart

  `sudo nginx -s reload`

 

 

 

### nginx configuration file

 

The main configuration file is `/ etc / nginx / nginx.conf`

 

** profile corresponding to the item into `/etc/nginx/conf.d / *. Conf` or` / etc / nginx / sites-enabled / * `**

 

For example tudo_nginx file

 

```nginx

upstream tornadoes{

    server 127.0.0.1:8000; # local access only 127.0.0.1

    server 127.0.0.1:8001;

    server 127.0.0.1:8002;

}

 

proxy_next_upstream error;

 

server {

    listen 8888; # 80 are generally

    server_name 127.0.0.1; # ip corresponding to the actual situation fill

 

    location /{

        proxy_pass_header Server;

        proxy_set_header Host $http_host;

        proxy_redirect off;

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header X-Scheme $scheme;

        # The requester proxy server tornado passed, load balancing

        proxy_pass http://tornadoes;

    }

}

```

 

 

 

### common problem

 

Operation 1. Linux directories and files

Tab 2. Enter command is completed with the operating

3. Press the order of the document operation (supervisord did not start being given)

4. supervisor of the web management interface

The configuration file is modified custom application routine

6. nginx configuration to explain the role, conf file

7. vim and use sudo

8. Why use nginx

 

Guess you like

Origin www.cnblogs.com/wdty/p/10966244.html