增加其它参数,更新Agent安装方法 (#80)

* 增加其它参数,更新Agent安装方法

* edit
This commit is contained in:
UUBulb 2024-07-14 04:10:24 +08:00 committed by GitHub
parent 0be33797e1
commit 6bd154cb94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 182 additions and 297 deletions

View File

@ -18,12 +18,18 @@ Nezha Monitoring supports one-click installation of the Agent on both Windows an
You need to set up a communication domain in the admin panel in advance, and this domain should not be connected to a CDN. This document uses the example communication domain “data.example.com”.
Go to the settings page in the admin panel, fill in the communication domain in the “Non-CDN Dashboard Server Domain/IP” field, and click "Save".
### One-Click Installation on Linux (Ubuntu, Debian, CentOS)
### One-Click Installation on Linux
1. First, add a server in the admin panel.
2. Click the green Linux icon button next to the newly added server and copy the one-click installation command.
3. Run the copied installation command on the monitored server, and wait for the installation to complete. Then, check if the server is online in the Dashboard home page.
### One-Click Installation on macOS
1. First, add a server in the admin panel.
2. Click the green Apple icon button next to the newly added server and copy the one-click installation command.
3. Run the copied installation command on the monitored server, and wait for the installation to complete. Then, check if the server is online in the Dashboard home page.
### One-Click Installation on Windows
1. First, add a server in the admin panel.
@ -38,7 +44,7 @@ If you encounter errors when running the one-click installation command in Power
## Other Ways to Install the Agent
### Installing the Agent on Linux (Ubuntu, Debian, CentOS)
### Installing the Agent on Linux (Support most distros)
<details>
<summary>Click to expand/collapse</summary>
@ -57,95 +63,98 @@ curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install_en.s
</details>
### Installing the Agent on Other Linux Distributions (e.g., Alpine using Openrc)
### Installing the Agent using the built-in service command (Support most systems)
<details>
<summary>Click to expand/collapse</summary>
This section is contributed by [unknown0054](https://github.com/unknwon0054).
First, get a copy of Nezha Agent: https://github.com/nezhahq/agent/releases
1. Modify SERVER, SECRET, TLS, and execute in the shell:
After extracting the archive, run the following command to install the service (may require root permission):
```shell
cat >/etc/init.d/nezha-agent<< EOF
#!/sbin/openrc-run
SERVER="" # Dashboard domain ip:port
SECRET="" # SECRET
TLS="" # Enable TLS if yes "--tls", leave empty if no
NZ_BASE_PATH="/opt/nezha"
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
pidfile="/run/${RC_SVCNAME}.pid"
command="/opt/nezha/agent/nezha-agent"
command_args="-s ${SERVER} -p ${SECRET} ${TLS}"
command_background=true
depend() {
need net
}
checkconfig() {
GITHUB_URL="github.com"
if [ ! -f "${NZ_AGENT_PATH}/nezha-agent" ]; then
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
local version=$(curl -m 10 -sL "https://api.github.com/repos/nezhahq/agent/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/nezhahq/agent/" | grep "option\.value" | awk -F "'" '{print $2}' | sed 's/nezhahq\/agent@/v/g')
fi
if [ ! -n "$version" ]; then
version=$(curl -m 10 -sL "https://gcore.jsdelivr.net/gh/nezhahq/agent/" | grep "option\.value" | awk -F "'" '{print $2}' | sed 's/nezhahq\/agent@/v/g')
fi
if [ ! -n "$version" ]; then
echo -e "Failed to get the version number. Please check if the server can connect to https://api.github.com/repos/nezhahq/agent/releases/latest"
return 0
else
echo -e "The latest version is: ${version}"
fi
wget -t 2 -T 10 -O nezha-agent_linux_${os_arch}.zip https://${GITHUB_URL}/nezhahq/agent/releases/download/${version}/nezha-agent_linux_${os_arch}.zip >/dev/null 2>&1
if [[ $? != 0 ]]; then
echo -e "Failed to download Release. Please check if the server can connect to ${GITHUB_URL}"
return 0
fi
mkdir -p $NZ_AGENT_PATH
chmod 755 -R $NZ_AGENT_PATH
unzip -qo nezha-agent_linux_${os_arch}.zip && mv nezha-agent $NZ_AGENT_PATH && rm -rf nezha-agent_linux_${os_arch}.zip README.md
fi
if [ ! -x "${NZ_AGENT_PATH}/nezha-agent" ]; then
chmod +x ${NZ_AGENT_PATH}/nezha-agent
fi
}
start_pre() {
if [ "${RC_CMD}" != "restart" ]; then
checkconfig || return $?
fi
}
EOF
```bash
./nezha-agent service install -s server_name:port -p password
```
2. Add execute permissions
You can also add other arguments except the server address and password. For more details, refer to the documentation: [Customizing Agent Monitoring Items](/en_US/guide/q7.html).
```shell
chmod +x /etc/init.d/nezha-agent
Uninstall the service:
```bash
./nezha-agent service uninstall
```
3. Start Nezha-Agent
Start the service:
```shell
rc-service nezha-agent start
```bash
./nezha-agent service start
```
4. Add to startup
Stop the service:
```shell
rc-update add nezha-agent
```bash
./nezha-agent service stop
```
Restart the service:
```bash
./nezha-agent service restart
```
</details>
### Installing the Agent with runit
<details>
<summary>Click to expand/collapse</summary>
The built-in service command of Agent supports most init systems, including FreeBSD rc.d and openrc, but still missing some of them.
Here we take Void Linux's runit as an example:
1. Create directory `/etc/sv/nezha-agent`:
```bash
mkdir /etc/sv/nezha-agent
```
2. Create service file `/etc/sv/nezha-agent/run`, with following content:
```bash
#!/bin/sh
exec 2>&1
exec /opt/nezha/agent/nezha-agent -s server_name:port -p password 2>&1
```
You can add other arguments here as well.
3. Create logging service file `/etc/sv/nezha-agent/log/run`:
```bash
#!/bin/sh
exec vlogger -t nezha-agent -p daemon
```
4. Enable the service:
```bash
sudo ln -s /etc/sv/nezha-agent/ /var/service
```
Use the `sv` command to manage the service.
How to view logs:
1. Install `socklog` and enable it:
```bash
sudo xbps-install -S socklog-void
sudo ln -s /etc/sv/socklog-unix /var/service
```
2. Run `svlogtail`:
```bash
sudo svlogtail | grep nezha-agent
```
</details>
@ -208,74 +217,6 @@ systemctl enable nezha
</details>
### Installing the Agent on macOS
<details>
<summary>Click to expand/collapse</summary>
***This section is adapted from [Mitsea Blog](https://blog.mitsea.com/e796f93db38d49e4b18df234c6ee75f5) with the author's permission***
::: warning
If you are prompted "macOS cannot verify this app" during installation, manually allow the program to run in System Settings.
:::
1. First, add a server in the admin panel.
2. Go to the [Release](https://github.com/nezhahq/agent/releases) page to download the Agent binary file. Choose to download the darwin amd64 or arm64 Agent according to your CPU architecture. Download the amd64 version for Intel CPU, or the arm64 version for Apple Silicon. After downloading, unzip the Agent binary file, such as unzipping it to the Downloads folder.
3. Create a file named `nezha_agent.plist` and save it with the following content:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>nezha_agent</string>
<key>Program</key>
<string>Modify the path to the Agent binary file here, such as: /Users/123/Downloads/nezha-agent</string>
<key>ProgramArguments</key>
<array>
<string>Modify the path to the Agent binary file here, same as above</string>
<string>--password</string>
<string>The communication secret, such as: 529664783eeb23cc25</string>
<string>--server</string>
<string>The communication URL and gRPC port, such as: data.example.com:5555</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
```
4. Load the plist file into launchd using the following command in Terminal, **make sure to replace the file path**:
```shell
launchctl load /Users/123/Desktop/nezha_agent.plist
```
5. Start the process:
```shell
launchctl start nezha_agent
```
6. Check if the process is running:
```shell
launchctl list | grep nezha_agent
```
7. Stop the process and remove it:
```shell
launchctl stop nezha_agent
```
```shell
launchctl remove nezha_agent
```
</details>
### Installing the Agent on macOS Using Homebrew
<details>
<summary>Click to expand/collapse</summary>

View File

@ -32,4 +32,6 @@ If you installed the Agent using a one-click script, you can add or modify param
- `--use-ipv6-countrycode`: Forces the use of IPv6 addresses to query country codes. By default, the Agent uses IPv4 addresses to query country codes. If server supports IPv6 and the country code of the IPv4 address is different, can use this parameter.
- `--gpu`: Enables GPU monitoring. Note: Monitoring GPU usage may require installation of additional dependencies. For more details, refer to the documentation: [Enable GPU Monitoring](/en_US/guide/q9.html).
- `--temperature`: Enables hardware temperature monitoring. Only effective on supported hardware, some VPS may not be able to retrieve temperature information.
- `--debug`: Enables debug mode.
- `-d` `--debug`: Enables debug mode.
- `-u` `--ip-report-period`: Set IP update interval. Is only effective when the set value is higher than `--report-delay`. The default is 1800 seconds.
- `-k` `--insecure`: Disable TLS certificate integrity check. Useful in situations involving a self-signed certificate.

View File

@ -3,7 +3,7 @@ outline: deep
---
# Enable GPU monitoring
GPU monitoring is a new feature implemented in Nezha Monitoring v0.17.x. Before using the feature, please check you Dashboard version is higher than v0.17.2 and Agent version is higher than v0.17.0.
GPU monitoring is a new feature implemented in Nezha Monitoring v0.17.x. Before using the feature, please ensure your Dashboard version is higher than v0.17.2 and Agent version is higher than v0.17.0.
## Enable
@ -23,7 +23,7 @@ Execute the following command to modify Agent configuration to enable GPU monito
/opt/nezha/agent/nezha-agent edit
```
In the returned interactive menu, choose to enable GPU monitoring.
In the interactive menu returned, choose to enable GPU monitoring.
## Enable GPU utilization monitoring
@ -43,7 +43,7 @@ If you use unofficial drivers like `nouveau`, then it's not possible to get GPU
### AMD
AMD cards need to install the official `amdgpu` driver and the `rocm-smi` utility.
AMD cards need to install the open source `amdgpu` driver and the `rocm-smi` utility.
Mainstream distros have already packaged `rocm-smi`, below are commands to install the utility on these distros:

View File

@ -18,12 +18,18 @@ Agent 二进制文件仓库地址为:<https://github.com/nezhahq/agent/release
你需要提前在管理面板中设置好通信域名,此域名不可以接入 CDN。本文档以示例通信域名 “data.example.com” 为例。
进入后台管理面板,转到“设置”页,在“未接入 CDN 的面板服务器域名/IP”项中填入通信域名然后点击"保存"。
### 在 Linux 中一键安装 (Ubuntu、Debian、CentOS)
### 在 Linux 中一键安装
1. 首先在管理面板中添加一台服务器。
2. 点击新添加的服务器旁的绿色 Linux 图标按钮,复制一键安装命令。
3. 在被控端服务器中运行复制的一键安装命令,等待安装完成后返回到 Dashboard 主页查看服务器是否上线。
### 在 macOS 中一键安装
1. 首先在管理面板中添加一台服务器。
2. 点击新添加的服务器旁的绿色 Apple 图标按钮,复制一键安装命令。
3. 在被控端服务器中运行复制的一键安装命令,等待安装完成后返回到 Dashboard 主页查看服务器是否上线。
### 在 Windows 中一键安装
1. 首先在管理面板中添加一台服务器。
@ -38,7 +44,7 @@ Agent 二进制文件仓库地址为:<https://github.com/nezhahq/agent/release
## 其他方式安装 Agent
### 在 Linux 中安装 Agent (Ubuntu、Debian、CentOS)
### 在 Linux 中安装 Agent(支持大部分发行版)
<details>
<summary>点击展开/收起</summary>
@ -63,95 +69,98 @@ curl -L https://gitee.com/naibahq/nezha/raw/master/script/install.sh -o nezha.sh
</details>
### 在其他 Linux 发行版(如 Alpine 使用 Openrc中安装 Agent
### 使用 Agent 内置服务命令安装(支持主流系统)
<details>
<summary>点击展开/收起</summary>
本节内容由 [unknown0054](https://github.com/unknwon0054) 贡献。
首先获取 Agent 的二进制文件https://github.com/nezhahq/agent/releases
1. 修改 SERVER、SECRET、TLS然后在 shell 中执行
解压后输入以下命令安装服务(可能需要 root 权限)
```shell
cat >/etc/init.d/nezha-agent<< EOF
#!/sbin/openrc-run
SERVER="" # Dashboard 地址 ip:port
SECRET="" # SECRET
TLS="" # 是否启用 TLS是 "--tls" ,否留空
NZ_BASE_PATH="/opt/nezha"
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
pidfile="/run/${RC_SVCNAME}.pid"
command="/opt/nezha/agent/nezha-agent"
command_args="-s ${SERVER} -p ${SECRET} ${TLS}"
command_background=true
depend() {
need net
}
checkconfig() {
GITHUB_URL="github.com"
if [ ! -f "${NZ_AGENT_PATH}/nezha-agent" ]; then
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
local version=$(curl -m 10 -sL "https://api.github.com/repos/nezhahq/agent/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/nezhahq/agent/" | grep "option\.value" | awk -F "'" '{print $2}' | sed 's/nezhahq\/agent@/v/g')
fi
if [ ! -n "$version" ]; then
version=$(curl -m 10 -sL "https://gcore.jsdelivr.net/gh/nezhahq/agent/" | grep "option\.value" | awk -F "'" '{print $2}' | sed 's/nezhahq\/agent@/v/g')
fi
if [ ! -n "$version" ]; then
echo -e "获取版本号失败,请检查本机能否链接 https://api.github.com/repos/nezhahq/agent/releases/latest"
return 0
else
echo -e "当前最新版本为: ${version}"
fi
wget -t 2 -T 10 -O nezha-agent_linux_${os_arch}.zip https://${GITHUB_URL}/nezhahq/agent/releases/download/${version}/nezha-agent_linux_${os_arch}.zip >/dev/null 2>&1
if [[ $? != 0 ]]; then
echo -e "Release 下载失败,请检查本机能否连接 ${GITHUB_URL}${plain}"
return 0
fi
mkdir -p $NZ_AGENT_PATH
chmod 755 -R $NZ_AGENT_PATH
unzip -qo nezha-agent_linux_${os_arch}.zip && mv nezha-agent $NZ_AGENT_PATH && rm -rf nezha-agent_linux_${os_arch}.zip README.md
fi
if [ ! -x "${NZ_AGENT_PATH}/nezha-agent" ]; then
chmod +x ${NZ_AGENT_PATH}/nezha-agent
fi
}
start_pre() {
if [ "${RC_CMD}" != "restart" ]; then
checkconfig || return $?
fi
}
EOF
```bash
./nezha-agent service install -s server_name:port -p password
```
2. 增加运行权限
除了服务器地址和密码,还可以添加其它支持的参数。具体参考[自定义 Agent 监控项目](/guide/q7.html)
```shell
chmod +x /etc/init.d/nezha-agent
卸载服务:
```bash
./nezha-agent service uninstall
```
3. 运行 Nezha-Agent
启动服务:
```shell
rc-service nezha-agent start
```bash
./nezha-agent service start
```
4. 添加开机自启动
停止服务:
```shell
rc-update add nezha-agent
```bash
./nezha-agent service stop
```
重启服务:
```bash
./nezha-agent service restart
```
</details>
### runit 安装 Agent
<details>
<summary>点击展开/收起</summary>
目前 Agent 内置的服务功能已经支持了绝大部分 init 系统,包括 FreeBSD rc.d 和 openrc。尽管如此还是有一些漏网之鱼。
这里使用 Void Linux 的 runit 作为示例:
1. 创建 `/etc/sv/nezha-agent` 目录:
```bash
mkdir /etc/sv/nezha-agent
```
2. 创建 `/etc/sv/nezha-agent/run` 服务文件,写入以下内容:
```bash
#!/bin/sh
exec 2>&1
exec /opt/nezha/agent/nezha-agent -s server_name:port -p password 2>&1
```
这里同样可以添加其它参数。
3. 创建 `/etc/sv/nezha-agent/log/run`
```bash
#!/bin/sh
exec vlogger -t nezha-agent -p daemon
```
4. 启用服务:
```bash
sudo ln -s /etc/sv/nezha-agent/ /var/service
```
之后可以通过 `sv` 命令来操作服务。
如何查看日志:
1. 安装 `socklog`,并启用:
```bash
sudo xbps-install -S socklog-void
sudo ln -s /etc/sv/socklog-unix /var/service
```
2. 运行 `svlogtail` 查看日志:
```bash
sudo svlogtail | grep nezha-agent
```
</details>
@ -216,75 +225,6 @@ systemctl enable nezha
</details>
### 在 macOS 中安装 Agent
<details>
<summary>点击展开/收起</summary>
***本节内容改编自 [Mitsea Blog](https://blog.mitsea.com/e796f93db38d49e4b18df234c6ee75f5),改编已获得原作者授权***
::: warning
安装过程中如提示“macOS 无法验证此 app“请前往系统设置手动允许程序运行。
:::
1. 首先在管理面板中添加一台服务器。
2. 前往 [Release](https://github.com/nezhahq/agent/releases) 页下载 Agent 二进制文件,根据 CPU 架构选择下载 darwin amd64 还是 arm64 的 Agent。
如 Intel CPU 下载 amd64Apple Silicon 下载 arm64 版本。下载完成后解压 Agent 二进制文件,如解压到下载文件夹。
3. 新建一个名为 `nezha_agent.plist` 的文件并保存,修改文件内容如下:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>nezha_agent</string>
<key>Program</key>
<string>在这里修改 Agent 二进制文件的的路径,如:/Users/123/Downloads/nezha-agent</string>
<key>ProgramArguments</key>
<array>
<string>在这里修改 Agent 二进制文件的的路径,同上</string>
<string>--password</string>
<string>通信密钥529664783eeb23cc25</string>
<string>--server</string>
<string>通信网址和 gRPC 端口,如:data.example.com:5555</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
```
4. 在 Terminal 中使用下面的命令加载 plist 文件到 launchd 里,**注意替换文件路径**
```shell
launchctl load /Users/123/Desktop/nezha_agent.plist
```
5. 启动进程:
```shell
launchctl start nezha_agent
```
6. 检查进程是否运行:
```shell
launchctl list | grep nezha_agent
```
7. 停止进程并移除:
```shell
launchctl stop nezha_agent
```
```shell
launchctl remove nezha_agent
```
</details>
### 在 macOS 中使用 Homebrew 安装 Agent
<details>
<summary>点击展开/收起</summary>

View File

@ -32,4 +32,6 @@ outline: deep
- `--use-ipv6-countrycode`:强制使用 IPv6 地址查询国家代码。默认情况下Agent 使用 IPv4 地址查询国家代码,如果服务器支持 IPv6 且与 IPv4 地址的国家代码不同,可以使用此参数。
- `--gpu`:启用 GPU 监控。注意GPU 使用率监控可能需要安装额外的依赖包,详细信息可以参考文档:[启用 GPU 监控](/guide/q9.html)。
- `--temperature`:启用硬件温度监控。仅支持的硬件有效,部分 VPS 可能无法获取温度信息。
- `--debug`:启用调试模式。
- `-d` `--debug`:启用调试模式。
- `-u` `--ip-report-period`本地IP更新间隔, 如果这个值小于 `--report-delay` 设置的值,那么以 `--report-delay` 的值为准。默认为1800秒30分钟
- `-k` `--insecure`:禁用证书检查,适用于使用自签证书的场景。

View File

@ -43,7 +43,7 @@ NVIDIA 显卡获取 GPU 使用率需要用到 `nvidia-smi` 工具,一般为官
### AMD
AMD 显卡获取 GPU 使用率需要安装官方 `amdgpu` 驱动和 `rocm-smi` 工具。
AMD 显卡获取 GPU 使用率需要安装 `amdgpu` 开源驱动和 `rocm-smi` 工具。
主流系统均已打包 `rocm-smi` ,以下是部分系统的安装命令: