+-
如何快速部署 idcops 系统(支持 WSL)

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

近期遇到很多新用户不知道怎么部署或者在部署过程中出错的问题,所以写了可以通过在线安装的 shell 脚本来快速部署 idcops 系统。

脚本采用 gunicorn 的方式部署 django-idcops 系统,配合 nginx 便可以直接上线生成环境使用。

1. 基本环境需求:

需要安装curl库用于下载安装脚本

# CentOS
yum install -y curl
# Ubuntu
apt install -y curl
# Alpine
apk 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,可选 develop
VERSION=master
# 下文可能会使用到的变量
WorkDir=/opt
ProjDir=${WorkDir}/django-idcops
VIRTUALENV=${ProjDir}/env
SrvAddr=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) 运行结果:

image
image
image

IDC运维管理平台 会尽力更新有关 django-idcops 开发或使用相关文章。如果文章中的内容对你有帮助,可以通过右下角点击 在看 支持一下,谢谢。