From 6bd154cb947728196b78dc238f473790c11ffb68 Mon Sep 17 00:00:00 2001 From: UUBulb <35923940+uubulb@users.noreply.github.com> Date: Sun, 14 Jul 2024 04:10:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=B6=E5=AE=83=E5=8F=82?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E6=9B=B4=E6=96=B0Agent=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20(#80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加其它参数,更新Agent安装方法 * edit --- docs/en_US/guide/agent.md | 231 ++++++++++++++----------------------- docs/en_US/guide/q7.md | 4 +- docs/en_US/guide/q9.md | 6 +- docs/guide/agent.md | 232 ++++++++++++++------------------------ docs/guide/q7.md | 4 +- docs/guide/q9.md | 2 +- 6 files changed, 182 insertions(+), 297 deletions(-) diff --git a/docs/en_US/guide/agent.md b/docs/en_US/guide/agent.md index cebb9f1a..abe30d5b 100644 --- a/docs/en_US/guide/agent.md +++ b/docs/en_US/guide/agent.md @@ -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)
Click to expand/collapse @@ -57,95 +63,98 @@ curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install_en.s
-### Installing the Agent on Other Linux Distributions (e.g., Alpine using Openrc) +### Installing the Agent using the built-in service command (Support most systems)
Click to expand/collapse -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 +``` + +
+ +### Installing the Agent with runit +
+ Click to expand/collapse + +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 ```
@@ -208,74 +217,6 @@ systemctl enable nezha -### Installing the Agent on macOS -
- Click to expand/collapse - -***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 - - - - - KeepAlive - - Label - nezha_agent - Program - Modify the path to the Agent binary file here, such as: /Users/123/Downloads/nezha-agent - ProgramArguments - - Modify the path to the Agent binary file here, same as above - --password - The communication secret, such as: 529664783eeb23cc25 - --server - The communication URL and gRPC port, such as: data.example.com:5555 - - RunAtLoad - - - -``` - -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 -``` - -
- ### Installing the Agent on macOS Using Homebrew
Click to expand/collapse diff --git a/docs/en_US/guide/q7.md b/docs/en_US/guide/q7.md index 5acf6b29..8e8ef78c 100755 --- a/docs/en_US/guide/q7.md +++ b/docs/en_US/guide/q7.md @@ -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. \ No newline at end of file +- `-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. \ No newline at end of file diff --git a/docs/en_US/guide/q9.md b/docs/en_US/guide/q9.md index c73f0160..1dede461 100644 --- a/docs/en_US/guide/q9.md +++ b/docs/en_US/guide/q9.md @@ -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: diff --git a/docs/guide/agent.md b/docs/guide/agent.md index 7597747a..27a41d35 100644 --- a/docs/guide/agent.md +++ b/docs/guide/agent.md @@ -18,12 +18,18 @@ Agent 二进制文件仓库地址为: 点击展开/收起 @@ -63,95 +69,98 @@ curl -L https://gitee.com/naibahq/nezha/raw/master/script/install.sh -o nezha.sh
-### 在其他 Linux 发行版(如 Alpine 使用 Openrc)中安装 Agent +### 使用 Agent 内置服务命令安装(支持主流系统)
点击展开/收起 -本节内容由 [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 +``` + +
+ +### runit 安装 Agent +
+ 点击展开/收起 + +目前 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 ```
@@ -216,75 +225,6 @@ systemctl enable nezha -### 在 macOS 中安装 Agent -
- 点击展开/收起 - -***本节内容改编自 [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 下载 amd64,Apple Silicon 下载 arm64 版本。下载完成后解压 Agent 二进制文件,如解压到下载文件夹。 -3. 新建一个名为 `nezha_agent.plist` 的文件并保存,修改文件内容如下: - -```xml - - - - - KeepAlive - - Label - nezha_agent - Program - 在这里修改 Agent 二进制文件的的路径,如:/Users/123/Downloads/nezha-agent - ProgramArguments - - 在这里修改 Agent 二进制文件的的路径,同上 - --password - 通信密钥,如:529664783eeb23cc25 - --server - 通信网址和 gRPC 端口,如:data.example.com:5555 - - RunAtLoad - - - -``` - -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 -``` - -
- ### 在 macOS 中使用 Homebrew 安装 Agent
点击展开/收起 diff --git a/docs/guide/q7.md b/docs/guide/q7.md index b7652ee5..941c493a 100644 --- a/docs/guide/q7.md +++ b/docs/guide/q7.md @@ -32,4 +32,6 @@ outline: deep - `--use-ipv6-countrycode`:强制使用 IPv6 地址查询国家代码。默认情况下,Agent 使用 IPv4 地址查询国家代码,如果服务器支持 IPv6 且与 IPv4 地址的国家代码不同,可以使用此参数。 - `--gpu`:启用 GPU 监控。注意:GPU 使用率监控可能需要安装额外的依赖包,详细信息可以参考文档:[启用 GPU 监控](/guide/q9.html)。 - `--temperature`:启用硬件温度监控。仅支持的硬件有效,部分 VPS 可能无法获取温度信息。 -- `--debug`:启用调试模式。 \ No newline at end of file +- `-d` `--debug`:启用调试模式。 +- `-u` `--ip-report-period`:本地IP更新间隔, 如果这个值小于 `--report-delay` 设置的值,那么以 `--report-delay` 的值为准。默认为1800秒(30分钟)。 +- `-k` `--insecure`:禁用证书检查,适用于使用自签证书的场景。 \ No newline at end of file diff --git a/docs/guide/q9.md b/docs/guide/q9.md index 16e1be63..3393417a 100644 --- a/docs/guide/q9.md +++ b/docs/guide/q9.md @@ -43,7 +43,7 @@ NVIDIA 显卡获取 GPU 使用率需要用到 `nvidia-smi` 工具,一般为官 ### AMD -AMD 显卡获取 GPU 使用率需要安装官方 `amdgpu` 驱动和 `rocm-smi` 工具。 +AMD 显卡获取 GPU 使用率需要安装 `amdgpu` 开源驱动和 `rocm-smi` 工具。 主流系统均已打包 `rocm-smi` ,以下是部分系统的安装命令: