centOS7 flask project deployment centos7 ngxin failed to start: Job for nginx.service failed (80-port solution is occupied) How to create a project, let gitlab triggered automatically build jenkins

CentOS deployment represents the first key point flask, and the problems you might encounter, and solutions with a map.

See pictures, you can look at [download], clarity can see the word

 

【aims】

  • LAN can be accessed via url flask written api
  • After updating the flask project, automatic deployment

 

【tool】

Automatic deployment tools involved:

  • gitlab
  • jenkins

 

Deployment flask project, involving tools:

  • flask Programming
  • gunicorn: gunicorn start method flask project
  • nginx: nginx clear relationship between gunicorn and, when the browser visits flask-api, behind what happened
  • supervisor: Mastering
  • linux: Create a file, change directory, installation tools, start / restart / close the tool, see the occupied port number, and, kill the process

 

[Introduction] Environmental

  • flask operating environment:

  python3, pip3, python virtual environment

  •  Deployment environment:

  centOS7

 

【Steps】

  Configuration gunicorn:

1. Create a virtual environment, and download gunicorn (pip install gunicorn) 

2. Create gunicorn boot files in the root directory of the project, wsgi.py, reads as follows:

from app import create_app

application = create_app()

if __name__ == '__main__':
    application.run()

3. Start command:

gunicorn -w 4 -b 127.0.0.1:8000 wsgi:application

Validation results:

By this time the command request url, you can see the response results. So it is a good distribution gunicorn

curl http://127.0.0.1:8000 /users

 

  Configuring nginx: 

Install nginx:

yum -y install nginx

If prompted package is not available, the solution: 7 under Centos install nginx, use yum install nginx, suggesting the package is not available

If it fails to start nginx, because the port number 80 is occupied, the solution: centos7 ngxin failed to start: Job for nginx.service failed (80-port solution is occupied)

 

Validation results:

After starting nginx, open your browser and enter http://10.2.1.92:8001(8001 port nginx is used)

See the following interface, represents a complete environment to build nginx 

 

 

  Configuration using nginx proxy gunicorn Service

Referring to the specific configuration: gunicorn configuration Nginx +

 

Validation results:

Before the verification results, make sure gunicorn is started

 

  Configuration management supervisor gunicorn process (start | restart | Close)

Finally, use the supervisor to start gunicorn background processes, or turn off a command window, gunicorn process was also killed, of course, not everyone wants to see results

The supervisor configuration, with reference to the use of the supervisor

 

Validation results:

After starting gunicorn by supervisor, turn off the command line window, noted that access address A / routing address (A address what, referring to the FIG.), See the correct response result indicating successfully launched supervisor gunicorn

Such nginx + gunicorn + supervisor deployment flask project is configured.

 

  Configure project updates, automatic deployment:

如果想要实现更新flask项目,自动布署,可以借助jenkins与gitlab的web-hook功能。

具体配置方法(只看前面与gitlab的配置即可,后面写的很乱,不用看):如何创建一个项目,让gitlab自动触发jenkins进行构建

 

验证结果:

在项目中新建1个测试文件:test.py,提交到仓库

在服务器~/.jenkins/workspace/job名称下查看,也存在test.py文件,即表示自动布署配置成功

 

具体的配置不太清楚时,可以看看这1篇,写的很乱,但可能会记录一些具体配置

Guess you like

Origin www.cnblogs.com/kaerxifa/p/11577897.html