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,重啟系統。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM