编程知识 cdmana.com

Deployment record of WSO vgiue

Deployment documents

1. Directory planning :

/home/useradmin/
                ├── applications  --- Application code deployment directory 
                │   ├── DEV  --- development environment 
                │   └── STG   --- Test environment 
                ├── applogs  -- Log file directory 
                │   ├── DEV --- development environment 
                │   └── STG   --- Test environment 
                ├── appvenv ---python Environmental Directory 
                │   ├── DEV --- development environment 
                │   └── STG   --- Test environment 
                ├── installpackage --- Download package or install package file 
                ├── scripts   --- Start scripts or update scripts automatically 
                └── tmp  -- The temporary file 

 Port planning :
 development environment  DEV 38000
 Test environment  STG 38001
2. Preparation before deployment :

Engineering uses environment variables VIRTUAL_ENV To identify the current environment is in local, dev, stg still prd Next , And then automatically start with different configuration files according to the environment ( see conf/settings/__init\__.py).
therefore ,

  1. To start a project using a virtual environment , also , The location of the virtual environment is shown in the figure above ( If you don't start with a virtual environment , To create a /home/useradmin/applogs/{DEV,STG,PRD}/ Catalog , And manually configure VIRTUAL_ENV The environment is /home/useradmin/appvenv/{DEV,STG,PRD}/venv
  2. Engineering use /home/useradmin/applogs/{DEV,STG,PRD} To store relevant logs , Ensure directory permissions when deploying
  3. Interpreter version : 3.6.5(3.6.x There should be no problem )

2. Project deployment :

Deployment structure : nginx Hosting all static files + uwsgi Hosting back end projects

All static files contain two parts : Basic static files and front-end projects required by the back-end framework

  1. To configure pip Source

    vim ~/.pip/pip.conf

    [global]
    timeout = 6000
    index-url = {  Intranet pip Source  }
  2. Into the current environment python A virtual environment
  3. cd To the project catalog , Installation works depend on , Make sure you are currently in a virtual environment , Otherwise, the dependency will be installed in the global environment :

    pip3 install -r requirements.txt
  4. Database initialization :

    python manage.py migrate

    If you are prompted db error, Reference Engineering conf/settings In the configuration file of the corresponding environment DB Configure to confirm that the database configuration is correct

  5. install uwsgi

    pip3 install uwsgi

    If you are prompted to abort compilation : plugins/python/uwsgi_python.h:2:20: Fatal error :Python.h: There is no file or directory , that deactivate, Back to the global environment sudo yum install python3-devel.x86_64 then , Back to the virtual environment pip3 install uwsgi

  6. Log files needed

    nginx The default log location for :
    /var/log/nginx/access.log and error.log
    
    uwsgi The Journal of the project uwsgi.ini It is specified in : 
    # /var/log/uwsgi/uwsgi-deam.log
    /home/useradmin/applogs/DEV/uwsgi-deam.log
    
    django The Journal of the project conf Specify the configuration file of the corresponding environment :
    /home/useradmin/applogs/DEV/djnago-req.log
    /home/useradmin/applogs/DEV/djnago-db.log
  7. Use uwsgi Start the project ,cd Go to the project directory , by uwsgi Specify the environment to start

    uwsgi --ini uwsgi.ini:DEV
    uwsgi --ini uwsgi.ini:STG
    uwsgi --ini uwsgi.ini:PRD

    May encounter log file read and write permission problems , We need to allocate the corresponding files to uwsgi The user specified in useradmin,

    chown useradmin:useradmin xx.log  #  Sometimes the parent file also needs 
  8. To configure nginx

    nginx Main configuration and uwsgi Docking , Static project and managed files

    First collect the static files to the specified static root directory , Go to the project directory

    python manager.py collectstatic

    Then edit nginx.conf, Because the front end uses the front end by default ip and port To request back-end resources , Causes the front and back ends to use the same nginx.conf Of server( Use the same server Another reason for this is to avoid cross domain problems ), therefore :

    1. Front and back end resources need to be in URL On the Internet ( The back-end using /api To mark back-end resources )
    2. from /static/ Filter out the static files used by the back-end framework under the path rest_framewor and admin
 server {
     listen       38000 default_server;
     # listen       [::]:80 default_server;
     server_name  _;
     root  /home/useradmin/applications/DEV/pauth_web/dist/;   #  Front end project catalog 

     # Load configuration files for the default server block.
     include /etc/nginx/default.d/*.conf;

     location /api/ {                                          #  Back end api root directory 
        include uwsgi_params;
        # uwsgi_pass unix:///run/DEV/pauth.sock;               #  Abandoning 
        uwsgi_pass unix:///home/useradmin/applications/DEV/run/pauth.sock
     }

     location /static/rest_framework/ {                        #  Back end Browseable API Static files needed 
       alias /home/useradmin/applications/DEV/static/rest_framework/;
     }

     location /static/admin/ {                                 #  Back end admin Static files needed 
       alias /home/useradmin/applications/DEV/static/admin/;
     }

     error_page 404 /404.html;
         location = /40x.html {
     }

     error_page 500 502 503 504 /50x.html;
         location = /50x.html {
     }
 }

版权声明
本文为[focus]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201225143156584C.html

Scroll to Top