完整教程:搭建哪吒监控 V1 配置CDN,并启用 Agent TLS 连接
前期准备
Cloudflare 用来配置 CDN 和 SSL 证书
一个域名(如 qq.com)
两台服务器,A 服务器安装 Dashboard 面板 与 Nginx,B 服务器安装 Agent 探针。如果需要,也可以选择将两者安装在同一台服务器上。
1. Cloudflare 配置 1.1 添加 A 记录,指定到 A 服务器 IP
1.2 开启 gRPC 与 WebSockets
1.3 创建 SSL 证书,并复制到 A 服务器 /etc/ssl/private/ 目录
1 2 证书(.cer) 复制到 /etc/ssl/private/fullchain.cer 私钥(.key) 复制到 /etc/ssl/private/private.key
2. 安装 Dashboard 哪吒监控面板 哪吒面板(Dashboard)用于管理和展示探针数据。 官方手册
2.1 执行脚本
1 2 3 4 5 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
2-2. 安装流程
3. 安装 Nginx 并配置反向代理 3.1 安装 Nginx
1 2 3 4 5 6 7 apt update apt install -y curl wget sudo unzip apt install -y nginx openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
3.2. 配置 Nginx 反向代理、gRPC
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 worker_processes 1 ; events { worker_connections 1024 ; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65 ; server { listen 443 ssl http2; listen [:: ]:443 ssl http2; server_name qq.com; ssl_certificate /etc/ssl/private/fullchain.cer; ssl_certificate_key /etc/ssl/private/private.key; ssl_stapling on; ssl_session_timeout 1d; ssl_session_cache shared:SSL:10m; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384' ; ssl_prefer_server_ciphers on; ssl_dhparam /etc/ssl/certs/dhparam.pem; set_real_ip_from 103.21 .244 .0 /22; 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; underscores_in_headers on; real_ip_header CF-Connecting-IP; real_ip_recursive on; proxy_temp_file_write_size 512k; location ^~ /proto.NezhaService/ { grpc_set_header Host $host; grpc_set_header nz-realip $http_CF-Connecting-IP; grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 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; } location ~* ^/api/v1/ws/(server|terminal|file)(.*)$ { proxy_set_header Host $host; proxy_set_header nz-realip $http_CF-Connecting-IP; 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; } location / { proxy_set_header Host $host; proxy_set_header nz-realip $http_CF-Connecting-IP; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 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_pass http://127.0.0.1:8008; } } upstream dashboard { server 127.0 .0 .1 :8008; keepalive 512 ; } }
3.3. 重启 Nginx
1 2 3 4 5 6 7 8 9 nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful systemctl restart nginx && systemctl status nginx
4. 安装 Agent 探针 登录 (Dashboard) 面板,首次登录的默认用户名和密码均为 admin,并复制 Agent 安装命令,并在 B 服务器 安装。
1 2 3 4 5 6 7 8 9 10 11 12 apt update apt install -y curl wget sudo unzip root@s38455:~# curl -L https://raw.githubusercontent.com/nezhahq/scripts/main/agent/install.sh -o agent.sh && chmod +x agent.sh && env NZ_SERVER=qq.com:443 NZ_TLS=true NZ_CLIENT_SECRET=DFF4dDF44ffsfdfdfFFF ./agent.sh % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 4947 100 4947 0 0 15564 0 --:--:-- --:--:-- --:--:-- 15605 Installing... 2025/03/07 01:04:15 Successfully executed action install! nezha-agent successfully installed
5. 美化面板 Dashboard 与 监控节点 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 https://nezhadash-docs.buycoffee.top/custom-code https://nezhainfojson.pages.dev/ https://1keji.net/t/topic/31 https://dnsdaquan.com/ https://ipw.cn/doc/else/dns.html https://www.nodeseek.com/post-82748-1 https://www.nodeseek.com/post-68572-1 https://hunter.qianxin.com 语法搜索:ip.city="广州" AND ip.isp="电信" AND (ip.port=80 OR ip.port=443) AND ip.asn="4134"
6. 安全设置 6.1 (Dashboard) 面板开启 OAuth2 绑定第三方网站账户 官方说明
访问 GitHub 开发者设置 创建 OAuth 应用,并记录 Client ID 与 Client secrets:
打开 Dashboard 面板配置,设置 OAuth2
1 2 3 4 5 6 7 8 9 10 11 oauth2: GitHub: clientid: "FF5sdfsfsbdb23dbf" clientsecret: "sfsdf6s5df65sf65sd6f5sd6f5sf5s6df" endpoint: authurl: "https://github.com/login/oauth/authorize" tokenurl: "https://github.com/login/oauth/access_token" userinfourl: "https://api.github.com/user" useridpath: "id"
登录 Dashboard 面板,进入个人信息,完成 GitHub 授权,即可通过 GitHub 账号登录面板。
授权 第三方网站 登录成功后,可到 更新个人资料 禁止密码登录。
6.2 关闭 探针(Agent)远程控制功能
把 disable_command_execute: 改成 true
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 打开 /opt/nezha/agent/config.yml client_secret: DXwVsdfsdfsfdsdf545s4f debug: false disable_auto_update: false disable_command_execute: true disable_force_update: false disable_nat: false disable_send_query: false gpu: false insecure_tls: false ip_report_period: 0 report_delay: 0 self_update_period: 0 server: qq.com:443 skip_connection_count: false skip_procs_count: false temperature: false tls: true use_gitee_to_upgrade: false use_ipv6_country_code: false uuid: sdfsdf-0243480-3444-4343-gdfgdfg4343
重启让配置生效
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ./nezha.sh 哪吒监控管理脚本 --- https://github.com/nezhahq/nezha --- 1. 安装面板端 2. 修改面板配置 3. 重启并更新面板 4. 查看面板日志 5. 卸载管理面板 ————————————————- 6. 更新脚本 ————————————————- 0. 退出脚本 请输入选择 [0-6]: 3
按照上述方法操作,绝对能正常搭建并使用,但可能由于你开启了某些功能导致冲突,以下是排查问题时可能用到的命令
1 测试 gRPC 服务: curl https://qq.com:443/proto.NezhaService/ -H "Content-Type:application/grpc" -X POST -v
7.1 按照教程操作后,探针(Agent)无法连接的解决方法