posts - 404,  comments - 115,  views - 118万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

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

 

一、安装SPUG

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

1、拉取spug项目代码

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

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

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

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

比如:spug_web_2.3.13.tar.gz

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

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

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

如果是 cetnos8 系统,报错

1
No match for argument: supervisor

请为 centos8 安装 EPEL 源

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

创建虚拟环境

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

安装python包

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

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

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

1
vi spug_api/spug/overrides.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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、初始化数据库

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

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

6、创建默认管理员账号

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

7、创建启动服务脚本

1
vi /etc/supervisord.d/spug.ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[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配置文件

1
vi /etc/nginx/conf.d/spug.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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、启动服务

1
2
3
4
5
6
7
systemctl enable nginx
systemctl enable redis
systemctl enable supervisord
 
systemctl restart nginx
systemctl restart redis
systemctl restart supervisord

10、退出python虚拟环境

1
deactivate

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

 

常见问题:

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

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

尝试暂时关闭 selinux

1
setenforce 0

或者永久关闭

1
vi /etc/selinux/config

中将 SELINUX=disabled,重启系统。

 

posted on   怀素真  阅读(3801)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决
历史上的今天:
2017-10-25 docker-ce-17.09 网络基础配置
点击右上角即可分享
微信分享提示