Forum福利VPS usage sharing 4—Pleasure of Piercing: Building the Nezha Monitoring Panel

论坛福利VPS使用分享-目录

论坛福利VPS使用分享
论坛福利VPS使用分享2—简单搭建自己的导航页
论坛福利VPS使用分享3—利用CF OR回源或EdgeOne CDN去除NAT端口号
论坛福利VPS使用分享4—扎针的快乐:哪吒监控面板搭建


:memo: 注意

所有操作基于以下环境,包括但不限于:

  • 操作系统为debian12
  • 已安装1Panel
  • 1Panel应用商店中已安装OpenResty,替代端80和443端口如下
    image
  • 已在VPS控制面板的网络页面映射了替代80,443的端口
    image
  • 已通过CF OR回源将443回源至母鸡映射的替代443端口

*** 实际使用中请使用自己实际分配到的母鸡端口替换演示端口 ***


:last_track_button: 准备

  1. 一个Cloudflare账号
  2. 一个托管在该Cloudflare账号下的域名
  3. 将该域名设置好 A 记录,指向VPS服务器 IP ,并开启CDN(小黄云),本次以 "status.udotech.me"演示
  4. 该域名开启gRPC及Websocket

:triangular_ruler: 在服务器中安装哪吒Dashboard

  • 通过SSH连接服务器后运行以下脚本
curl -L https://raw.githubusercontent.com/nezhahq/scripts/refs/heads/main/install.sh -o nezha.sh && chmod +x nezha.sh && sudo ./nezha.sh
  • 以 Docker 安装为例(我本人偏向应用之间的隔离,所以比较钟爱使用1Panel和docker部署),根据提示输入以下信息:
    请输入站点标题: - 自定义站点标题。
    请输入暴露端口: - 公开访问端口(默认 8008,可自定义)。
    nezha-agent 连接地址: - 解析好的Dashboard访问地址(如"status.udotech.me:443")
    请指定后台语言: - 选择语言偏好。
    输入完成后,等待拉取 Docker 镜像

此处填写的信息可以通过Dashboard后台页面进行修改,即使填错了也无需在意(暴露端口影响反代配置)

        * 如果需要再次运行安装脚本,可输入以下命令:

./nezha.sh

:straight_ruler: 配置反向代理文件

  • 添加域名反代,配置SSL证书
    略(参考论坛福利VPS使用分享)
  • 修改反代配置,增加CDN回源IP
    1. 选择反代dashboard的域名,进入配置页面
    2. 选择域名设置中的配置文件
    3. 添加gRPC以及websocket相关配置(注意修改proxy_passserver的设定端口,为前文设置的暴露端口)
    4. 点击保存并重载使配置生效
添加grpc、websocket及CFCDN回源IP内容
      # grpc 相关    
    location ^~ /proto.NezhaService/ {
        grpc_set_header Host $host; 
        grpc_set_header nz-realip $http_CF_Connecting_IP; # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认
        # grpc_set_header nz-realip $remote_addr; # 如果你使用nginx作为最外层,就把上面一行注释掉,启用此行
        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 $http_cf_connecting_ip; # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认
        # proxy_set_header nz-realip $remote_addr; # 如果你使用nginx作为最外层,就把上面一行注释掉,启用此行
        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; 
    }
    underscores_in_headers on; 
    set_real_ip_from 103.21.244.0/22; # 替换为你的 CDN 回源 IP 地址段
    set_real_ip_from 103.22.200.0/22; 
    set_real_ip_from 103.31.4.0/22; 
    set_real_ip_from 104.16.0.0/13; 
    set_real_ip_from 104.24.0.0/14; 
    set_real_ip_from 108.162.192.0/18; 
    set_real_ip_from 131.0.72.0/22; 
    set_real_ip_from 141.101.64.0/18; 
    set_real_ip_from 162.158.0.0/15; 
    set_real_ip_from 172.64.0.0/13; 
    set_real_ip_from 173.245.48.0/20; 
    set_real_ip_from 188.114.96.0/20; 
    set_real_ip_from 190.93.240.0/20; 
    set_real_ip_from 197.234.240.0/22; 
    set_real_ip_from 198.41.128.0/17; 
    real_ip_header CF-Connecting-IP; # 替换为你的 CDN 提供的私有 header,此处为 CloudFlare 默认
    # 如果你使用nginx作为最外层,把上面两行注释掉
}
upstream dashboard {
    keepalive 512; 
    server 127.0.0.1:8008; 
}




登录并设置Dashboard


安装Agent被控端

  • 确认系统设置中Agent对接地址、端口和TLS开启开关配置正确
  • 复制Agent安装链接
    1. 点击服务器
    2. 点击安装命令
    3. 选择对应的安装平台,点击会自动复制Agent安装指令
    4. 到被控端安装Agent
    5. 被控端上线,修改服务器显示名称


以上,即可完成最基本的服务器监控

6 Likes

占楼待编辑

1 Like

:xhj006: :xhj16:

哪吒有一个毛病 就是不能分组

:xhj16:

感谢分享

谢谢分享。。感谢

可以分组啊,V0 V1都可以

V6一直失败

nat mini机的V6本身是不通的
如果dashboard是在v4 only的机器上,你的agent机器是v6 only的话需要在CF里把V6兼容打开
或者给你v6 only机器装warp开个v4出口才能通

学习到了

I have learned, thank you