用戶:Byte6b
21 次編輯加入於
更多語言
更多操作
BandwagonHost安裝哪吒監控(Nezha Monitoring)+ Nginx 反代 + HTTPS 完整教程
一、什麼是哪吒監控(Nezha Monitoring)
哪吒監控(Nezha Monitoring)是一款開源、自託管、輕量級的伺服器與網站實時監控和運維工具。它支持通過 Dashboard 查看系統狀態、資源使用情況,並通過 Agent 採集被監控主機數據。
在本文中,我們將一步一步教你如何從零開始在BandwagonHost(搬瓦工) 機器上使用docker安裝與部署哪吒監控(Nezha Monitoring)系統的 Dashboard 面板,使用nginx反代Dashboard,並配合 Agent 安裝與基本配置內容。
二、部署前的準備
1、伺服器與網絡條件:
- 一台 BandwagonHost(搬瓦工) 或者其他可以訪問公網的伺服器
- 伺服器防火牆和安全策略需允許 Dashboard 使用的端口(默認是 8008)
- 推薦的規格:單核 + 512MB 內存 對於大部分場景足夠。
2、域名設置
三、安裝 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 + Nginx 插件 Certbot 是 Let's Encrypt 官方推薦的證書管理工具
python3-certbot-nginx插件可以 自動修改 Nginx 配置。安裝完成後,檢查版本: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、可以添加更多的機器
將複製的指令在其他機器上執行就可以實現監控其他的機器的狀態(只需要執行命令即可不需要再次安裝面板端)