BandwagonHost 发表于 2026-7-9 15:10

搬瓦工VPS安装哪吒监控完整教程

BandwagonHost 安装哪吒监控(Nezha Monitoring)+ Nginx 反代 + HTTPS 完整教程

一、什么是哪吒监控(Nezha Monitoring)

哪吒监控(Nezha Monitoring)是一款开源、自托管、轻量级的服务器与网站实时监控和运维工具。它支持通过 Dashboard 查看系统状态、资源使用情况,并通过 Agent 采集被监控主机数据。

本文将一步一步教你如何从零开始在 BandwagonHost (搬瓦工) 机器上使用 Docker 安装与部署哪吒监控系统的 Dashboard 面板,使用 Nginx 反代 Dashboard,并配合 Agent 安装与基本配置。

二、部署前的准备

1. 服务器与网络条件:
- 一台 BandwagonHost (搬瓦工) 或其他可以访问公网的服务器。
- 服务器防火墙和安全策略需允许 Dashboard 使用的端口(默认是 8008)。
- 推荐规格:单核 + 512MB 内存对于大部分场景足够。

2. 域名设置:
- 一个已设置好 A 记录指向 Dashboard 服务器 IP 的域名。
- 如果面板端使用 CDN,还建议准备第二个域名用于 Agent 通信(不通过 CDN)。

三、安装 Dashboard 面板

1. 运行官方安装脚本
在你的 Dashboard 服务器终端执行以下命令:

curl -L https://raw.githubusercontent.com/nezhahq/scripts/refs/heads/main/install.sh -o nezha.sh && chmod +x nezha.sh && sudo ./nezha.sh

如果你的服务器位于中国大陆,可以使用镜像:

curl -L https://gitee.com/naibahq/scripts/raw/main/install.sh -o nezha.sh && chmod +x nezha.sh && sudo CN=true ./nezha.sh


在浏览器中输入 http://your_server_ip:8008 可以访问哪吒监控的 Web 界面。

四、使用 Nginx 反代

1. 安装 Nginx

sudo apt update
sudo apt install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginx


2. 申请证书
安装 Certbot:

sudo apt install certbot python3-certbot-nginx
certbot --version

申请证书:

sudo certbot --nginx -d 你的域名


3. 配置 Nginx 配置文件
文件路径一般在 /etc/nginx/sites-available/default:


server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name dashboard.example.com; # 替换为你的域名
    ssl_certificate         /data/letsencrypt/fullchain.pem; # 域名证书路径
    ssl_certificate_key   /data/letsencrypt/key.pem;      # 域名私钥路径
    ssl_stapling on;
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:10m;
    ssl_protocols TLSv1.2 TLSv1.3;

    underscores_in_headers on;

    # grpc 相关   
    location ^~ /proto.NezhaService/ {
      grpc_set_header Host $host;
      grpc_set_header nz-realip $remote_addr;
      grpc_read_timeout 600s;
      grpc_send_timeout 600s;
      grpc_socket_keepalive on;
      client_max_body_size 10m;
      grpc_buffer_size 4m;
      grpc_pass grpc://dashboard;
    }
    # websocket 相关
    location ~* ^/api/v1/ws/(server|terminal|file)(.*)$ {
      proxy_set_header Host $host;
      proxy_set_header nz-realip $remote_addr;
      proxy_set_header Origin https://$host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_read_timeout 3600s;
      proxy_send_timeout 3600s;
      proxy_pass http://127.0.0.1:8008;
    }
    # web
    location / {
      proxy_set_header Host $host;
      proxy_set_header nz-realip $remote_addr;
      proxy_read_timeout 3600s;
      proxy_send_timeout 3600s;
      proxy_buffer_size 128k;
      proxy_buffers 4 256k;
      proxy_busy_buffers_size 256k;
      proxy_max_temp_file_size 0;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_pass http://127.0.0.1:8008;
    }
}

upstream dashboard {
    server 127.0.0.1:8008;
    keepalive 512;
}


重新加载 Nginx 服务:

sudo systemctl restart nginx


五、配置面板

1. 通过域名访问你的面板。
2. 登录管理后台修改密码(初始账号密码都是 admin)。

六、添加机器

1. 在面板后台复制安装命令。
2. 在目标机器安装 Agent(执行刚才复制的指令即可)。
3. 添加完成后,即可在前台查看机器状态。
4. 你可以添加更多的机器,将指令在其他机器上执行即可实现监控。
页: [1]
查看完整版本: 搬瓦工VPS安装哪吒监控完整教程