mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
📝 [WIP] English documents [skip ci]
This commit is contained in:
parent
d5ee1ca4ff
commit
386a0b4a98
416
README.md
416
README.md
@ -1,414 +1,38 @@
|
||||
<div align="center">
|
||||
<br>
|
||||
<img width="250" style="max-width:80%" src="resource/static/brand.svg" title="哪吒监控">
|
||||
<img width="250" style="max-width:80%" src="resource/static/brand.svg" title="哪吒监控 Nezha Monitoring">
|
||||
<br>
|
||||
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
|
||||
<br><br>
|
||||
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.12.30&logo=github&style=for-the-badge"> <img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.8.3-brightgreen?style=for-the-badge&logo=linux">
|
||||
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.12.30&logo=github&style=for-the-badge"> <img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.9.0-brightgreen?style=for-the-badge&logo=linux">
|
||||
<br>
|
||||
<br>
|
||||
<p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,计划任务和在线终端。</p>
|
||||
<p>:trollface: <b>Nezha Monitoring</b> One-stop light monitoring and light operation and maintenance system. Supports system status, HTTP (SSL certificate change, upcoming expiration, expiration), TCP, Ping monitoring and alarm, scheduled tasks and web terminal.</p>
|
||||
</div>
|
||||
|
||||
\>> Telegram Group: [Nezha Monitoring Global (English Only)](https://t.me/nezhamonitoring_global), [哪吒监控(中文群组)](https://t.me/nezhamonitoring)
|
||||
|
||||
\>> QQ 交流群:872069346 **加群要求:已搭建好哪吒监控 & 有 2+ 服务器, 机器人自动审核**
|
||||
|
||||
\>> [我们的用户](https://www.google.com/search?q="powered+by+哪吒监控"&filter=0) (Google)
|
||||
\>> [Use Cases | 我们的用户](https://www.google.com/search?q="powered+by+哪吒监控"&filter=0) (Google)
|
||||
|
||||
| 默认主题 | DayNight [@JackieSung](https://github.com/JackieSung4ev) | hotaru |
|
||||
| Default Theme | DayNight [@JackieSung](https://github.com/JackieSung4ev) | hotaru |
|
||||
| ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------- |
|
||||
| ![默认主题](resource/template/theme-default/screenshot.png) | <img src="resource/template/theme-daynight/screenshot.png" width="3000px"/> | <img src="resource/template/theme-hotaru/screenshot.png" width="1500px" /> |
|
||||
| <div align="center"><b>默认主题魔改 <a href="https://ii.do/43.html">[教程]</a></b></div> | <div align="center"><b>Neko Mdui <a href="https://github.com/MikoyChinese">@MikoyChinese</a></b></div> | |
|
||||
| ![Default Theme](resource/template/theme-default/screenshot.png) | <img src="resource/template/theme-daynight/screenshot.png" width="3000px"/> | <img src="resource/template/theme-hotaru/screenshot.png" width="1500px" /> |
|
||||
| <div align="center"><b>Default modified <a href="https://ii.do/43.html">[Guide]</a></b></div> | <div align="center"><b>Neko Mdui <a href="https://github.com/MikoyChinese">@MikoyChinese</a></b></div> | |
|
||||
| ![默认主题魔改](https://fastly.jsdelivr.net/gh/idarku/img@main/me/1631120192341.webp) | ![Neko Mdui](resource/template/theme-mdui/screenshot.png) | |
|
||||
|
||||
## 安装脚本
|
||||
## User Guide
|
||||
|
||||
**推荐配置:** 安装前准备 _两个域名_,一个可以 **接入 CDN** 作为 _公开访问_,比如 (status.nai.ba);另外一个解析到面板服务器作为 Agent 连接 Dashboard 使用,**不能接入 CDN** 直接暴露面板主机 IP,比如(ip-to-dashboard.nai.ba)。
|
||||
- [中文文档](docs/UserGuide_zh.md)
|
||||
- [English](docs/UserGuide_en.md)
|
||||
|
||||
```shell
|
||||
curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh -o nezha.sh && chmod +x nezha.sh
|
||||
sudo ./nezha.sh
|
||||
```
|
||||
## Special Thanks
|
||||
|
||||
国内镜像加速:
|
||||
|
||||
```shell
|
||||
curl -L https://fastly.jsdelivr.net/gh/naiba/nezha@master/script/install.sh -o nezha.sh && chmod +x nezha.sh
|
||||
CN=true sudo ./nezha.sh
|
||||
```
|
||||
|
||||
_\* 使用 WatchTower 可以自动更新面板,Windows 终端可以使用 nssm 配置自启动(见尾部教程)_
|
||||
|
||||
|
||||
**Windows 一键安装 Agent (请使用 Powershell 管理员权限)**
|
||||
|
||||
```powershell
|
||||
set-ExecutionPolicy RemoteSigned;Invoke-WebRequest https://raw.githubusercontent.com/naiba/nezha/master/script/install.ps1 -OutFile C:\install.ps1;powershell.exe C:\install.ps1 dashboard_host:grpc_port secret
|
||||
```
|
||||
|
||||
|
||||
![image](https://user-images.githubusercontent.com/47450409/165829132-cb1ab16a-7b22-4c5f-9fdf-89d140cf7e40.png)
|
||||
|
||||
*如遇此图请选择 Y*
|
||||
|
||||
### Agent 自定义
|
||||
|
||||
#### 自定义监控的网卡和硬盘分区
|
||||
|
||||
执行 `/opt/nezha/agent/nezha-agent --edit-agent-config` 来选择自定义的网卡和分区,然后重启 Agent 即可
|
||||
|
||||
#### 运行参数
|
||||
|
||||
通过执行 `./nezha-agent --help` 查看支持的参数,如果你使用一键脚本,可以编辑 `/etc/systemd/system/nezha-agent.service`,在 `ExecStart=` 这一行的末尾加上
|
||||
|
||||
- `--report-delay` 系统信息上报的间隔,默认为 1 秒,可以设置为 3 来进一步降低 agent 端系统资源占用(配置区间 1-4)
|
||||
- `--skip-conn` 不监控连接数,机场/连接密集型机器推荐设置,不然比较占 CPU([shirou/gopsutil/issues#220](https://github.com/shirou/gopsutil/issues/220))
|
||||
- `--skip-procs` 不监控进程数,也可以降低 agent 占用
|
||||
- `--disable-auto-update` 禁止 **自动更新** Agent(安全特性)
|
||||
- `--disable-force-update` 禁止 **强制更新** Agent(安全特性)
|
||||
- `--disable-command-execute` 禁止在 Agent 机器上执行定时任务、打开在线终端(安全特性)
|
||||
- `--tls` 启用 SSL/TLS 加密(使用 nginx 反向代理 Agent 的 grpc 连接,并且 nginx 开启 SSL/TLS 时,需要启用该项配置)
|
||||
|
||||
## 功能说明
|
||||
|
||||
<details>
|
||||
<summary>计划任务:备份脚本、服务重启,等定期运维任务。</summary>
|
||||
|
||||
使用此功能可以定期结合 restic、rclone 给服务器备份,或者定期某项重启服务来重置网络连接。
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>报警通知:负载、CPU、内存、硬盘、带宽、流量、月流量、进程数、连接数实时监控。</summary>
|
||||
|
||||
#### 灵活通知方式
|
||||
|
||||
`#NEZHA#` 是面板消息占位符,面板触发通知时会自动替换占位符到实际消息
|
||||
|
||||
Body 内容是`JSON` 格式的:**当请求类型为 FORM 时**,值为 `key:value` 的形式,`value` 里面可放置占位符,通知时会自动替换。**当请求类型为 JSON 时** 只会简进行字符串替换后直接提交到`URL`。
|
||||
|
||||
URL 里面也可放置占位符,请求时会进行简单的字符串替换。
|
||||
|
||||
参考下方的示例,非常灵活。
|
||||
|
||||
1. 添加通知方式
|
||||
|
||||
- server 酱示例
|
||||
|
||||
- 名称:server 酱
|
||||
- URL:<https://sc.ftqq.com/SCUrandomkeys.send?text=#NEZHA>#
|
||||
- 请求方式: GET
|
||||
- 请求类型: 默认
|
||||
- Body: 空
|
||||
|
||||
- wxpusher 示例,需要关注你的应用
|
||||
|
||||
- 名称: wxpusher
|
||||
- URL:<http://wxpusher.zjiecode.com/api/send/message>
|
||||
- 请求方式: POST
|
||||
- 请求类型: JSON
|
||||
- Body: `{"appToken":"你的appToken","topicIds":[],"content":"#NEZHA#","contentType":"1","uids":["你的uid"]}`
|
||||
|
||||
- telegram 示例 [@haitau](https://github.com/haitau) 贡献
|
||||
|
||||
- 名称:telegram 机器人消息通知
|
||||
- URL:<https://api.telegram.org/botXXXXXX/sendMessage?chat_id=YYYYYY&text=#NEZHA>#
|
||||
- 请求方式: GET
|
||||
- 请求类型: 默认
|
||||
- Body: 空
|
||||
- URL 参数获取说明:botXXXXXX 中的 XXXXXX 是在 telegram 中关注官方 @Botfather ,输入/newbot ,创建新的机器人(bot)时,会提供的 token(在提示 Use this token to access the HTTP API:后面一行)这里 'bot' 三个字母不可少。创建 bot 后,需要先在 telegram 中与 BOT 进行对话(随便发个消息),然后才可用 API 发送消息。YYYYYY 是 telegram 用户的数字 ID。与机器人@userinfobot 对话可获得。
|
||||
|
||||
2. 添加一个离线报警
|
||||
|
||||
- 名称:离线通知
|
||||
- 规则:`[{"Type":"offline","Duration":10}]`
|
||||
- 启用:√
|
||||
|
||||
3. 添加一个监控 CPU 持续 10s 超过 50% **且** 内存持续 20s 占用低于 20% 的报警
|
||||
|
||||
- 名称:CPU+内存
|
||||
- 规则:`[{"Type":"cpu","Min":0,"Max":50,"Duration":10},{"Type":"memory","Min":20,"Max":0,"Duration":20}]`
|
||||
- 启用:√
|
||||
|
||||
#### 报警规则说明
|
||||
|
||||
##### 基本规则
|
||||
|
||||
- type
|
||||
- `cpu`、`memory`、`swap`、`disk`
|
||||
- `net_in_speed` 入站网速、`net_out_speed` 出站网速、`net_all_speed` 双向网速、`transfer_in` 入站流量、`transfer_out` 出站流量、`transfer_all` 双向流量
|
||||
- `offline` 离线监控
|
||||
- `load1`、`load5`、`load15` 负载
|
||||
- `process_count` 进程数 _目前取线程数占用资源太多,暂时不支持_
|
||||
- `tcp_conn_count`、`udp_conn_count` 连接数
|
||||
- duration:持续秒数,秒数内采样记录 30% 以上触发阈值才会报警(防数据插针)
|
||||
- min/max
|
||||
- 流量、网速类数值 为字节(1KB=1024B,1MB = 1024\*1024B)
|
||||
- 内存、硬盘、CPU 为占用百分比
|
||||
- 离线监控无需设置
|
||||
- cover `[{"type":"offline","duration":10, "cover":0, "ignore":{"5": true}}]`
|
||||
- `0` 监控所有,通过 `ignore` 忽略特定服务器
|
||||
- `1` 忽略所有,通过 `ignore` 监控特定服务器
|
||||
- ignore: `{"1": true, "2":false}` 特定服务器,搭配 `cover` 使用
|
||||
|
||||
##### 特殊:任意周期流量报警
|
||||
|
||||
可以用作月流量报警
|
||||
|
||||
- type
|
||||
- transfer_in_cycle 周期内的入站流量
|
||||
- transfer_out_cycle 周期内的出站流量
|
||||
- transfer_all_cycle 周期内双向流量和
|
||||
- cycle_start 统计周期开始日期(可以是你机器计费周期的开始日期),RFC3339 时间格式,例如北京时间为`2022-01-11T08:00:00.00+08:00`
|
||||
- cycle_interval 每隔多少个周期单位(例如,周期单位为天,该值为 7,则代表每隔 7 天统计一次)
|
||||
- cycle_unit 统计周期单位,默认`hour`,可选(`hour`, `day`, `week`, `month`, `year`)
|
||||
- min/max、cover、ignore 参考基本规则配置
|
||||
- 示例: ID 为 3 的机器(ignore 里面定义)的每月 15 号计费的出站月流量 1T 报警 `[{"type":"transfer_out_cycle","max":1000000000000,"cycle_start":"2022-01-11T08:00:00.00+08:00","cycle_interval":1,"cycle_unit":"month","cover":1,"ignore":{"3":true}}]`
|
||||
![7QKaUx.md.png](https://s4.ax1x.com/2022/01/13/7QKaUx.md.png)
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>服务监控:HTTP、SSL证书、ping、TCP 端口等。</summary>
|
||||
|
||||
进入 `/monitor` 页面点击新建监控即可,表单下面有相关说明。
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>自定义代码:改LOGO、改色调、加统计代码等。</summary>
|
||||
|
||||
- 默认主题更改进度条颜色示例
|
||||
|
||||
```html
|
||||
<style>
|
||||
.ui.fine.progress> .bar {
|
||||
background-color: pink !important;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
- DayNight 主题更改进度条颜色、修改页脚示例(来自 [@hyt-allen-xu](https://github.com/hyt-allen-xu))
|
||||
|
||||
```html
|
||||
<style>
|
||||
.ui.fine.progress> .progress-bar {
|
||||
background-color: #00a7d0 !important;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
window.onload = function(){
|
||||
var footer=document.querySelector("div.footer-container")
|
||||
footer.innerHTML="©2021 你的名字 & Powered by 你的名字"
|
||||
footer.style.visibility="visible"
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
- 默认主题修改 LOGO、修改页脚示例(来自 [@iLay1678](https://github.com/iLay1678))
|
||||
|
||||
```html
|
||||
<style>
|
||||
.right.menu>a{
|
||||
visibility: hidden;
|
||||
}
|
||||
.footer .is-size-7{
|
||||
visibility: hidden;
|
||||
}
|
||||
.item img{
|
||||
visibility: hidden;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
window.onload = function(){
|
||||
var avatar=document.querySelector(".item img")
|
||||
var footer=document.querySelector("div.is-size-7")
|
||||
footer.innerHTML="Powered by 你的名字"
|
||||
footer.style.visibility="visible"
|
||||
avatar.src="你的方形logo地址"
|
||||
avatar.style.visibility="visible"
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
- hotaru 主题更改背景图片示例
|
||||
|
||||
```html
|
||||
<style>
|
||||
.hotaru-cover {
|
||||
background: url(https://s3.ax1x.com/2020/12/08/DzHv6A.jpg) center;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## 常见问题
|
||||
|
||||
<details>
|
||||
<summary>如何进行数据迁移、备份恢复?</summary>
|
||||
|
||||
1. 先使用一键脚本 `停止面板`
|
||||
2. 打包 `/opt/nezha` 文件夹,到新环境相同位置
|
||||
3. 使用一键脚本 `启动面板`
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Agent 启动/上线 问题自检流程</summary>
|
||||
|
||||
1. 直接执行 `/opt/nezha/agent/nezha-agent -s 面板IP或非CDN域名:面板RPC端口 -p Agent密钥 -d` 查看日志是否是 DNS、网络不佳导致超时(timeout) 问题。
|
||||
2. `nc -v 域名/IP 面板RPC端口` 或者 `telnet 域名/IP 面板RPC端口` 检验是否是网络问题,检查本机与面板服务器出入站防火墙,如果单机无法判断可借助 <https://port.ping.pe/> 提供的端口检查工具进行检测。
|
||||
3. 如果上面步骤检测正常,Agent 正常上线,尝试关闭 SELinux,[如何关闭 SELinux?](https://www.google.com/search?q=%E5%85%B3%E9%97%ADSELINUX)
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>如何使 旧版OpenWRT/LEDE 自启动?</summary>
|
||||
|
||||
参考此项目: <https://github.com/Erope/openwrt_nezha>
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>如何使 新版OpenWRT 自启动?来自 @艾斯德斯</summary>
|
||||
|
||||
首先在 release 下载对应的二进制解压 zip 包后放置到 `/root`,然后 `chmod +x /root/nezha-agent` 赋予执行权限,然后创建 `/etc/init.d/nezha-service`:
|
||||
|
||||
```shell
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
|
||||
start_service() {
|
||||
procd_open_instance
|
||||
procd_set_param command /root/nezha-agent -s 面板网址:接收端口 -p 唯一秘钥 -d
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
killall nezha-agent
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
sleep 2
|
||||
start
|
||||
}
|
||||
```
|
||||
|
||||
赋予执行权限 `chmod +x /etc/init.d/nezha-service` 然后启动服务 `/etc/init.d/nezha-service enable && /etc/init.d/nezha-service start`
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>实时通道断开/在线终端连接失败</summary>
|
||||
|
||||
使用反向代理时需要针对 `/ws`,`/terminal` 路径的 WebSocket 进行特别配置以支持实时更新服务器状态和 **WebSSH**。
|
||||
|
||||
- Nginx(宝塔):在你的 nginx 配置文件中加入以下代码
|
||||
|
||||
```nginx
|
||||
server{
|
||||
|
||||
#原有的一些配置
|
||||
#server_name blablabla...
|
||||
|
||||
location ~ ^/(ws|terminal/.+)$ {
|
||||
proxy_pass http://ip:站点访问端口;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "Upgrade";
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
#其他的 location blablabla...
|
||||
}
|
||||
```
|
||||
|
||||
如果非宝塔,还要在 `server{}` 中添加上这一段
|
||||
|
||||
```nginx
|
||||
location / {
|
||||
proxy_pass http://ip:站点访问端口;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
```
|
||||
|
||||
- CaddyServer v1(v2 无需特别配置)
|
||||
|
||||
```Caddyfile
|
||||
proxy /ws http://ip:8008 {
|
||||
websocket
|
||||
}
|
||||
proxy /terminal/* http://ip:8008 {
|
||||
websocket
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>反向代理 gRPC 端口(支持 Cloudflare CDN)</summary>
|
||||
使用 Nginx 或者 Caddy 反向代理 gRPC
|
||||
|
||||
- Nginx 配置
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name ip-to-dashboard.nai.ba; # 你的 Agent 连接 Dashboard 的域名
|
||||
|
||||
ssl_certificate /data/letsencrypt/fullchain.pem; # 你的域名证书路径
|
||||
ssl_certificate_key /data/letsencrypt/key.pem; # 你的域名私钥路径
|
||||
|
||||
underscores_in_headers on;
|
||||
|
||||
location / {
|
||||
grpc_read_timeout 300s;
|
||||
grpc_send_timeout 300s;
|
||||
grpc_pass grpc://localhost:5555;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- Caddy 配置
|
||||
|
||||
```Caddyfile
|
||||
ip-to-dashboard.nai.ba:443 { # 你的 Agent 连接 Dashboard 的域名
|
||||
reverse_proxy {
|
||||
to localhost:5555
|
||||
transport http {
|
||||
versions h2c 2
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Dashboard 面板端配置
|
||||
|
||||
- 首先登录面板进入管理后台 打开设置页面,在 `未接入CDN的面板服务器域名/IP` 中填入上一步在 Nginx 或 Caddy 中配置的域名 比如 `ip-to-dashboard.nai.ba` ,并保存。
|
||||
- 然后在面板服务器中,打开 /opt/nezha/dashboard/data/config.yaml 文件,将 `proxygrpcport` 修改为 Nginx 或 Caddy 监听的端口,比如上一步设置的 `443` ;因为我们在 Nginx 或 Caddy 中开启了 SSL/TLS,所以需要将 `tls` 设置为 `true` ;修改完成后重启面板。
|
||||
|
||||
Agent 端配置
|
||||
|
||||
- 登录面板管理后台,复制一键安装命令,在对应的服务器上面执行一键安装命令重新安装 agent 端即可。
|
||||
|
||||
开启 Cloudflare CDN(可选)
|
||||
|
||||
根据 Cloudflare gRPC 的要求:gRPC 服务必须侦听 443 端口 且必须支持 TLS 和 HTTP/2。
|
||||
所以如果需要开启 CDN,必须在配置 Nginx 或者 Caddy 反向代理 gRPC 时使用 443 端口,并配置证书(Caddy 会自动申请并配置证书)。
|
||||
|
||||
- 登录 Cloudflare,选择使用的域名。打开 `网络` 选项将 `gRPC` 开关打开,打开 `DNS` 选项,找到 Nginx 或 Caddy 反代 gRPC 配置的域名的解析记录,打开橙色云启用 CDN。
|
||||
|
||||
</details>
|
||||
|
||||
## 社区文章
|
||||
|
||||
- [哪吒探针 - Windows 客户端安装](https://nyko.me/2020/12/13/nezha-windows-client.html)
|
||||
- [哪吒监控,一个便携服务器状态监控面板搭建教程,不想拥有一个自己的探针吗?](https://haoduck.com/644.html)
|
||||
- [哪吒监控:小鸡们的最佳探针](https://www.zhujizixun.com/2843.html) _(已过时)_
|
||||
- [>>更多教程](https://www.google.com/search?q="哪吒监控"+"教程") (Google)
|
||||
|
||||
SEO **云探针、多服务器探针、云监控、多服务器云监控**
|
||||
- [@JackieSung](https://github.com/JackieSung4ev) for our first community-contributed front-end theme.
|
||||
- [@Erope](https://github.com/JackieSung4ev) for contributed a lot to our installation scripts and community building.
|
||||
- [@MikoyChinese](https://github.com/MikoyChinese) for our second community-contributed front-end theme.
|
||||
- [@AkkiaS7](https://github.com/Akkia) and [hhhkkk520](https://github.com/hhhkkk520) for the excellent contribution in the early days of globalization.
|
||||
- [@dysf888](https://gitub.com/dysf888) for the installation script in windows.
|
||||
- [@MartijnLindeman](https://github.com/MartijnLindeman) for his perseverance has taken us to the international market.
|
||||
- and other [contributors](https://github.com/naiba/nezha/graphs/contributors).
|
||||
|
360
docs/UserGuide_en.md
Normal file
360
docs/UserGuide_en.md
Normal file
@ -0,0 +1,360 @@
|
||||
# User Guide
|
||||
|
||||
## 安装脚本
|
||||
|
||||
**推荐配置:** 安装前准备 _两个域名_,一个可以 **接入 CDN** 作为 _公开访问_,比如 (status.nai.ba);另外一个解析到面板服务器作为 Agent 连接 Dashboard 使用,**不能接入 CDN** 直接暴露面板主机 IP,比如(ip-to-dashboard.nai.ba)。
|
||||
|
||||
```shell
|
||||
curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install_en.sh -o nezha.sh && chmod +x nezha.sh
|
||||
sudo ./nezha.sh
|
||||
```
|
||||
|
||||
_\* 使用 WatchTower 可以自动更新面板,Windows 终端可以使用 nssm 配置自启动_
|
||||
|
||||
**Windows 一键安装 Agent (请使用 Powershell 管理员权限)**
|
||||
|
||||
```powershell
|
||||
set-ExecutionPolicy RemoteSigned;Invoke-WebRequest https://raw.githubusercontent.com/naiba/nezha/master/script/install.ps1 -OutFile C:\install.ps1;powershell.exe C:\install.ps1 dashboard_host:grpc_port secret
|
||||
```
|
||||
|
||||
_如遇到确认「执行策略变更」请选择 Y_
|
||||
|
||||
### Agent 自定义
|
||||
|
||||
#### 自定义监控的网卡和硬盘分区
|
||||
|
||||
执行 `/opt/nezha/agent/nezha-agent --edit-agent-config` 来选择自定义的网卡和分区,然后重启 Agent 即可
|
||||
|
||||
#### 运行参数
|
||||
|
||||
通过执行 `./nezha-agent --help` 查看支持的参数,如果你使用一键脚本,可以编辑 `/etc/systemd/system/nezha-agent.service`,在 `ExecStart=` 这一行的末尾加上
|
||||
|
||||
- `--report-delay` 系统信息上报的间隔,默认为 1 秒,可以设置为 3 来进一步降低 agent 端系统资源占用(配置区间 1-4)
|
||||
- `--skip-conn` 不监控连接数,如果 机场/连接密集型机器 CPU占用较高,推荐设置
|
||||
- `--skip-procs` 不监控进程数,也可以降低 agent 占用
|
||||
- `--disable-auto-update` 禁止 **自动更新** Agent(安全特性)
|
||||
- `--disable-force-update` 禁止 **强制更新** Agent(安全特性)
|
||||
- `--disable-command-execute` 禁止在 Agent 机器上执行定时任务、打开在线终端(安全特性)
|
||||
- `--tls` 启用 SSL/TLS 加密(使用 nginx 反向代理 Agent 的 grpc 连接,并且 nginx 开启 SSL/TLS 时,需要启用该项配置)
|
||||
|
||||
## 功能说明
|
||||
|
||||
<details>
|
||||
<summary>计划任务:备份脚本、服务重启,等定期运维任务。</summary>
|
||||
|
||||
使用此功能可以定期结合 restic、rclone 给服务器备份,或者定期某项重启服务来重置网络连接。
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>报警通知:负载、CPU、内存、硬盘、带宽、流量、月流量、进程数、连接数实时监控。</summary>
|
||||
|
||||
#### 灵活通知方式
|
||||
|
||||
`#NEZHA#` 是面板消息占位符,面板触发通知时会自动替换占位符到实际消息
|
||||
|
||||
Body 内容是`JSON` 格式的:**当请求类型为 FORM 时**,值为 `key:value` 的形式,`value` 里面可放置占位符,通知时会自动替换。**当请求类型为 JSON 时** 只会简进行字符串替换后直接提交到`URL`。
|
||||
|
||||
URL 里面也可放置占位符,请求时会进行简单的字符串替换。
|
||||
|
||||
参考下方的示例,非常灵活。
|
||||
|
||||
1. 添加通知方式
|
||||
|
||||
- telegram 示例 [@haitau](https://github.com/haitau) 贡献
|
||||
|
||||
- 名称:telegram 机器人消息通知
|
||||
- URL:<https://api.telegram.org/botXXXXXX/sendMessage?chat_id=YYYYYY&text=#NEZHA>#
|
||||
- 请求方式: GET
|
||||
- 请求类型: 默认
|
||||
- Body: 空
|
||||
- URL 参数获取说明:botXXXXXX 中的 XXXXXX 是在 telegram 中关注官方 @Botfather ,输入/newbot ,创建新的机器人(bot)时,会提供的 token(在提示 Use this token to access the HTTP API:后面一行)这里 'bot' 三个字母不可少。创建 bot 后,需要先在 telegram 中与 BOT 进行对话(随便发个消息),然后才可用 API 发送消息。YYYYYY 是 telegram 用户的数字 ID。与机器人@userinfobot 对话可获得。
|
||||
|
||||
2. 添加一个离线报警
|
||||
|
||||
- 名称:离线通知
|
||||
- 规则:`[{"Type":"offline","Duration":10}]`
|
||||
- 启用:√
|
||||
|
||||
3. 添加一个监控 CPU 持续 10s 超过 50% **且** 内存持续 20s 占用低于 20% 的报警
|
||||
|
||||
- 名称:CPU+内存
|
||||
- 规则:`[{"Type":"cpu","Min":0,"Max":50,"Duration":10},{"Type":"memory","Min":20,"Max":0,"Duration":20}]`
|
||||
- 启用:√
|
||||
|
||||
#### 报警规则说明
|
||||
|
||||
##### 基本规则
|
||||
|
||||
- type
|
||||
- `cpu`、`memory`、`swap`、`disk`
|
||||
- `net_in_speed` 入站网速、`net_out_speed` 出站网速、`net_all_speed` 双向网速、`transfer_in` 入站流量、`transfer_out` 出站流量、`transfer_all` 双向流量
|
||||
- `offline` 离线监控
|
||||
- `load1`、`load5`、`load15` 负载
|
||||
- `process_count` 进程数 _目前取线程数占用资源太多,暂时不支持_
|
||||
- `tcp_conn_count`、`udp_conn_count` 连接数
|
||||
- duration:持续秒数,秒数内采样记录 30% 以上触发阈值才会报警(防数据插针)
|
||||
- min/max
|
||||
- 流量、网速类数值 为字节(1KB=1024B,1MB = 1024\*1024B)
|
||||
- 内存、硬盘、CPU 为占用百分比
|
||||
- 离线监控无需设置
|
||||
- cover `[{"type":"offline","duration":10, "cover":0, "ignore":{"5": true}}]`
|
||||
- `0` 监控所有,通过 `ignore` 忽略特定服务器
|
||||
- `1` 忽略所有,通过 `ignore` 监控特定服务器
|
||||
- ignore: `{"1": true, "2":false}` 特定服务器,搭配 `cover` 使用
|
||||
|
||||
##### 特殊:任意周期流量报警
|
||||
|
||||
可以用作月流量报警
|
||||
|
||||
- type
|
||||
- transfer_in_cycle 周期内的入站流量
|
||||
- transfer_out_cycle 周期内的出站流量
|
||||
- transfer_all_cycle 周期内双向流量和
|
||||
- cycle_start 统计周期开始日期(可以是你机器计费周期的开始日期),RFC3339 时间格式,例如北京时间为`2022-01-11T08:00:00.00+08:00`
|
||||
- cycle_interval 每隔多少个周期单位(例如,周期单位为天,该值为 7,则代表每隔 7 天统计一次)
|
||||
- cycle_unit 统计周期单位,默认`hour`,可选(`hour`, `day`, `week`, `month`, `year`)
|
||||
- min/max、cover、ignore 参考基本规则配置
|
||||
- 示例: ID 为 3 的机器(ignore 里面定义)的每月 15 号计费的出站月流量 1T 报警 `[{"type":"transfer_out_cycle","max":1000000000000,"cycle_start":"2022-01-11T08:00:00.00+08:00","cycle_interval":1,"cycle_unit":"month","cover":1,"ignore":{"3":true}}]`
|
||||
![7QKaUx.md.png](https://s4.ax1x.com/2022/01/13/7QKaUx.md.png)
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>服务监控:HTTP、SSL证书、ping、TCP 端口等。</summary>
|
||||
|
||||
进入 `/monitor` 页面点击新建监控即可,表单下面有相关说明。
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>自定义代码:改LOGO、改色调、加统计代码等。</summary>
|
||||
|
||||
**Effective only on the visitor's home page.**
|
||||
|
||||
- 默认主题更改进度条颜色示例
|
||||
|
||||
```html
|
||||
<style>
|
||||
.ui.fine.progress> .bar {
|
||||
background-color: pink !important;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
- DayNight 主题更改进度条颜色、修改页脚示例(来自 [@hyt-allen-xu](https://github.com/hyt-allen-xu))
|
||||
|
||||
```html
|
||||
<style>
|
||||
.ui.fine.progress> .progress-bar {
|
||||
background-color: #00a7d0 !important;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
window.onload = function(){
|
||||
var footer=document.querySelector("div.footer-container")
|
||||
footer.innerHTML="©2021 你的名字 & Powered by 你的名字"
|
||||
footer.style.visibility="visible"
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
- 默认主题修改 LOGO、修改页脚示例(来自 [@iLay1678](https://github.com/iLay1678))
|
||||
|
||||
```html
|
||||
<style>
|
||||
.right.menu>a{
|
||||
visibility: hidden;
|
||||
}
|
||||
.footer .is-size-7{
|
||||
visibility: hidden;
|
||||
}
|
||||
.item img{
|
||||
visibility: hidden;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
window.onload = function(){
|
||||
var avatar=document.querySelector(".item img")
|
||||
var footer=document.querySelector("div.is-size-7")
|
||||
footer.innerHTML="Powered by 你的名字"
|
||||
footer.style.visibility="visible"
|
||||
avatar.src="你的方形logo地址"
|
||||
avatar.style.visibility="visible"
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
- hotaru 主题更改背景图片示例
|
||||
|
||||
```html
|
||||
<style>
|
||||
.hotaru-cover {
|
||||
background: url(https://s3.ax1x.com/2020/12/08/DzHv6A.jpg) center;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## 常见问题
|
||||
|
||||
<details>
|
||||
<summary>如何进行数据迁移、备份恢复?</summary>
|
||||
|
||||
1. 先使用一键脚本 `停止面板`
|
||||
2. 打包 `/opt/nezha` 文件夹,到新环境相同位置
|
||||
3. 使用一键脚本 `启动面板`
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Agent 启动/上线 问题自检流程</summary>
|
||||
|
||||
1. 直接执行 `/opt/nezha/agent/nezha-agent -s 面板IP或非CDN域名:面板RPC端口 -p Agent密钥 -d` 查看日志是否是 DNS、网络不佳导致超时(timeout) 问题。
|
||||
2. `nc -v 域名/IP 面板RPC端口` 或者 `telnet 域名/IP 面板RPC端口` 检验是否是网络问题,检查本机与面板服务器出入站防火墙,如果单机无法判断可借助 <https://port.ping.pe/> 提供的端口检查工具进行检测。
|
||||
3. 如果上面步骤检测正常,Agent 正常上线,尝试关闭 SELinux,[如何关闭 SELinux?](https://www.google.com/search?q=%E5%85%B3%E9%97%ADSELINUX)
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>如何使 旧版OpenWRT/LEDE 自启动?</summary>
|
||||
|
||||
参考此项目: <https://github.com/Erope/openwrt_nezha>
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>如何使 新版OpenWRT 自启动?来自 @艾斯德斯</summary>
|
||||
|
||||
首先在 release 下载对应的二进制解压 zip 包后放置到 `/root`,然后 `chmod +x /root/nezha-agent` 赋予执行权限,然后创建 `/etc/init.d/nezha-service`:
|
||||
|
||||
```shell
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
|
||||
start_service() {
|
||||
procd_open_instance
|
||||
procd_set_param command /root/nezha-agent -s 面板网址:接收端口 -p 唯一秘钥 -d
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
killall nezha-agent
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
sleep 2
|
||||
start
|
||||
}
|
||||
```
|
||||
|
||||
赋予执行权限 `chmod +x /etc/init.d/nezha-service` 然后启动服务 `/etc/init.d/nezha-service enable && /etc/init.d/nezha-service start`
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>实时通道断开/在线终端连接失败</summary>
|
||||
|
||||
使用反向代理时需要针对 `/ws`,`/terminal` 路径的 WebSocket 进行特别配置以支持实时更新服务器状态和 **WebSSH**。
|
||||
|
||||
- Nginx(宝塔):在你的 nginx 配置文件中加入以下代码
|
||||
|
||||
```nginx
|
||||
server{
|
||||
|
||||
#原有的一些配置
|
||||
#server_name blablabla...
|
||||
|
||||
location ~ ^/(ws|terminal/.+)$ {
|
||||
proxy_pass http://ip:站点访问端口;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "Upgrade";
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
#其他的 location blablabla...
|
||||
}
|
||||
```
|
||||
|
||||
如果非宝塔,还要在 `server{}` 中添加上这一段
|
||||
|
||||
```nginx
|
||||
location / {
|
||||
proxy_pass http://ip:站点访问端口;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
```
|
||||
|
||||
- CaddyServer v1(v2 无需特别配置)
|
||||
|
||||
```Caddyfile
|
||||
proxy /ws http://ip:8008 {
|
||||
websocket
|
||||
}
|
||||
proxy /terminal/* http://ip:8008 {
|
||||
websocket
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>反向代理 gRPC 端口(支持 Cloudflare CDN)</summary>
|
||||
使用 Nginx 或者 Caddy 反向代理 gRPC
|
||||
|
||||
- Nginx 配置
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name ip-to-dashboard.nai.ba; # 你的 Agent 连接 Dashboard 的域名
|
||||
|
||||
ssl_certificate /data/letsencrypt/fullchain.pem; # 你的域名证书路径
|
||||
ssl_certificate_key /data/letsencrypt/key.pem; # 你的域名私钥路径
|
||||
|
||||
underscores_in_headers on;
|
||||
|
||||
location / {
|
||||
grpc_read_timeout 300s;
|
||||
grpc_send_timeout 300s;
|
||||
grpc_pass grpc://localhost:5555;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- Caddy 配置
|
||||
|
||||
```Caddyfile
|
||||
ip-to-dashboard.nai.ba:443 { # 你的 Agent 连接 Dashboard 的域名
|
||||
reverse_proxy {
|
||||
to localhost:5555
|
||||
transport http {
|
||||
versions h2c 2
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Dashboard 面板端配置
|
||||
|
||||
- 首先登录面板进入管理后台 打开设置页面,在 `未接入CDN的面板服务器域名/IP` 中填入上一步在 Nginx 或 Caddy 中配置的域名 比如 `ip-to-dashboard.nai.ba` ,并保存。
|
||||
- 然后在面板服务器中,打开 /opt/nezha/dashboard/data/config.yaml 文件,将 `proxygrpcport` 修改为 Nginx 或 Caddy 监听的端口,比如上一步设置的 `443` ;因为我们在 Nginx 或 Caddy 中开启了 SSL/TLS,所以需要将 `tls` 设置为 `true` ;修改完成后重启面板。
|
||||
|
||||
Agent 端配置
|
||||
|
||||
- 登录面板管理后台,复制一键安装命令,在对应的服务器上面执行一键安装命令重新安装 agent 端即可。
|
||||
|
||||
开启 Cloudflare CDN(可选)
|
||||
|
||||
根据 Cloudflare gRPC 的要求:gRPC 服务必须侦听 443 端口 且必须支持 TLS 和 HTTP/2。
|
||||
所以如果需要开启 CDN,必须在配置 Nginx 或者 Caddy 反向代理 gRPC 时使用 443 端口,并配置证书(Caddy 会自动申请并配置证书)。
|
||||
|
||||
- 登录 Cloudflare,选择使用的域名。打开 `网络` 选项将 `gRPC` 开关打开,打开 `DNS` 选项,找到 Nginx 或 Caddy 反代 gRPC 配置的域名的解析记录,打开橙色云启用 CDN。
|
||||
|
||||
</details>
|
400
docs/UserGuide_zh.md
Normal file
400
docs/UserGuide_zh.md
Normal file
@ -0,0 +1,400 @@
|
||||
<div align="center">
|
||||
<br>
|
||||
<img width="250" style="max-width:80%" src="../resource/static/brand.svg" title="哪吒监控 Nezha Monitoring">
|
||||
<br>
|
||||
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
|
||||
<br>
|
||||
<br>
|
||||
<p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,计划任务和在线终端。</p>
|
||||
</div>
|
||||
|
||||
## 安装脚本
|
||||
|
||||
**推荐配置:** 安装前准备 _两个域名_,一个可以 **接入 CDN** 作为 _公开访问_,比如 (status.nai.ba);另外一个解析到面板服务器作为 Agent 连接 Dashboard 使用,**不能接入 CDN** 直接暴露面板主机 IP,比如(ip-to-dashboard.nai.ba)。
|
||||
|
||||
```shell
|
||||
curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh -o nezha.sh && chmod +x nezha.sh
|
||||
sudo ./nezha.sh
|
||||
```
|
||||
|
||||
国内镜像加速:
|
||||
|
||||
```shell
|
||||
curl -L https://fastly.jsdelivr.net/gh/naiba/nezha@master/script/install.sh -o nezha.sh && chmod +x nezha.sh
|
||||
CN=true sudo ./nezha.sh
|
||||
```
|
||||
|
||||
_\* 使用 WatchTower 可以自动更新面板,Windows 终端可以使用 nssm 配置自启动_
|
||||
|
||||
**Windows 一键安装 Agent (请使用 Powershell 管理员权限)**
|
||||
|
||||
```powershell
|
||||
set-ExecutionPolicy RemoteSigned;Invoke-WebRequest https://raw.githubusercontent.com/naiba/nezha/master/script/install.ps1 -OutFile C:\install.ps1;powershell.exe C:\install.ps1 dashboard_host:grpc_port secret
|
||||
```
|
||||
|
||||
_如遇到确认「执行策略变更」请选择 Y_
|
||||
|
||||
### Agent 自定义
|
||||
|
||||
#### 自定义监控的网卡和硬盘分区
|
||||
|
||||
执行 `/opt/nezha/agent/nezha-agent --edit-agent-config` 来选择自定义的网卡和分区,然后重启 Agent 即可
|
||||
|
||||
#### 运行参数
|
||||
|
||||
通过执行 `./nezha-agent --help` 查看支持的参数,如果你使用一键脚本,可以编辑 `/etc/systemd/system/nezha-agent.service`,在 `ExecStart=` 这一行的末尾加上
|
||||
|
||||
- `--report-delay` 系统信息上报的间隔,默认为 1 秒,可以设置为 3 来进一步降低 agent 端系统资源占用(配置区间 1-4)
|
||||
- `--skip-conn` 不监控连接数,如果 机场/连接密集型机器 CPU占用较高,推荐设置
|
||||
- `--skip-procs` 不监控进程数,也可以降低 agent 占用
|
||||
- `--disable-auto-update` 禁止 **自动更新** Agent(安全特性)
|
||||
- `--disable-force-update` 禁止 **强制更新** Agent(安全特性)
|
||||
- `--disable-command-execute` 禁止在 Agent 机器上执行定时任务、打开在线终端(安全特性)
|
||||
- `--tls` 启用 SSL/TLS 加密(使用 nginx 反向代理 Agent 的 grpc 连接,并且 nginx 开启 SSL/TLS 时,需要启用该项配置)
|
||||
|
||||
## 功能说明
|
||||
|
||||
<details>
|
||||
<summary>计划任务:备份脚本、服务重启,等定期运维任务。</summary>
|
||||
|
||||
使用此功能可以定期结合 restic、rclone 给服务器备份,或者定期某项重启服务来重置网络连接。
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>报警通知:负载、CPU、内存、硬盘、带宽、流量、月流量、进程数、连接数实时监控。</summary>
|
||||
|
||||
#### 灵活通知方式
|
||||
|
||||
`#NEZHA#` 是面板消息占位符,面板触发通知时会自动替换占位符到实际消息
|
||||
|
||||
Body 内容是`JSON` 格式的:**当请求类型为 FORM 时**,值为 `key:value` 的形式,`value` 里面可放置占位符,通知时会自动替换。**当请求类型为 JSON 时** 只会简进行字符串替换后直接提交到`URL`。
|
||||
|
||||
URL 里面也可放置占位符,请求时会进行简单的字符串替换。
|
||||
|
||||
参考下方的示例,非常灵活。
|
||||
|
||||
1. 添加通知方式
|
||||
|
||||
- server 酱示例
|
||||
|
||||
- 名称:server 酱
|
||||
- URL:<https://sc.ftqq.com/SCUrandomkeys.send?text=#NEZHA>#
|
||||
- 请求方式: GET
|
||||
- 请求类型: 默认
|
||||
- Body: 空
|
||||
|
||||
- wxpusher 示例,需要关注你的应用
|
||||
|
||||
- 名称: wxpusher
|
||||
- URL:<http://wxpusher.zjiecode.com/api/send/message>
|
||||
- 请求方式: POST
|
||||
- 请求类型: JSON
|
||||
- Body: `{"appToken":"你的appToken","topicIds":[],"content":"#NEZHA#","contentType":"1","uids":["你的uid"]}`
|
||||
|
||||
- telegram 示例 [@haitau](https://github.com/haitau) 贡献
|
||||
|
||||
- 名称:telegram 机器人消息通知
|
||||
- URL:<https://api.telegram.org/botXXXXXX/sendMessage?chat_id=YYYYYY&text=#NEZHA>#
|
||||
- 请求方式: GET
|
||||
- 请求类型: 默认
|
||||
- Body: 空
|
||||
- URL 参数获取说明:botXXXXXX 中的 XXXXXX 是在 telegram 中关注官方 @Botfather ,输入/newbot ,创建新的机器人(bot)时,会提供的 token(在提示 Use this token to access the HTTP API:后面一行)这里 'bot' 三个字母不可少。创建 bot 后,需要先在 telegram 中与 BOT 进行对话(随便发个消息),然后才可用 API 发送消息。YYYYYY 是 telegram 用户的数字 ID。与机器人@userinfobot 对话可获得。
|
||||
|
||||
2. 添加一个离线报警
|
||||
|
||||
- 名称:离线通知
|
||||
- 规则:`[{"Type":"offline","Duration":10}]`
|
||||
- 启用:√
|
||||
|
||||
3. 添加一个监控 CPU 持续 10s 超过 50% **且** 内存持续 20s 占用低于 20% 的报警
|
||||
|
||||
- 名称:CPU+内存
|
||||
- 规则:`[{"Type":"cpu","Min":0,"Max":50,"Duration":10},{"Type":"memory","Min":20,"Max":0,"Duration":20}]`
|
||||
- 启用:√
|
||||
|
||||
#### 报警规则说明
|
||||
|
||||
##### 基本规则
|
||||
|
||||
- type
|
||||
- `cpu`、`memory`、`swap`、`disk`
|
||||
- `net_in_speed` 入站网速、`net_out_speed` 出站网速、`net_all_speed` 双向网速、`transfer_in` 入站流量、`transfer_out` 出站流量、`transfer_all` 双向流量
|
||||
- `offline` 离线监控
|
||||
- `load1`、`load5`、`load15` 负载
|
||||
- `process_count` 进程数 _目前取线程数占用资源太多,暂时不支持_
|
||||
- `tcp_conn_count`、`udp_conn_count` 连接数
|
||||
- duration:持续秒数,秒数内采样记录 30% 以上触发阈值才会报警(防数据插针)
|
||||
- min/max
|
||||
- 流量、网速类数值 为字节(1KB=1024B,1MB = 1024\*1024B)
|
||||
- 内存、硬盘、CPU 为占用百分比
|
||||
- 离线监控无需设置
|
||||
- cover `[{"type":"offline","duration":10, "cover":0, "ignore":{"5": true}}]`
|
||||
- `0` 监控所有,通过 `ignore` 忽略特定服务器
|
||||
- `1` 忽略所有,通过 `ignore` 监控特定服务器
|
||||
- ignore: `{"1": true, "2":false}` 特定服务器,搭配 `cover` 使用
|
||||
|
||||
##### 特殊:任意周期流量报警
|
||||
|
||||
可以用作月流量报警
|
||||
|
||||
- type
|
||||
- transfer_in_cycle 周期内的入站流量
|
||||
- transfer_out_cycle 周期内的出站流量
|
||||
- transfer_all_cycle 周期内双向流量和
|
||||
- cycle_start 统计周期开始日期(可以是你机器计费周期的开始日期),RFC3339 时间格式,例如北京时间为`2022-01-11T08:00:00.00+08:00`
|
||||
- cycle_interval 每隔多少个周期单位(例如,周期单位为天,该值为 7,则代表每隔 7 天统计一次)
|
||||
- cycle_unit 统计周期单位,默认`hour`,可选(`hour`, `day`, `week`, `month`, `year`)
|
||||
- min/max、cover、ignore 参考基本规则配置
|
||||
- 示例: ID 为 3 的机器(ignore 里面定义)的每月 15 号计费的出站月流量 1T 报警 `[{"type":"transfer_out_cycle","max":1000000000000,"cycle_start":"2022-01-11T08:00:00.00+08:00","cycle_interval":1,"cycle_unit":"month","cover":1,"ignore":{"3":true}}]`
|
||||
![7QKaUx.md.png](https://s4.ax1x.com/2022/01/13/7QKaUx.md.png)
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>服务监控:HTTP、SSL证书、ping、TCP 端口等。</summary>
|
||||
|
||||
进入 `/monitor` 页面点击新建监控即可,表单下面有相关说明。
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>自定义代码:改LOGO、改色调、加统计代码等。</summary>
|
||||
|
||||
**仅在游客首页生效。**
|
||||
|
||||
- 默认主题更改进度条颜色示例
|
||||
|
||||
```html
|
||||
<style>
|
||||
.ui.fine.progress> .bar {
|
||||
background-color: pink !important;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
- DayNight 主题更改进度条颜色、修改页脚示例(来自 [@hyt-allen-xu](https://github.com/hyt-allen-xu))
|
||||
|
||||
```html
|
||||
<style>
|
||||
.ui.fine.progress> .progress-bar {
|
||||
background-color: #00a7d0 !important;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
window.onload = function(){
|
||||
var footer=document.querySelector("div.footer-container")
|
||||
footer.innerHTML="©2021 你的名字 & Powered by 你的名字"
|
||||
footer.style.visibility="visible"
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
- 默认主题修改 LOGO、修改页脚示例(来自 [@iLay1678](https://github.com/iLay1678))
|
||||
|
||||
```html
|
||||
<style>
|
||||
.right.menu>a{
|
||||
visibility: hidden;
|
||||
}
|
||||
.footer .is-size-7{
|
||||
visibility: hidden;
|
||||
}
|
||||
.item img{
|
||||
visibility: hidden;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
window.onload = function(){
|
||||
var avatar=document.querySelector(".item img")
|
||||
var footer=document.querySelector("div.is-size-7")
|
||||
footer.innerHTML="Powered by 你的名字"
|
||||
footer.style.visibility="visible"
|
||||
avatar.src="你的方形logo地址"
|
||||
avatar.style.visibility="visible"
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
- hotaru 主题更改背景图片示例
|
||||
|
||||
```html
|
||||
<style>
|
||||
.hotaru-cover {
|
||||
background: url(https://s3.ax1x.com/2020/12/08/DzHv6A.jpg) center;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## 常见问题
|
||||
|
||||
<details>
|
||||
<summary>如何进行数据迁移、备份恢复?</summary>
|
||||
|
||||
1. 先使用一键脚本 `停止面板`
|
||||
2. 打包 `/opt/nezha` 文件夹,到新环境相同位置
|
||||
3. 使用一键脚本 `启动面板`
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Agent 启动/上线 问题自检流程</summary>
|
||||
|
||||
1. 直接执行 `/opt/nezha/agent/nezha-agent -s 面板IP或非CDN域名:面板RPC端口 -p Agent密钥 -d` 查看日志是否是 DNS、网络不佳导致超时(timeout) 问题。
|
||||
2. `nc -v 域名/IP 面板RPC端口` 或者 `telnet 域名/IP 面板RPC端口` 检验是否是网络问题,检查本机与面板服务器出入站防火墙,如果单机无法判断可借助 <https://port.ping.pe/> 提供的端口检查工具进行检测。
|
||||
3. 如果上面步骤检测正常,Agent 正常上线,尝试关闭 SELinux,[如何关闭 SELinux?](https://www.google.com/search?q=%E5%85%B3%E9%97%ADSELINUX)
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>如何使 旧版OpenWRT/LEDE 自启动?</summary>
|
||||
|
||||
参考此项目: <https://github.com/Erope/openwrt_nezha>
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>如何使 新版OpenWRT 自启动?来自 @艾斯德斯</summary>
|
||||
|
||||
首先在 release 下载对应的二进制解压 zip 包后放置到 `/root`,然后 `chmod +x /root/nezha-agent` 赋予执行权限,然后创建 `/etc/init.d/nezha-service`:
|
||||
|
||||
```shell
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
|
||||
start_service() {
|
||||
procd_open_instance
|
||||
procd_set_param command /root/nezha-agent -s 面板网址:接收端口 -p 唯一秘钥 -d
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
killall nezha-agent
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
sleep 2
|
||||
start
|
||||
}
|
||||
```
|
||||
|
||||
赋予执行权限 `chmod +x /etc/init.d/nezha-service` 然后启动服务 `/etc/init.d/nezha-service enable && /etc/init.d/nezha-service start`
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>实时通道断开/在线终端连接失败</summary>
|
||||
|
||||
使用反向代理时需要针对 `/ws`,`/terminal` 路径的 WebSocket 进行特别配置以支持实时更新服务器状态和 **WebSSH**。
|
||||
|
||||
- Nginx(宝塔):在你的 nginx 配置文件中加入以下代码
|
||||
|
||||
```nginx
|
||||
server{
|
||||
|
||||
#原有的一些配置
|
||||
#server_name blablabla...
|
||||
|
||||
location ~ ^/(ws|terminal/.+)$ {
|
||||
proxy_pass http://ip:站点访问端口;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "Upgrade";
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
#其他的 location blablabla...
|
||||
}
|
||||
```
|
||||
|
||||
如果非宝塔,还要在 `server{}` 中添加上这一段
|
||||
|
||||
```nginx
|
||||
location / {
|
||||
proxy_pass http://ip:站点访问端口;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
```
|
||||
|
||||
- CaddyServer v1(v2 无需特别配置)
|
||||
|
||||
```Caddyfile
|
||||
proxy /ws http://ip:8008 {
|
||||
websocket
|
||||
}
|
||||
proxy /terminal/* http://ip:8008 {
|
||||
websocket
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>反向代理 gRPC 端口(支持 Cloudflare CDN)</summary>
|
||||
使用 Nginx 或者 Caddy 反向代理 gRPC
|
||||
|
||||
- Nginx 配置
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name ip-to-dashboard.nai.ba; # 你的 Agent 连接 Dashboard 的域名
|
||||
|
||||
ssl_certificate /data/letsencrypt/fullchain.pem; # 你的域名证书路径
|
||||
ssl_certificate_key /data/letsencrypt/key.pem; # 你的域名私钥路径
|
||||
|
||||
underscores_in_headers on;
|
||||
|
||||
location / {
|
||||
grpc_read_timeout 300s;
|
||||
grpc_send_timeout 300s;
|
||||
grpc_pass grpc://localhost:5555;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- Caddy 配置
|
||||
|
||||
```Caddyfile
|
||||
ip-to-dashboard.nai.ba:443 { # 你的 Agent 连接 Dashboard 的域名
|
||||
reverse_proxy {
|
||||
to localhost:5555
|
||||
transport http {
|
||||
versions h2c 2
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Dashboard 面板端配置
|
||||
|
||||
- 首先登录面板进入管理后台 打开设置页面,在 `未接入CDN的面板服务器域名/IP` 中填入上一步在 Nginx 或 Caddy 中配置的域名 比如 `ip-to-dashboard.nai.ba` ,并保存。
|
||||
- 然后在面板服务器中,打开 /opt/nezha/dashboard/data/config.yaml 文件,将 `proxygrpcport` 修改为 Nginx 或 Caddy 监听的端口,比如上一步设置的 `443` ;因为我们在 Nginx 或 Caddy 中开启了 SSL/TLS,所以需要将 `tls` 设置为 `true` ;修改完成后重启面板。
|
||||
|
||||
Agent 端配置
|
||||
|
||||
- 登录面板管理后台,复制一键安装命令,在对应的服务器上面执行一键安装命令重新安装 agent 端即可。
|
||||
|
||||
开启 Cloudflare CDN(可选)
|
||||
|
||||
根据 Cloudflare gRPC 的要求:gRPC 服务必须侦听 443 端口 且必须支持 TLS 和 HTTP/2。
|
||||
所以如果需要开启 CDN,必须在配置 Nginx 或者 Caddy 反向代理 gRPC 时使用 443 端口,并配置证书(Caddy 会自动申请并配置证书)。
|
||||
|
||||
- 登录 Cloudflare,选择使用的域名。打开 `网络` 选项将 `gRPC` 开关打开,打开 `DNS` 选项,找到 Nginx 或 Caddy 反代 gRPC 配置的域名的解析记录,打开橙色云启用 CDN。
|
||||
|
||||
</details>
|
||||
|
||||
## 社区文章
|
||||
|
||||
- [哪吒探针 - Windows 客户端安装](https://nyko.me/2020/12/13/nezha-windows-client.html)
|
||||
- [哪吒监控,一个便携服务器状态监控面板搭建教程,不想拥有一个自己的探针吗?](https://haoduck.com/644.html)
|
||||
- [哪吒监控:小鸡们的最佳探针](https://www.zhujizixun.com/2843.html) _(已过时)_
|
||||
- [>>更多教程](https://www.google.com/search?q="哪吒监控"+"教程") (Google)
|
||||
|
||||
SEO **云探针 多服务器探针 云监控 多服务器云监控**
|
598
script/install_en.sh
Executable file
598
script/install_en.sh
Executable file
@ -0,0 +1,598 @@
|
||||
#!/bin/bash
|
||||
|
||||
#========================================================
|
||||
# System Required: CentOS 7+ / Debian 8+ / Ubuntu 16+ /
|
||||
# Arch 未测试
|
||||
# Description: 哪吒监控安装脚本
|
||||
# Github: https://github.com/naiba/nezha
|
||||
#========================================================
|
||||
|
||||
NZ_BASE_PATH="/opt/nezha"
|
||||
NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard"
|
||||
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
|
||||
NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service"
|
||||
NZ_VERSION="v0.9.0"
|
||||
|
||||
red='\033[0;31m'
|
||||
green='\033[0;32m'
|
||||
yellow='\033[0;33m'
|
||||
plain='\033[0m'
|
||||
export PATH=$PATH:/usr/local/bin
|
||||
|
||||
os_arch=""
|
||||
|
||||
pre_check() {
|
||||
command -v systemctl >/dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "不支持此系统:未找到 systemctl 命令"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# check root
|
||||
[[ $EUID -ne 0 ]] && echo -e "${red}错误: ${plain} 必须使用root用户运行此脚本!\n" && exit 1
|
||||
|
||||
## os_arch
|
||||
if [[ $(uname -m | grep 'x86_64') != "" ]]; then
|
||||
os_arch="amd64"
|
||||
elif [[ $(uname -m | grep 'i386\|i686') != "" ]]; then
|
||||
os_arch="386"
|
||||
elif [[ $(uname -m | grep 'aarch64\|armv8b\|armv8l') != "" ]]; then
|
||||
os_arch="arm64"
|
||||
elif [[ $(uname -m | grep 'arm') != "" ]]; then
|
||||
os_arch="arm"
|
||||
elif [[ $(uname -m | grep 's390x') != "" ]]; then
|
||||
os_arch="s390x"
|
||||
elif [[ $(uname -m | grep 'riscv64') != "" ]]; then
|
||||
os_arch="riscv64"
|
||||
fi
|
||||
|
||||
## China_IP
|
||||
if [[ -z "${CN}" ]]; then
|
||||
if [[ $(curl -m 10 -s https://ipapi.co/json | grep 'China') != "" ]]; then
|
||||
echo "根据ipapi.co提供的信息,当前IP可能在中国"
|
||||
read -e -r -p "是否选用中国镜像完成安装? [Y/n] " input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
echo "使用中国镜像"
|
||||
CN=true
|
||||
;;
|
||||
|
||||
[nN][oO] | [nN])
|
||||
echo "不使用中国镜像"
|
||||
;;
|
||||
*)
|
||||
echo "使用中国镜像"
|
||||
CN=true
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "${CN}" ]]; then
|
||||
GITHUB_RAW_URL="raw.githubusercontent.com/naiba/nezha/master"
|
||||
GITHUB_URL="github.com"
|
||||
Get_Docker_URL="get.docker.com"
|
||||
Get_Docker_Argu=" "
|
||||
Docker_IMG="ghcr.io\/naiba\/nezha-dashboard"
|
||||
else
|
||||
GITHUB_RAW_URL="fastly.jsdelivr.net/gh/naiba/nezha@master"
|
||||
GITHUB_URL="dn-dao-github-mirror.daocloud.io"
|
||||
Get_Docker_URL="get.daocloud.io/docker"
|
||||
Get_Docker_Argu=" -s docker --mirror Aliyun"
|
||||
Docker_IMG="registry.cn-shanghai.aliyuncs.com\/naibahq\/nezha-dashboard"
|
||||
fi
|
||||
}
|
||||
|
||||
confirm() {
|
||||
if [[ $# > 1 ]]; then
|
||||
echo && read -e -p "$1 [默认$2]: " temp
|
||||
if [[ x"${temp}" == x"" ]]; then
|
||||
temp=$2
|
||||
fi
|
||||
else
|
||||
read -e -p "$1 [y/n]: " temp
|
||||
fi
|
||||
if [[ x"${temp}" == x"y" || x"${temp}" == x"Y" ]]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
update_script() {
|
||||
echo -e "> 更新脚本"
|
||||
|
||||
curl -sL https://${GITHUB_RAW_URL}/script/install.sh -o /tmp/nezha.sh
|
||||
new_version=$(cat /tmp/nezha.sh | grep "NZ_VERSION" | head -n 1 | awk -F "=" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
|
||||
if [ ! -n "$new_version" ]; then
|
||||
echo -e "脚本获取失败,请检查本机能否链接 https://${GITHUB_RAW_URL}/script/install.sh"
|
||||
return 1
|
||||
fi
|
||||
echo -e "当前最新版本为: ${new_version}"
|
||||
mv -f /tmp/nezha.sh ./nezha.sh && chmod a+x ./nezha.sh
|
||||
|
||||
echo -e "3s后执行新脚本"
|
||||
sleep 3s
|
||||
clear
|
||||
exec ./nezha.sh
|
||||
exit 0
|
||||
}
|
||||
|
||||
before_show_menu() {
|
||||
echo && echo -n -e "${yellow}* 按回车返回主菜单 *${plain}" && read temp
|
||||
show_menu
|
||||
}
|
||||
|
||||
install_base() {
|
||||
(command -v git >/dev/null 2>&1 && command -v curl >/dev/null 2>&1 && command -v wget >/dev/null 2>&1 && command -v unzip >/dev/null 2>&1) ||
|
||||
(install_soft curl wget git unzip)
|
||||
}
|
||||
|
||||
install_soft() {
|
||||
(command -v yum >/dev/null 2>&1 && yum install $* -y) ||
|
||||
(command -v apt >/dev/null 2>&1 && apt install $* -y) ||
|
||||
(command -v pacman >/dev/null 2>&1 && pacman -Syu $*) ||
|
||||
(command -v apt-get >/dev/null 2>&1 && apt-get install $* -y)
|
||||
}
|
||||
|
||||
install_dashboard() {
|
||||
install_base
|
||||
|
||||
echo -e "> 安装面板"
|
||||
|
||||
# 哪吒监控文件夹
|
||||
mkdir -p $NZ_DASHBOARD_PATH
|
||||
chmod 777 -R $NZ_DASHBOARD_PATH
|
||||
|
||||
command -v docker >/dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "正在安装 Docker"
|
||||
bash <(curl -sL https://${Get_Docker_URL}) ${Get_Docker_Argu} >/dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${red}下载脚本失败,请检查本机能否连接 ${Get_Docker_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
systemctl enable docker.service
|
||||
systemctl start docker.service
|
||||
echo -e "${green}Docker${plain} 安装成功"
|
||||
fi
|
||||
|
||||
command -v docker-compose >/dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "正在安装 Docker Compose"
|
||||
wget -O /usr/local/bin/docker-compose "https://${GITHUB_URL}/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" >/dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${red}下载脚本失败,请检查本机能否连接 ${GITHUB_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
chmod +x /usr/local/bin/docker-compose
|
||||
echo -e "${green}Docker Compose${plain} 安装成功"
|
||||
fi
|
||||
|
||||
modify_dashboard_config 0
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
install_agent() {
|
||||
install_base
|
||||
|
||||
echo -e "> 安装监控Agent"
|
||||
|
||||
echo -e "正在获取监控Agent版本号"
|
||||
|
||||
local version=$(curl -m 10 -sL "https://api.github.com/repos/naiba/nezha/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
|
||||
if [ ! -n "$version" ]; then
|
||||
version=$(curl -m 10 -sL "https://fastly.jsdelivr.net/gh/naiba/nezha/" | grep "option\.value" | awk -F "'" '{print $2}' | sed 's/naiba\/nezha@/v/g')
|
||||
fi
|
||||
|
||||
if [ ! -n "$version" ]; then
|
||||
echo -e "获取版本号失败,请检查本机能否链接 https://api.github.com/repos/naiba/nezha/releases/latest"
|
||||
return 0
|
||||
else
|
||||
echo -e "当前最新版本为: ${version}"
|
||||
fi
|
||||
|
||||
# 哪吒监控文件夹
|
||||
mkdir -p $NZ_AGENT_PATH
|
||||
chmod 777 -R $NZ_AGENT_PATH
|
||||
|
||||
echo -e "正在下载监控端"
|
||||
wget -O nezha-agent_linux_${os_arch}.zip https://${GITHUB_URL}/naiba/nezha/releases/download/${version}/nezha-agent_linux_${os_arch}.zip >/dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${red}Release 下载失败,请检查本机能否连接 ${GITHUB_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
unzip -qo nezha-agent_linux_${os_arch}.zip &&
|
||||
mv nezha-agent $NZ_AGENT_PATH &&
|
||||
rm -rf nezha-agent_linux_${os_arch}.zip README.md
|
||||
|
||||
if [ $# -ge 3 ]; then
|
||||
modify_agent_config "$@"
|
||||
else
|
||||
modify_agent_config 0
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
modify_agent_config() {
|
||||
echo -e "> 修改Agent配置"
|
||||
|
||||
wget -O $NZ_AGENT_SERVICE https://${GITHUB_RAW_URL}/script/nezha-agent.service >/dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${red}文件下载失败,请检查本机能否连接 ${GITHUB_RAW_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ $# -lt 3 ]; then
|
||||
echo "请先在管理面板上添加Agent,记录下密钥" &&
|
||||
read -ep "请输入一个解析到面板所在IP的域名(不可套CDN): " nz_grpc_host &&
|
||||
read -ep "请输入面板RPC端口: (5555)" nz_grpc_port &&
|
||||
read -ep "请输入Agent 密钥: " nz_client_secret
|
||||
if [[ -z "${nz_grpc_host}" || -z "${nz_client_secret}" ]]; then
|
||||
echo -e "${red}所有选项都不能为空${plain}"
|
||||
before_show_menu
|
||||
return 1
|
||||
fi
|
||||
if [[ -z "${nz_grpc_port}" ]]; then
|
||||
nz_grpc_port=5555
|
||||
fi
|
||||
else
|
||||
nz_grpc_host=$1
|
||||
nz_grpc_port=$2
|
||||
nz_client_secret=$3
|
||||
fi
|
||||
|
||||
sed -i "s/nz_grpc_host/${nz_grpc_host}/" ${NZ_AGENT_SERVICE}
|
||||
sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_AGENT_SERVICE}
|
||||
sed -i "s/nz_client_secret/${nz_client_secret}/" ${NZ_AGENT_SERVICE}
|
||||
|
||||
shift 3
|
||||
if [ $# -gt 0 ]; then
|
||||
args=" $*"
|
||||
sed -i "/ExecStart/ s/$/${args}/" ${NZ_AGENT_SERVICE}
|
||||
fi
|
||||
|
||||
echo -e "Agent配置 ${green}修改成功,请稍等重启生效${plain}"
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable nezha-agent
|
||||
systemctl restart nezha-agent
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
modify_dashboard_config() {
|
||||
echo -e "> 修改面板配置"
|
||||
|
||||
echo -e "正在下载 Docker 脚本"
|
||||
wget -O ${NZ_DASHBOARD_PATH}/docker-compose.yaml https://${GITHUB_RAW_URL}/script/docker-compose.yaml >/dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${red}下载脚本失败,请检查本机能否连接 ${GITHUB_RAW_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
mkdir -p $NZ_DASHBOARD_PATH/data
|
||||
|
||||
wget -O ${NZ_DASHBOARD_PATH}/data/config.yaml https://${GITHUB_RAW_URL}/script/config.yaml >/dev/null 2>&1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${red}下载脚本失败,请检查本机能否连接 ${GITHUB_RAW_URL}${plain}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "关于 GitHub Oauth2 应用:在 https://github.com/settings/developers 创建,无需审核,Callback 填 http(s)://域名或IP/oauth2/callback" &&
|
||||
echo "关于 Gitee Oauth2 应用:在 https://gitee.com/oauth/applications 创建,无需审核,Callback 填 http(s)://域名或IP/oauth2/callback" &&
|
||||
read -ep "请输入 OAuth2 提供商(gitee/github,默认 github): " nz_oauth2_type &&
|
||||
read -ep "请输入 Oauth2 应用的 Client ID: " nz_github_oauth_client_id &&
|
||||
read -ep "请输入 Oauth2 应用的 Client Secret: " nz_github_oauth_client_secret &&
|
||||
read -ep "请输入 GitHub/Gitee 登录名作为管理员,多个以逗号隔开: " nz_admin_logins &&
|
||||
read -ep "请输入站点标题: " nz_site_title &&
|
||||
read -ep "请输入站点访问端口: (默认 8008)" nz_site_port &&
|
||||
read -ep "请输入用于 Agent 接入的 RPC 端口: (默认 5555)" nz_grpc_port
|
||||
|
||||
if [[ -z "${nz_admin_logins}" || -z "${nz_github_oauth_client_id}" || -z "${nz_github_oauth_client_secret}" || -z "${nz_site_title}" ]]; then
|
||||
echo -e "${red}所有选项都不能为空${plain}"
|
||||
before_show_menu
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -z "${nz_site_port}" ]]; then
|
||||
nz_site_port=8008
|
||||
fi
|
||||
if [[ -z "${nz_grpc_port}" ]]; then
|
||||
nz_grpc_port=5555
|
||||
fi
|
||||
if [[ -z "${nz_oauth2_type}" ]]; then
|
||||
nz_oauth2_type=github
|
||||
fi
|
||||
|
||||
sed -i "s/nz_oauth2_type/${nz_oauth2_type}/" ${NZ_DASHBOARD_PATH}/data/config.yaml
|
||||
sed -i "s/nz_admin_logins/${nz_admin_logins}/" ${NZ_DASHBOARD_PATH}/data/config.yaml
|
||||
sed -i "s/nz_grpc_port/${nz_grpc_port}/" ${NZ_DASHBOARD_PATH}/data/config.yaml
|
||||
sed -i "s/nz_github_oauth_client_id/${nz_github_oauth_client_id}/" ${NZ_DASHBOARD_PATH}/data/config.yaml
|
||||
sed -i "s/nz_github_oauth_client_secret/${nz_github_oauth_client_secret}/" ${NZ_DASHBOARD_PATH}/data/config.yaml
|
||||
sed -i "s/nz_site_title/${nz_site_title}/" ${NZ_DASHBOARD_PATH}/data/config.yaml
|
||||
sed -i "s/nz_site_port/${nz_site_port}/" ${NZ_DASHBOARD_PATH}/docker-compose.yaml
|
||||
sed -i "s/nz_grpc_port/${nz_grpc_port}/g" ${NZ_DASHBOARD_PATH}/docker-compose.yaml
|
||||
sed -i "s/nz_image_url/${Docker_IMG}/" ${NZ_DASHBOARD_PATH}/docker-compose.yaml
|
||||
|
||||
echo -e "面板配置 ${green}修改成功,请稍等重启生效${plain}"
|
||||
|
||||
restart_and_update
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
restart_and_update() {
|
||||
echo -e "> 重启并更新面板"
|
||||
|
||||
cd $NZ_DASHBOARD_PATH
|
||||
docker-compose pull
|
||||
docker-compose down
|
||||
docker-compose up -d
|
||||
if [[ $? == 0 ]]; then
|
||||
echo -e "${green}哪吒监控 重启成功${plain}"
|
||||
echo -e "默认管理面板地址:${yellow}域名:站点访问端口${plain}"
|
||||
else
|
||||
echo -e "${red}重启失败,可能是因为启动时间超过了两秒,请稍后查看日志信息${plain}"
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
start_dashboard() {
|
||||
echo -e "> 启动面板"
|
||||
|
||||
cd $NZ_DASHBOARD_PATH && docker-compose up -d
|
||||
if [[ $? == 0 ]]; then
|
||||
echo -e "${green}哪吒监控 启动成功${plain}"
|
||||
else
|
||||
echo -e "${red}启动失败,请稍后查看日志信息${plain}"
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
stop_dashboard() {
|
||||
echo -e "> 停止面板"
|
||||
|
||||
cd $NZ_DASHBOARD_PATH && docker-compose down
|
||||
if [[ $? == 0 ]]; then
|
||||
echo -e "${green}哪吒监控 停止成功${plain}"
|
||||
else
|
||||
echo -e "${red}停止失败,请稍后查看日志信息${plain}"
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
show_dashboard_log() {
|
||||
echo -e "> 获取面板日志"
|
||||
|
||||
cd $NZ_DASHBOARD_PATH && docker-compose logs -f
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
uninstall_dashboard() {
|
||||
echo -e "> 卸载管理面板"
|
||||
|
||||
cd $NZ_DASHBOARD_PATH &&
|
||||
docker-compose down
|
||||
rm -rf $NZ_DASHBOARD_PATH
|
||||
docker rmi -f ghcr.io/naiba/nezha-dashboard > /dev/null 2>&1
|
||||
docker rmi -f registry.cn-shanghai.aliyuncs.com/naibahq/nezha-dashboard > /dev/null 2>&1
|
||||
clean_all
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
show_agent_log() {
|
||||
echo -e "> 获取Agent日志"
|
||||
|
||||
journalctl -xf -u nezha-agent.service
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
uninstall_agent() {
|
||||
echo -e "> 卸载Agent"
|
||||
|
||||
systemctl disable nezha-agent.service
|
||||
systemctl stop nezha-agent.service
|
||||
rm -rf $NZ_AGENT_SERVICE
|
||||
systemctl daemon-reload
|
||||
|
||||
rm -rf $NZ_AGENT_PATH
|
||||
clean_all
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
restart_agent() {
|
||||
echo -e "> 重启Agent"
|
||||
|
||||
systemctl restart nezha-agent.service
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
before_show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
clean_all() {
|
||||
if [ -z "$(ls -A ${NZ_BASE_PATH})" ]; then
|
||||
rm -rf ${NZ_BASE_PATH}
|
||||
fi
|
||||
}
|
||||
|
||||
show_usage() {
|
||||
echo "哪吒监控 管理脚本使用方法: "
|
||||
echo "--------------------------------------------------------"
|
||||
echo "./nezha.sh - 显示管理菜单"
|
||||
echo "./nezha.sh install_dashboard - 安装面板端"
|
||||
echo "./nezha.sh modify_dashboard_config - 修改面板配置"
|
||||
echo "./nezha.sh start_dashboard - 启动面板"
|
||||
echo "./nezha.sh stop_dashboard - 停止面板"
|
||||
echo "./nezha.sh restart_and_update - 重启并更新面板"
|
||||
echo "./nezha.sh show_dashboard_log - 查看面板日志"
|
||||
echo "./nezha.sh uninstall_dashboard - 卸载管理面板"
|
||||
echo "--------------------------------------------------------"
|
||||
echo "./nezha.sh install_agent - 安装监控Agent"
|
||||
echo "./nezha.sh modify_agent_config - 修改Agent配置"
|
||||
echo "./nezha.sh show_agent_log - 查看Agent日志"
|
||||
echo "./nezha.sh uninstall_agent - 卸载Agen"
|
||||
echo "./nezha.sh restart_agent - 重启Agen"
|
||||
echo "./nezha.sh update_script - 更新脚本"
|
||||
echo "--------------------------------------------------------"
|
||||
}
|
||||
|
||||
show_menu() {
|
||||
echo -e "
|
||||
${green}哪吒监控管理脚本${plain} ${red}${NZ_VERSION}${plain}
|
||||
--- https://github.com/naiba/nezha ---
|
||||
${green}1.${plain} 安装面板端
|
||||
${green}2.${plain} 修改面板配置
|
||||
${green}3.${plain} 启动面板
|
||||
${green}4.${plain} 停止面板
|
||||
${green}5.${plain} 重启并更新面板
|
||||
${green}6.${plain} 查看面板日志
|
||||
${green}7.${plain} 卸载管理面板
|
||||
————————————————-
|
||||
${green}8.${plain} 安装监控Agent
|
||||
${green}9.${plain} 修改Agent配置
|
||||
${green}10.${plain} 查看Agent日志
|
||||
${green}11.${plain} 卸载Agent
|
||||
${green}12.${plain} 重启Agent
|
||||
————————————————-
|
||||
${green}13.${plain} 更新脚本
|
||||
————————————————-
|
||||
${green}0.${plain} 退出脚本
|
||||
"
|
||||
echo && read -ep "请输入选择 [0-13]: " num
|
||||
|
||||
case "${num}" in
|
||||
0)
|
||||
exit 0
|
||||
;;
|
||||
1)
|
||||
install_dashboard
|
||||
;;
|
||||
2)
|
||||
modify_dashboard_config
|
||||
;;
|
||||
3)
|
||||
start_dashboard
|
||||
;;
|
||||
4)
|
||||
stop_dashboard
|
||||
;;
|
||||
5)
|
||||
restart_and_update
|
||||
;;
|
||||
6)
|
||||
show_dashboard_log
|
||||
;;
|
||||
7)
|
||||
uninstall_dashboard
|
||||
;;
|
||||
8)
|
||||
install_agent
|
||||
;;
|
||||
9)
|
||||
modify_agent_config
|
||||
;;
|
||||
10)
|
||||
show_agent_log
|
||||
;;
|
||||
11)
|
||||
uninstall_agent
|
||||
;;
|
||||
12)
|
||||
restart_agent
|
||||
;;
|
||||
13)
|
||||
update_script
|
||||
;;
|
||||
*)
|
||||
echo -e "${red}请输入正确的数字 [0-13]${plain}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
pre_check
|
||||
|
||||
if [[ $# > 0 ]]; then
|
||||
case $1 in
|
||||
"install_dashboard")
|
||||
install_dashboard 0
|
||||
;;
|
||||
"modify_dashboard_config")
|
||||
modify_dashboard_config 0
|
||||
;;
|
||||
"start_dashboard")
|
||||
start_dashboard 0
|
||||
;;
|
||||
"stop_dashboard")
|
||||
stop_dashboard 0
|
||||
;;
|
||||
"restart_and_update")
|
||||
restart_and_update 0
|
||||
;;
|
||||
"show_dashboard_log")
|
||||
show_dashboard_log 0
|
||||
;;
|
||||
"uninstall_dashboard")
|
||||
uninstall_dashboard 0
|
||||
;;
|
||||
"install_agent")
|
||||
shift
|
||||
if [ $# -ge 3 ]; then
|
||||
install_agent "$@"
|
||||
else
|
||||
install_agent 0
|
||||
fi
|
||||
;;
|
||||
"modify_agent_config")
|
||||
modify_agent_config 0
|
||||
;;
|
||||
"show_agent_log")
|
||||
show_agent_log 0
|
||||
;;
|
||||
"uninstall_agent")
|
||||
uninstall_agent 0
|
||||
;;
|
||||
"restart_agent")
|
||||
restart_agent 0
|
||||
;;
|
||||
"update_script")
|
||||
update_script 0
|
||||
;;
|
||||
*) show_usage ;;
|
||||
esac
|
||||
else
|
||||
show_menu
|
||||
fi
|
Loading…
Reference in New Issue
Block a user