spug项目配置监控报警

一、启动spug项目

1.spug代码仓库地址:

spug: 开源运维平台:面向中小型企业设计的无 Agent的自动化运维平台,整合了主机管理、主机批量执行、主机在线终端、文件在线上传下载、应用发布、任务计划、配置中心、监控、报警等一系列功能。 - Gitee.com

注意:如果要找怎么进行容器化部署的详细说明,直接在这个仓库看官方文档就行了

一般流程:

1)进入docs/docker目录,执行docker-compose up -d

2)docker-compose ps查看容器的端口,打开浏览器查看效果

3)新建登录用户

docker exec spug init_spug admin spug.cc

使用用户名admin和密码spug.cc登录

二、新建报警联系人

1.钉钉机器人配置:

新建钉钉群,在群设置中找到“机器人”菜单,再点击添加机器人

添加机器人之后可以点击创建后的机器人设置,可以看到Webhook,将这个Webhook对应的网址拷贝到上面“新建报警联系人”弹窗中的“钉钉”右边的输入框中

2.邮件配置:

三、新建报警联系组

四、监控执行=》新建任务

为了尽快看到效果,都选最小的时间

五、测试效果

停掉nginx进程

systemctl stop nginx

等待之后看钉钉和邮件

当然,如果你配置了微信,也有类似的效果

再启动nginx


报警历史中也能看到报警发生和和故障恢复的记录:

 六、自定义脚本

a=$(free | grep Mem | awk '{print $3/$2 * 100.0}' | bc -l)
b=8
num=$(echo "$a > $b" | bc -l)

if (( "$num == 1" | bc -l )); then
    echo "used内存超过${b}%!!"
    exit 1
fi

 

七、修改“来自Spug运维平台”底部文案

因为是后端代码导致的问题,所以直接修改后端代码:

1.获取3.2.4版本的代码:

 2.install.sh

#!/bin/bash
# Copyright: (c) OpenSpug Organization. https://github.com/openspug/spug
# Copyright: (c) <spug.dev@gmail.com>
# Released under the AGPL-3.0 License.

set -e


function spuy_banner() {

echo "                           ";
echo " ####  #####  #    #  #### ";
echo "#      #    # #    # #    #";
echo " ####  #    # #    # #     ";
echo "     # #####  #    # #  ###";
echo "#    # #      #    # #    #";
echo " ####  #       ####   #### ";
echo "                           ";

}


function init_system_lib() {
    source /etc/os-release
    case $ID in
        centos|fedora|rhel|rocky)
            echo "开始安装/更新可能缺少的依赖: git mariadb-server mariadb-devel python3-devel gcc openldap-devel redis nginx supervisor python36"
            yum install -y epel-release
            yum install -y git mysql-server python3-devel gcc openldap-devel redis nginx supervisor python39 python39-devel
            sed -i 's/ default_server//g' /etc/nginx/nginx.conf
            MYSQL_CONF=/etc/my.cnf.d/spug.cnf
            SUPERVISOR_CONF=/etc/supervisor/conf.d/spug.conf
            REDIS_SRV=redis
            SUPERVISOR_SRV=supervisord
            ;;

        debian|ubuntu|devuan)
            echo "开始安装/更新可能缺少的依赖: git mariadb-server libmariadbd-dev python3-venv libsasl2-dev libldap2-dev redis-server nginx supervisor"
            apt update
            apt install -y git mariadb-server libmariadbd-dev python3-dev python3-venv libsasl2-dev libldap2-dev redis-server nginx supervisor
            rm -f /etc/nginx/sites-enabled/default
            MYSQL_CONF=/etc/mysql/conf.d/spug.cnf
            SUPERVISOR_CONF=/etc/supervisor/conf.d/spug.conf
            REDIS_SRV=redis-server
            SUPERVISOR_SRV=supervisor
            ;;
        *)
            exit 1
            ;;
    esac
}


