67 lines
36 KiB
JavaScript
67 lines
36 KiB
JavaScript
import{_ as s,c as i,o as a,a4 as e}from"./chunks/framework.BmdFiWrL.js";const F=JSON.parse('{"title":"Install Agent","description":"","frontmatter":{"outline":"deep"},"headers":[],"relativePath":"en_US/guide/agent.md","filePath":"en_US/guide/agent.md","lastUpdated":1723329100000}'),n={name:"en_US/guide/agent.md"},t=e(`<h1 id="install-agent" tabindex="-1">Install Agent <a class="header-anchor" href="#install-agent" aria-label="Permalink to "Install Agent""></a></h1><p><strong>This document will introduce how to install the Agent on the monitored server and connect it to the Dashboard.</strong></p><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>The repository for Agent binaries can be found at: <a href="https://github.com/nezhahq/agent/releases" target="_blank" rel="noreferrer">https://github.com/nezhahq/agent/releases</a></p></div><h2 id="one-click-installation-of-the-agent" tabindex="-1">One-Click Installation of the Agent <a class="header-anchor" href="#one-click-installation-of-the-agent" aria-label="Permalink to "One-Click Installation of the Agent""></a></h2><p>Nezha Monitoring supports one-click installation of the Agent on both Windows and Linux. By following the steps in this document, you can easily deploy it on your server.</p><h3 id="preparation" tabindex="-1">Preparation <a class="header-anchor" href="#preparation" aria-label="Permalink to "Preparation""></a></h3><p>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”.<br> 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".</p><h3 id="one-click-installation-on-linux" tabindex="-1">One-Click Installation on Linux <a class="header-anchor" href="#one-click-installation-on-linux" aria-label="Permalink to "One-Click Installation on Linux""></a></h3><ol><li>First, add a server in the admin panel.</li><li>Click the green Linux icon button next to the newly added server and copy the one-click installation command.</li><li>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.</li></ol><h3 id="one-click-installation-on-macos" tabindex="-1">One-Click Installation on macOS <a class="header-anchor" href="#one-click-installation-on-macos" aria-label="Permalink to "One-Click Installation on macOS""></a></h3><ol><li>First, add a server in the admin panel.</li><li>Click the green Apple icon button next to the newly added server and copy the one-click installation command.</li><li>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.</li></ol><h3 id="one-click-installation-on-windows" tabindex="-1">One-Click Installation on Windows <a class="header-anchor" href="#one-click-installation-on-windows" aria-label="Permalink to "One-Click Installation on Windows""></a></h3><ol><li>First, add a server in the admin panel.</li><li>Click the green Windows icon button next to the newly added server and copy the one-click installation command.</li><li>Go to the Windows server, run PowerShell, and execute the copied installation command in PowerShell.</li><li>If you encounter a prompt to "change execution policy," choose Y.</li><li>Wait for the installation to complete, then check if the server is online in the Dashboard home page.</li></ol><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p>If you encounter errors when running the one-click installation command in PowerShell, try the <strong>Manual Installation of the Agent on Windows</strong> below.</p></div><h2 id="other-ways-to-install-the-agent" tabindex="-1">Other Ways to Install the Agent <a class="header-anchor" href="#other-ways-to-install-the-agent" aria-label="Permalink to "Other Ways to Install the Agent""></a></h2><h3 id="installing-the-agent-on-linux-support-most-distros" tabindex="-1">Installing the Agent on Linux (Support most distros) <a class="header-anchor" href="#installing-the-agent-on-linux-support-most-distros" aria-label="Permalink to "Installing the Agent on Linux (Support most distros)""></a></h3><details><summary>Click to expand/collapse</summary><ol><li>First, add a server in the admin panel.</li><li>Run the script on the monitored server:</li></ol><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">curl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -L</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://raw.githubusercontent.com/naiba/nezha/master/script/install_en.sh</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nezha.sh</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> && </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">chmod</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +x</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nezha.sh</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> && </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ./nezha.sh</span></span></code></pre></div><ol><li>Select “Install monitoring Agent.”</li><li>Enter the communication domain, such as "data.example.com".</li><li>Enter the dashboard communication port (gRPC port), default is 5555.</li><li>Enter the Agent secret, which is generated when you add a server in the admin panel and can be found on the “Servers” page in the admin panel.</li><li>Wait for the installation to complete, then check if the server is online in the Dashboard home page.</li></ol></details><h3 id="installing-the-agent-using-the-built-in-service-command-support-most-systems" tabindex="-1">Installing the Agent using the built-in service command (Support most systems) <a class="header-anchor" href="#installing-the-agent-using-the-built-in-service-command-support-most-systems" aria-label="Permalink to "Installing the Agent using the built-in service command (Support most systems)""></a></h3><details><summary>Click to expand/collapse</summary><p>First, get a copy of Nezha Agent: <a href="https://github.com/nezhahq/agent/releases" target="_blank" rel="noreferrer">https://github.com/nezhahq/agent/releases</a></p><p>After extracting the archive, run the following command to install the service (may require root permission):</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./nezha-agent</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> service</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -s</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> server_name:port</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> password</span></span></code></pre></div><p>You can also add other arguments except the server address and password. For more details, refer to the documentation: <a href="/en_US/guide/q7.html">Customizing Agent Monitoring Items</a>.</p><p>Uninstall the service:</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./nezha-agent</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> service</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> uninstall</span></span></code></pre></div><p>Start the service:</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./nezha-agent</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> service</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> start</span></span></code></pre></div><p>Stop the service:</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./nezha-agent</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> service</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> stop</span></span></code></pre></div><p>Restart the service:</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./nezha-agent</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> service</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> restart</span></span></code></pre></div></details><h3 id="installing-the-agent-with-runit" tabindex="-1">Installing the Agent with runit <a class="header-anchor" href="#installing-the-agent-with-runit" aria-label="Permalink to "Installing the Agent with runit""></a></h3><details><summary>Click to expand/collapse</summary><p>The built-in service command of Agent supports most init systems, including FreeBSD rc.d and openrc, but still missing some of them.</p><p>Here we take Void Linux's runit as an example:</p><ol><li>Create directory <code>/etc/sv/nezha-agent</code>:</li></ol><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mkdir</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/sv/nezha-agent</span></span></code></pre></div><ol start="2"><li>Create service file <code>/etc/sv/nezha-agent/run</code>, with following content:</li></ol><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/sh</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">exec</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> 2>&1</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">exec</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /opt/nezha/agent/nezha-agent</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -s</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> server_name:port</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> password</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> 2>&1</span></span></code></pre></div><p>You can add other arguments here as well.</p><ol start="3"><li>Create logging service file <code>/etc/sv/nezha-agent/log/run</code>:</li></ol><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/sh</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">exec</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> vlogger</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -t</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nezha-agent</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> daemon</span></span></code></pre></div><ol start="4"><li>Enable the service:</li></ol><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ln</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -s</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/sv/nezha-agent/</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /var/service</span></span></code></pre></div><p>Use the <code>sv</code> command to manage the service.</p><p>How to view logs:</p><ol><li>Install <code>socklog</code> and enable it:</li></ol><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> xbps-install</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -S</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> socklog-void</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ln</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -s</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/sv/socklog-unix</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /var/service</span></span></code></pre></div><ol start="2"><li>Run <code>svlogtail</code>:</li></ol><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> svlogtail</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> grep</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nezha-agent</span></span></code></pre></div></details><h3 id="manual-installation-of-the-agent-on-windows" tabindex="-1">Manual Installation of the Agent on Windows <a class="header-anchor" href="#manual-installation-of-the-agent-on-windows" aria-label="Permalink to "Manual Installation of the Agent on Windows""></a></h3><ul><li>Refer to the community article:<br><a href="https://nyko.me/2020/12/13/nezha-windows-client.html" target="_blank" rel="noreferrer">Nezha - Windows Client Installation</a> (Chinese)</li></ul><h3 id="installing-the-agent-on-synology-dsm" tabindex="-1">Installing the Agent on Synology DSM <a class="header-anchor" href="#installing-the-agent-on-synology-dsm" aria-label="Permalink to "Installing the Agent on Synology DSM""></a></h3><details><summary>Click to expand/collapse</summary><ul><li><p>Refer to community articles:<br><a href="https://blog.mitsea.com/3929551d08bd4bb0a8baa453e2d92b0c/" target="_blank" rel="noreferrer">Installing Nezha Monitoring Agent on Synology DSM 7.x</a> (Chinese)<br><a href="https://wl.gta5pdx.cn/archives/546/" target="_blank" rel="noreferrer">Nezha - Synology Client (Agent) Installation Tutorial</a> (Chinese)</p></li><li><p>Using Systemd <em>for DSM7 only</em>:</p></li></ul><div class="language-sh vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Agent path</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">EXEC</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"/PATH/TO/nezha-agent"</span></span>
|
||
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Log path</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">LOG</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"\${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">EXEC</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">}.log"</span></span>
|
||
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Additional execution parameters, can be empty</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ARGS</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">""</span></span>
|
||
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Nezha server gRPC address</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">SERVER</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"HOST_OR_IP:gRPC_PORT"</span></span>
|
||
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># The secret key obtained in the previous step</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">SECRET</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"APP_SECRET"</span></span>
|
||
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># User running the service, *strongly recommended to use non-root user*</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">RUN_USER</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"nezha"</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Write to systemd service file</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cat</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> <<</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> EOF</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /usr/lib/systemd/system/nezha.service</span></span>
|
||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[Unit]</span></span>
|
||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">Description=Nezha Agent Service</span></span>
|
||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">After=network.target</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[Service]</span></span>
|
||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">Type=simple</span></span>
|
||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">ExecStart=/bin/nohup \${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">EXEC</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">} \${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ARGS</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">} -s \${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">SERVER</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">} -p \${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">SECRET</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">} &>> \${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">LOG</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">} &</span></span>
|
||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">ExecStop=ps -fe |grep nezha-agent|awk '{print </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">2}'|xargs kill</span></span>
|
||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">User=\${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">RUN_USER</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">}</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">Restart=on-abort</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[Install]</span></span>
|
||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">WantedBy=multi-user.target</span></span>
|
||
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">EOF</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Reload service</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">systemctl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> daemon-reload</span></span>
|
||
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Start service</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">systemctl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> start</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nezha</span></span>
|
||
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Enable service startup</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">systemctl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> enable</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nezha</span></span></code></pre></div><p>‼️ Modify the corresponding information before running the above commands with the <code>root</code> account to complete the installation.</p></details><h3 id="installing-the-agent-on-macos-using-homebrew" tabindex="-1">Installing the Agent on macOS Using Homebrew <a class="header-anchor" href="#installing-the-agent-on-macos-using-homebrew" aria-label="Permalink to "Installing the Agent on macOS Using Homebrew""></a></h3><details><summary>Click to expand/collapse</summary><p><em><strong>This section is adapted from <a href="https://blog.mre.red/archives/install_nezha_monitoring_agent_service_with_homebrew" target="_blank" rel="noreferrer">🐿️松鼠收集🌰</a> with the author's permission</strong></em></p><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p>Please be sure to add environment variables before installing nezha-agent through Homebrew! Homebrew creates the service-required plist file during software installation, and if you add the environment variables after installation, it will fail to start due to missing parameters.</p></div><ol><li>Add environment variables:</li></ol><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'export HOMEBREW_NEZHA_AGENT_PASSWORD="Communication key, obtained from the service page"'</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.zshrc</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'export HOMEBREW_NEZHA_AGENT_SERVER="Your server and port, format your.domain:5555 "'</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> >></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.zshrc</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">source</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ~/.zshrc</span></span></code></pre></div><ol start="2"><li>Install Nezha Agent:</li></ol><div class="danger custom-block"><p class="custom-block-title">DANGER</p><p>Note that this Homebrew repository is maintained by a third party and is unrelated to Nezha Monitoring. The Nezha project team does not endorse this repository's usability, security, etc. Please evaluate the risks yourself before using!</p></div><p>Since it has not yet been submitted to the Homebrew Core official library, it is temporarily placed in the <a href="https://github.com/Brewforge/homebrew-chinese" target="_blank" rel="noreferrer">third-party Homebrew repository</a> maintained by the author of the blog:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> brewforge/chinese/nezha-agent</span></span></code></pre></div><ol start="3"><li>Start Nezha Agent service through Homebrew:</li></ol><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> services</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> start</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nezha-agent</span></span></code></pre></div><ol start="4"><li>Check the service status:</li></ol><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> services</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> info</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nezha-agent</span></span></code></pre></div><ol start="5"><li>Stop the service:</li></ol><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> services</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> stop</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nezha-agent</span></span></code></pre></div><ol start="6"><li>Uninstall Nezha Agent:</li></ol><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> rm</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nezha-agent</span></span></code></pre></div><ol start="7"><li>If there is an error, first check the environment variables:</li></ol><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $HOMEBREW_NEZHA_AGENT_PASSWORD</span></span>
|
||
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $HOMEBREW_NEZHA_AGENT_SERVER</span></span></code></pre></div><ol start="8"><li>If the environment variables are configured correctly, try reinstalling:</li></ol><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> services</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> stop</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nezha-agent</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> reinstall</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nezha-agent</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> services</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> start</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nezha-agent</span></span></code></pre></div><ol start="9"><li>If the issue persists, submit a issue to the <a href="https://github.com/Brewforge/homebrew-chinese" target="_blank" rel="noreferrer">third-party Homebrew repository</a>.</li></ol></details><h3 id="installing-the-agent-on-openwrt" tabindex="-1">Installing the Agent on OpenWRT <a class="header-anchor" href="#installing-the-agent-on-openwrt" aria-label="Permalink to "Installing the Agent on OpenWRT""></a></h3><details><summary>Click to expand/collapse</summary><p><strong>How to solve installation difficulties and issues in one step?</strong></p><ul><li>Refer to the project:<br><a href="https://github.com/dysf888/NZ-OpenWrt" target="_blank" rel="noreferrer">NZ-OpenWrt</a></li></ul><p><strong>How to enable autostart on older OpenWRT/LEDE?</strong></p><ul><li>Refer to the project:<br><a href="https://github.com/Erope/openwrt_nezha" target="_blank" rel="noreferrer">Nezha Monitoring for OpenWRT</a></li></ul><p><strong>How to enable autostart on newer OpenWRT? Contributor: @艾斯德斯</strong></p><ul><li>First, download the corresponding binary from the release, unzip the zip package, and place it in <code>/root</code>.</li><li>Run <code>chmod +x /root/nezha-agent</code> to grant execution permission, then create <code>/etc/init.d/nezha-service</code>:</li></ul><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/sh /etc/rc.common</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">START</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">99</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">USE_PROCD</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">1</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">start_service</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> procd_open_instance</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> procd_set_param</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> command</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /root/nezha-agent</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -s</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Dashboard</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> communication</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> domain:port</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Key</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -d</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> procd_set_param</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> respawn</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> procd_close_instance</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">stop_service</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> killall</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> nezha-agent</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">restart</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> stop</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> sleep</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> start</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><ul><li>Run <code>chmod +x /etc/init.d/nezha-service</code> to grant execution permission.</li><li>Start the service: <code>/etc/init.d/nezha-service enable && /etc/init.d/nezha-service start</code></li></ul></details><h2 id="does-the-agent-have-a-docker-image" tabindex="-1">Does the Agent Have a Docker Image? <a class="header-anchor" href="#does-the-agent-have-a-docker-image" aria-label="Permalink to "Does the Agent Have a Docker Image?""></a></h2><p><strong>The Agent does not currently have a Docker image.</strong><br> The design philosophy of the Agent is opposite to that of the Dashboard. While the Dashboard should minimally impact the server, the Agent needs to execute monitoring services and run commands within the server.<br> Running the Agent inside a container can still perform monitoring tasks, but features like WebShell will not function properly, so no Docker image is provided.</p>`,31),l=[t];function h(p,o,r,k,d,c){return a(),i("div",null,l)}const u=s(n,[["render",h]]);export{F as __pageData,u as default};
|