哪吒监控+cfcdn+ 反代grp端口

哪吒监控+cfcdn+ 反代grp端口

背景:

  • 哪吒监控:感觉VPS线路不稳定,为了打消自己潜意识,希望量化延迟。

  • cfcdn:隐藏真实站点,保障小鸡隐秘安全

  • 反代grpc端口: 反代grpc到支持https(TLS)的端口,这样dashboard与agent的grpc传输会开启TLS安全传输。CF只支持443,这里反代grpc端口到443

具体步骤:

参考文档里面有详细步骤这里只列出一些关键点

安装 Dashboard |官方文档

Nezha Monitoring | 大数据最佳实践

需要准备
  • GitHub oauth2账号

  • cf上两个域名

接入GitHub作为后台管理员账号

使用oauth2登录极大的提高了自建应用的安全性,好评

安装Dashboard

我是用docker compose 安装

9080:dashboard端口

5555:dashboard与agent通信端口

services:
  dashboard:
    image: ghcr.io/naiba/nezha-dashboard
    restart: always
    container_name: nezha
    volumes:
      - ./data:/dashboard/data
      - ./static-custom/static:/dashboard/resource/static/custom:ro
      - ./theme-custom/template:/dashboard/resource/template/theme-custom:ro
      - ./dashboard-custom/template:/dashboard/resource/template/dashboard-custom:ro
    ports:
      - 9080:80
      - 5555:5555

NG配置

反代Dashboard

https能力需NG提供,访问路径是:https://域名 -> NG:443 ->dashboaed 9080

一个是反代/ 一个是反代理ws 一个反代terminal

 location / {
     proxy_pass http://127.0.0.1:9080;
     proxy_set_header Host $http_host;
     proxy_set_header      Upgrade $http_upgrade;
 }
 location ~ ^/(ws|terminal/.+)$  {
     proxy_pass http://127.0.0.1:9080;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "Upgrade";
     proxy_set_header Host $http_host;
 }tp_host;
}
SNI分流
  • Dashboard不支持DOMAIN_PATH,需独占一个域名。使用xxxx.eu.org

  • dashboard与 agent grpc端口需要反代到443,也需要独占一个域名。使用data.xxxx.eu.org

两个域名都监听443,所以ng上配置域名SNI分流

创建 /etc/nginx/conf.d/sni.stream 配置。定义一个map,proxy_pass 带给后端端口

9443:Dashboard

10443:data

map $ssl_preread_server_name $backend_name {
    xxxx.eu.org cf;
    data.xxxx.eu.org cf-cat;
}
upstream cf {
    server 127.0.0.1:9443;
    server [::1]:9443;
}

upstream cf-data {
    server 127.0.0.1:10443;
    server [::1]:10443;
}

server {
    listen 443 reuseport;
    listen [::]:443 reuseport;

    proxy_pass $backend_name;
    ssl_preread on;

    proxy_protocol on;
}

/etc/nginx/nginx.conf 中引入sni分流的stream

stream {
    log_format basic '$remote_addr [$time_local] '
                 '$protocol $status $bytes_sent $bytes_received '
                 '$session_time $ssl_preread_server_name';
    include /etc/nginx/conf.d/*.stream;
}

这样就可以按照SNI域名分流到后端的Dashboard或者grpc了

反代grp端口到443

dashboard与agent grpc使用https更加安全,我因为使用CF,所以反代grpc端口到443,开启TLS安全传输

官方文档很详细:反向代理 gRPC 端口(支持 Cloudflare CDN) | 哪吒监控

grpc默认就安全的?

grpc默认传输如果没有TLS证书,抓包看看,TCP里面是明文的

在这里插入图片描述

看看agent的源码

agent/cmd/agent/main.go at f882ca3498c0766784e31ba454bb09934a118fd3 · nezhahq/agent · GitHub

securityOption = grpc.WithTransportCredentials(insecure.NewCredentials())没有TL证书,默认grpc就是不安全

为什么使用CF的CDN

隐藏源站IP,而且CF CDN支持grpc

哪吒监控Agent按照

安装 Agent | 哪吒监控

简图

在这里插入图片描述

  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值