function install_spug() {
  echo "开始安装Spug..."
  mkdir -p /data/
  cd /data/
  git clone --depth=1 https://gitee.com/openspug/spug.git
#   curl -o /tmp/web_latest.tar.gz https://spug.dev/installer/web_latest.tar.gz
#   tar xf /tmp/web_latest.tar.gz -C spug/spug_web/
  cd spug/spug_api
  python3.9 -m venv venv
  source venv/bin/activate
  venv/bin/python3.9 -m pip install --upgrade pip

  pip3.9 install wheel -i https://pypi.doubanio.com/simple/
  pip3.9 install gunicorn mysqlclient -i https://pypi.doubanio.com/simple/
  pip3.9 install -r requirements.txt -i https://pypi.doubanio.com/simple/
}


function setup_conf() {

  echo "开始配置Spug配置..."
# mysql conf
cat << EOF > $MYSQL_CONF
[mysqld]
bind-address=0.0.0.0
EOF

# spug conf
cat << EOF > spug/overrides.py
DEBUG = False
ALLOWED_HOSTS = ['0.0.0.0','192.168.137.12','127.0.0.1']

DATABASES = {
    'default': {
        'ATOMIC_REQUESTS': True,
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'spug',
        'USER': 'spug',
        'PASSWORD': 'spug.dev',
        'HOST': '192.168.137.12',
        'OPTIONS': {
            'charset': 'utf8mb4',
            'sql_mode': 'STRICT_TRANS_TABLES',
        }
    }
}
EOF

cat << EOF > $SUPERVISOR_CONF
[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
EOF

cat << EOF > /etc/nginx/conf.d/spug.conf
server {
        listen 80 default_server;
        root /data/spug/spug_web/build/;

        location ^~ /api/ {
                rewrite ^/api(.*) \$1 break;
                proxy_pass http://127.0.0.1:9001;
                proxy_redirect off;
                proxy_set_header X-Real-IP \$remote_addr;
        }

        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-Real-IP \$remote_addr;
        }

        error_page 404 /index.html;
}
EOF


systemctl restart mysqld
systemctl enable mysqld

#mysql -e "create database spug default character set utf8mb4 collate utf8mb4_unicode_ci;"
#mysql -e "grant all on spug.* to spug@'%' identified by 'spug.dev'"
#mysql -e "flush privileges"

source venv/bin/activate

#python3.9 manage.py initdb
#python3.9 manage.py user add -u admin -p admin.dev -s -n 管理员
#python3.9 manage.py user add -u spug -p spug.dev -s -n 开发
#python3.9 manage.py user add -u yunwei -p yunwei.dev -s -n 运维

python3.9 /data/spug/spug_api/manage.py updatedb



systemctl enable nginx
systemctl enable $REDIS_SRV
systemctl enable $SUPERVISOR_SRV

systemctl restart nginx
systemctl restart $REDIS_SRV
systemctl restart $SUPERVISOR_SRV

}


spuy_banner
init_system_lib
install_spug
setup_conf

echo -e "\n\n\033[33m安全警告:默认的数据库和Redis服务并不安全,请确保其仅监听在127.0.0.1,推荐参考官网文档自行加固安全配置!\033[0m"
echo -e "\033[32m安装成功!\033[0m"
echo "默认管理员账户:admin  密码:admin.dev"
echo "默认数据库用户:spug   密码:spug.dev"

使用代码编辑器找到“来自Spug运维平台”关键字replace all

找到“来自Spug官网(测试)”关键字replace all

3.然后启动后端:

cd /data/spug/spug_api
source venv/bin/activate
python3.9 manage.py runserver 0.0.0.0:8000
# bash /data/spug/spug_api/tools/start-api.sh #前端打包,需要启动后端的9100端口时使用
bash /data/spug/spug_api/tools/start-ws.sh
bash /data/spug/spug_api/tools/start-worker.sh
bash /data/spug/spug_api/tools/start-monitor.sh
bash /data/spug/spug_api/tools/start-scheduler.sh

 4.前端测试

新建联系人的时候可以使用输入框右边的闪电标志测试

 注意: 如果点击输入框右边的闪电标志,测试提示去“系统设置-基本设置”去输入调用凭据

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值