SPUG自动化运维平台的简单安装

SPUG是一个面向中小型企业的自动化运维平台,方便管理主机,代码发布,任务计划,配置中心,监控等功能。

一、安装SPUG

官方文档上推荐使用docker安装,我这里使用手动部署。

1、拉取spug项目代码

git clone https://github.com/openspug/spug /data/spug
cd /data/spug
git checkout v2.3.13

我这里指定的版本是 v2.3.13,大家根据需要自行修改。

2、下载编译好的前端项目

https://gitee.com/openspug/spug/releases

比如:spug_web_2.3.13.tar.gz

tar xf spug_web_2.3.13.tar.gz -C /data/spug/spug_web/

3、安装依赖,创建运行环境

yum install mariadb-devel python3-devel gcc openldap-devel redis nginx supervisor

如果是 cetnos8 系统,报错

No match for argument: supervisor

请为 centos8 安装 EPEL 源

yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm

创建虚拟环境

cd /data/spug/spug_api
python3 -m venv venv
source venv/bin/activate  

安装python包

pip install -r requirements.txt -i https://pypi.doubanio.com/simple/
pip install gunicorn mysqlclient -i https://pypi.doubanio.com/simple/

注意,这里安装包后,先不退出python虚拟环境,后面初始化数据库和创建管理员账号会需要。

4、配置数据库,我这里使用mysql,大家自行选择

vi spug_api/spug/overrides.py
DEBUG = False
DATABASES = {
    'default': {
        'ATOMIC_REQUESTS': True,
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'spug',           # 替换为自己的数据库名,请预先创建好编码为utf8mb4的数据库
        'USER': 'root',           # 数据库用户名
        'PASSWORD': '123456',     # 数据库密码
        'HOST': '192.168.1.222',  # 数据库地址
        'OPTIONS': {
            'charset': 'utf8mb4',
            'sql_mode': 'STRICT_TRANS_TABLES',
            #'unix_socket': '/opt/mysql/mysql.sock' # 如果是本机数据库,且不是默认安装的Mysql,需要指定Mysql的socket文件路径
        }
    }
}

注意,数据库地址,用户名,密码,请自行修改。

5、初始化数据库

cd /data/spug/spug_api
python manage.py initdb

注意这里,需要在python虚拟环境中运行上述命令,不然在我的 centos8 中会报 bash: python: 未找到命令

6、创建默认管理员账号

python manage.py useradd -u admin -p admin -s -n 超级管理员

7、创建启动服务脚本

vi /etc/supervisord.d/spug.ini
[program:spug-api]
command = bash /data/spug/spug_api/tools/start-api.sh
autostart = true
stdout_logfile = /data/spug/spug_api/logs/api.log
redirect_stderr = true

[program:spug-ws]
command = bash /data/spug/spug_api/tools/start-ws.sh
autostart = true
stdout_logfile = /data/spug/spug_api/logs/ws.log
redirect_stderr = true

[program:spug-worker]
command = bash /data/spug/spug_api/tools/start-worker.sh
autostart = true
stdout_logfile = /data/spug/spug_api/logs/worker.log
redirect_stderr = true

[program:spug-monitor]
command = bash /data/spug/spug_api/tools/start-monitor.sh
autostart = true
stdout_logfile = /data/spug/spug_api/logs/monitor.log
redirect_stderr = true

[program:spug-scheduler]
command = bash /data/spug/spug_api/tools/start-scheduler.sh
autostart = true
stdout_logfile = /data/spug/spug_api/logs/scheduler.log
redirect_stderr = true

8、创建前端nginx配置文件

vi /etc/nginx/conf.d/spug.conf
server {
    listen 80;
    server_name 192.168.1.111;     # 修改为自定义的访问域名
    root /data/spug/spug_web/build/;
    client_max_body_size 20m;   # 该值会影响文件管理器可上传文件的大小限制,请合理调整

    gzip  on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 7;
    gzip_types       text/plain text/css text/javascript application/javascript application/json;
    gzip_vary on;

    location ^~ /api/ {
        rewrite ^/api(.*) $1 break;
        proxy_pass http://127.0.0.1:9001;
        proxy_read_timeout 180s;
        proxy_redirect off;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location ^~ /api/ws/ {
        rewrite ^/api(.*) $1 break;
        proxy_pass http://127.0.0.1:9002;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location / {
        try_files $uri /index.html;
    }
}

注意,我这里 server_name 配置的是 192.168.111,大家可以根据情况自行修改。

9、启动服务

systemctl enable nginx
systemctl enable redis
systemctl enable supervisord

systemctl restart nginx
systemctl restart redis
systemctl restart supervisord

10、退出python虚拟环境

deactivate

11、访问 192.168.1.111,如果一直转圈,看看防火墙。

常见问题:

如果访问时报 请求失败: 502 Bad Gateway,通过查看nginx错误日志

cat /var/log/nginx/error.log
failed (13: Permission denied) while connecting to upstream

尝试暂时关闭 selinux

setenforce 0

或者永久关闭

vi /etc/selinux/config

中将 SELINUX=disabled,重启系统。

原文地址:https://www.cnblogs.com/jkko123/p/13872984.html