哪吒监控升级v1

背景

之前给自己的服务器搭建了一个服务器监控的程序,采用的是哪吒监控 具体可以看下面这篇文章

最近发现哪吒监控升级到v1版本了,界面变得更加好看了,需要的端口也从2个减少为1个(不再区分dashboard和agent的端口了),并且可以套上https,共用443端口来接入了

更换v1步骤

由于更换了agent的端口,自己的服务器监控也不用保留监控数据,就打算推翻重来

  1. 删除旧的dashboard和agent,在服务器上执行nezha.sh,选择卸载即可

  2. 安装v1的dashboard,curl -L https://gitee.com/naibahq/scripts/raw/main/install.sh -o nezha.sh && chmod +x nezha.sh && sudo CN=true ./nezha.sh

  3. 配置nginx开启下划线的header转发,在server块内增加underscores_in_headers on; , 这个是必须的,否则会造成agent无法连上服务器

  4. 配置nginx反向代理

    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
    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://127.0.0.1:8008;
    }
    location ^~ / {
    proxy_pass http://127.0.0.1:8008;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_http_version 1.1;
    add_header X-Cache $upstream_cache_status;
    add_header Strict-Transport-Security "max-age=31536000";
    add_header Cache-Control no-cache;
    proxy_ssl_server_name off;
    }
    location ~* ^/api/v1/ws/(server|terminal|file)(.*)$ {
    proxy_pass http://127.0.0.1:8008;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_connection;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_http_version 1.1;
    add_header X-Cache $upstream_cache_status;
    add_header Cache-Control no-cache;
    proxy_ssl_server_name off;
    proxy_ssl_name $proxy_host;
    # 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;

    }
  5. 登录dashboard(默认账号密码都是admin,记得修改)

  6. dashboard/settings 设置agent访问地址

  1. 获取agent安装命令

  1. 在各服务器上使用安装命令安装agent

至此,更换v1版本的哪吒监控就完成了

更换主题

dashboard/settings 中可以设置主题,默认就有社区主题选择,还是比较好看的

设置 OAuth 2.0 绑定

这里以gitee为例

  1. 首先在gitee中的第三方应用中创建应用,配置dashboard的回调,回调地址为 https://域名/api/v1/oauth2/callback

  1. 获取Client ID和Client Secret

  2. 在dashboard中配置OAuth 2.0设置

配置文件是 /opt/nezha/dashboard/data/config.yaml 追加以下内容

1
2
3
4
5
6
7
8
9
10
11
oauth2:
gitee: # replace it with desired name, like `GitHub`
clientid: "第二步中的Client ID"
clientsecret: "第二步中的Client Secret"
endpoint:
authurl: "https://gitee.com/oauth/authorize"
tokenurl: "https://gitee.com/oauth/token"
scopes:
- "user_info"
userinfourl: "https://gitee.com/api/v5/user"
useridpath: "id"
  1. 重启dashboard,如果是docker安装的重启容器即可

  2. 登录dashboard,在用户个人信息Oauth2 bindings中选择绑定,成功授权绑定后会展示绑定的id

  1. 最后在更新个人资料中设置禁止账号密码登录,来增加安全性

如果不是gitee,其余的oauth2.0绑定可以查看以下文档