之前写的 idcops 部署文档大多是以 uwsgi 为主,uwsgi 是绝对于 gunicorn 来说更全面的应用服务器。

近期遇到很多新用户不晓得怎么部署或者在部署过程中出错的问题,所以写了能够通过在线装置的 shell 脚本来疾速部署 idcops 零碎。

脚本采纳 gunicorn 的形式部署 django-idcops 零碎,配合 nginx 便能够间接上线生成环境应用。

1. 根本环境需要:

须要装置curl库用于下载安装脚本

# CentOSyum install -y curl# Ubuntuapt install -y curl# Alpineapk add curl

2. 装置指令:

curl -sL https://gitee.com/wenvki/django-idcops/raw/master/auto_install.sh |sh

已测试零碎:

  • CentOS Linux 7 (Core)
  • Ubuntu 18.04.4 LTS (Windows 10 WSL2)
  • Alpine Linux v3.12 (Windows 10 WSL2)

3. 局部可选配置参数或变量:
装置目录:/opt/django-idcops/

# shell 参数等号间不能有空格# 默认端口号:(gunicorn),可选其余 tcp端口SrvPort=18113# idcops 版本: 默认 master,可选 developVERSION=master# 下文可能会应用到的变量WorkDir=/optProjDir=${WorkDir}/django-idcopsVIRTUALENV=${ProjDir}/envSrvAddr=0.0.0.0# 日志文件:LogFile=${ProjDir}/logs/idcops.log# Pid文件:PidFile=${ProjDir}/run/idcops.pid

4. 启动与进行:

# 终端下执行# 我的项目目录 /opt/django-idcops/cd /opt/django-idcops/# 启动:RUN_SERVER="nohup ${VIRTUALENV}/bin/gunicorn --workers 3  --bind ${SrvAddr}:${SrvPort}  --pid ${PidFile}  --log-file ${LogFile}  --access-logfile ${LogFile}  --pythonpath ${ProjDir}  idcops_proj.wsgi:application > /dev/null 2>&1 &"eval ${RUN_SERVER}# 进行:kill `cat /opt/django-idcops/run/idcops.pid`

5. Nginx 反向代理:

nginx 反向代理服务器次要是能够更高效地解决动态文件,其余申请还是转发到 gunicorn 进行解决。

很多同学不晓得 nginx 配置文件放哪里才失效,这边略微再提一下,倡议先自行搜索引擎找一下如何配置 nginx 。

# CentOS yum 装置的 nginx# 主配置文件/etc/nginx/nginx.conf# 默认的 Server 段虚拟主机配置目录/etc/nginx/conf.d/# 个别编译装置的 nginx# 默认编译门路主配置文件: /usr/local/nginx/conf/nginx.conf
# 上面这段保留为:idcops_nginx.conf 放到 /etc/nginx/conf.d/ 目录下server { listen 80; server_name idcops.iloxp.com 192.168.21.21; # 将下面 server_name 的 192.168.21.21 换成你nginx服务器的IP地址 root /opt/django-idcops/; # 将下面 root 的门路换成你 django-idcops 我的项目的目录门路 # include idcops_nginx_ssl_conf; location / { # Gunicorn proxy_pass http://127.0.0.1:18113; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; } location /static { alias /opt/django-idcops/static; expires      7h; access_log off; }  location /media { alias /opt/django-idcops/media; expires      7h; access_log off; } # access_log /opt/django-idcops/logs/idcops_access.log; error_log /opt/django-idcops/logs/idcops_error.log;  location ~ /.ht { deny  all; }}

6. Alpine Linux v3.12 (WSL2) 运行后果:




IDC运维治理平台 会尽力更新无关 django-idcops 开发或应用相干文章。如果文章中的内容对你有帮忙,能够通过右下角点击 在看 反对一下,谢谢。