Installing the Agent
The client-side service of Nezha Monitoring is called the Agent. This document will guide you on how to install the Agent on the client server and connect it to the Dashboard.
TIP
The binary repository for the Agent is available at: https://github.com/nezhahq/agent/releases
One-click Installation of the Agent
Nezha Monitoring supports one-click installation of the Agent on Windows, macOS, and Linux. By following the steps in this document, you can easily deploy it on your server.
Prerequisites
Before installation, you need to set up a communication domain in the Dashboard Admin Panel. It is not recommended to route this domain through a CDN. This document uses the example communication domains "data.example.com".
- In the Dashboard Admin Panel, click on your avatar to navigate to the System Settings page.
- In the Agent Connection Address [Domain/IP:Port] field, enter the communication domain and port, e.g.,
data.example.com:8008
. - Click Confirm to save the settings.
One-click Installation Steps
- On the Servers page, click Install Command and select your corresponding operating system. The installation command will be automatically copied to your clipboard.
- Run the installation command on the client server. After the installation completes, return to the Servers page to check if the Agent has come online.
- If the installation is successful, a new server will automatically appear on the page. You can click the Edit button to assign a name to it.
Platform-specific Instructions
Windows Specific Instructions
- On the Windows server, open PowerShell.
- Paste and run the installation command in PowerShell.
- If prompted with an "Execution Policy Change" confirmation, type
Y
and press Enter.
Alternative Methods to Install the Agent
Installing the Agent on Synology DSM 7
Click to Expand/Collapse
Since Synology NAS devices are based on specific versions of Linux, their shell environments and package managers differ from standard Linux systems, making one-click installation scripts unsupported. Therefore, you need to manually install the Agent by following these steps:
1. Preparation
Ensure Administrator Privileges
- Log in to the Synology management interface or SSH into the device using an administrator account.
Install Necessary Dependencies
Ensure that your Synology device haswget
,unzip
, orcurl
installed.
TIP
Alternatively, you can download and extract the Nezha Agent binaries in advance and manually upload them via Synology's DSM File Station, bypassing the need to install dependencies.
2. Download the Nezha Agent
Determine the Synology CPU Architecture
Use the following command to identify your device's architecture:bashuname -m
Common architecture mappings:
x86_64
corresponds toamd64
armv7l
oraarch64
corresponds toarm
Download the Appropriate Nezha Agent Binary
Select the correct download link based on your device's architecture. For example, foramd64
:bashwget -O nezha-agent.zip https://github.com/nezhahq/agent/releases/latest/download/nezha-agent_linux_amd64.zip
Extract the Files
Extract the downloaded archive to a specified directory, such as/opt/nezha
:bashmkdir -p /opt/nezha unzip nezha-agent.zip -d /opt/nezha
Grant Execute Permissions
bashchmod +x /opt/nezha/nezha-agent
3. Create the Configuration File
- Create and Edit the Configuration File
In the/opt/nezha
directory, create aconfig.yml
file with the following content:yamlclient_secret: your_agent_secret debug: false disable_auto_update: false disable_command_execute: false disable_force_update: false disable_nat: false disable_send_query: false gpu: false insecure_tls: false ip_report_period: 1800 report_delay: 1 server: data.example.com:8008 skip_connection_count: false skip_procs_count: false temperature: false tls: false use_gitee_to_upgrade: false use_ipv6_country_code: false uuid: your_uuid
- Field Descriptions:
server
: Replace with your Dashboard address and port, e.g.,data.example.com:8008
.client_secret
: Replace with theagentsecretkey
from the Dashboard's configuration file, typically located at/opt/nezha/dashboard/data/config.yaml
.uuid
: Generate a unique identifier for this Agent using theuuidgen
command:bashuuidgen
- Save the File: Save the file to
/opt/nezha/config.yml
.
- Field Descriptions:
4. Create a systemd Service File
Create the Service File
In the/etc/systemd/system/
directory, create anezha-agent.service
file:bashsudo nano /etc/systemd/system/nezha-agent.service
Add the Following Content:
ini[Unit] Description=Nezha Agent After=network.target [Service] Type=simple User=root Group=root ExecStart=/opt/nezha/nezha-agent -c /opt/nezha/config.yml Restart=always RestartSec=5 [Install] WantedBy=multi-user.target
Save the File and Reload Service Configuration:
bashsudo systemctl daemon-reload
5. Start the Agent
Start the Service
Use the following command to start the Agent:bashsudo systemctl start nezha-agent
Enable the Service to Start on Boot
bashsudo systemctl enable nezha-agent
Check Service Status
Ensure the Agent is running correctly:bashsudo systemctl status nezha-agent
6. Verify Agent Connection
- Log in to the Dashboard and check if a new device has come online.
- Ensure the Agent is running smoothly without any error logs.
Manually Installing the Agent on Windows
Click to Expand/Collapse
In addition to the one-click script, Windows systems can also install the Agent by downloading the corresponding binary files and manually configuring them. Follow the steps below:
1. Preparation
Ensure Administrator Privileges
Log in to the Windows system using an administrator account.Install Necessary Tools
- Ensure you have a decompression tool installed, such as
7-Zip
orWinRAR
.
- Ensure you have a decompression tool installed, such as
2. Download the Nezha Agent
Confirm System Architecture
- Windows systems are generally
amd64
architecture, so download the corresponding binary.
- Windows systems are generally
Download the Nezha Agent Files
- Visit the Nezha Agent Releases page and download the version suitable for
Windows
, for example:plaintextnezha-agent_windows_amd64.zip
- Visit the Nezha Agent Releases page and download the version suitable for
Extract the Files
- Extract the downloaded archive to a designated directory, such as
C:\nezha
.
- Extract the downloaded archive to a designated directory, such as
3. Create the Configuration File
Create and Edit the Configuration File
In the extracted directory, create aconfig.yml
file with the following content:yamlclient_secret: your_agent_secret debug: false disable_auto_update: false disable_command_execute: false disable_force_update: false disable_nat: false disable_send_query: false gpu: false insecure_tls: false ip_report_period: 1800 report_delay: 1 server: data.example.com:8008 skip_connection_count: false skip_procs_count: false temperature: false tls: false use_gitee_to_upgrade: false use_ipv6_country_code: false uuid: your_uuid
- Field Descriptions:
server
: Replace with your Dashboard address and port, e.g.,data.example.com:8008
.client_secret
: Replace with theagentsecretkey
from the Dashboard's configuration file, typically located at/opt/nezha/dashboard/data/config.yaml
.uuid
: Generate a unique identifier for this Agent using an online tool.
- Field Descriptions:
Save the File
Save the file asconfig.yml
in the Agent's directory.
4. Run the Agent
Run the Agent with Administrator Privileges
Open CMD with administrator rights, navigate to the Agent's directory, and execute the following command:powershellnezha-agent.exe -c config.yml
Verify the Connection
- Log in to the Dashboard and check if a new device has come online.
- If there are no error messages in the Agent's logs, the installation is successful.
5. Configure the Agent to Run as a Service
Install as a Service
- Navigate to the Agent's directory in CMD and run:powershell
nezha-agent.exe service install
- Navigate to the Agent's directory in CMD and run:
Start the Service
- After successful installation, the Agent will automatically start as a service and will run on system boot.
Uninstall the Service
- To uninstall the service, run the following command:powershell
nezha-agent.exe service uninstall
- To uninstall the service, run the following command:
Installing the Agent on OpenWrt
Click to Expand/Collapse
OpenWrt is a lightweight Linux distribution. Installing the Nezha Agent on OpenWrt requires manual downloading and configuration. Follow the steps below:
1. Preparation
Ensure Administrator Privileges
- SSH into the OpenWrt device using the
root
account.
- SSH into the OpenWrt device using the
Install Necessary Tools
- Update the package list and install required tools:bash
opkg update opkg install wget unzip
- Update the package list and install required tools:
2. Download the Nezha Agent
Determine System Architecture
Use the following command to identify the device's architecture:bashuname -m
Common architecture mappings:
x86_64
corresponds tonezha-agent_linux_amd64.zip
arm
oraarch64
corresponds tonezha-agent_linux_arm.zip
Download the Appropriate Nezha Agent
Replace<arch>
with your device's architecture:bashwget -O nezha-agent.zip https://github.com/nezhahq/agent/releases/latest/download/nezha-agent_linux_<arch>.zip
Extract the Files
Extract the archive to the/etc/nezha
directory:bashmkdir -p /etc/nezha unzip nezha-agent.zip -d /etc/nezha
3. Create the Configuration File
Create the Configuration File
Create and edit the/etc/nezha/config.yml
file:bashtouch /etc/nezha/config.yml vi /etc/nezha/config.yml
Add the following content:
yamlclient_secret: your_agent_secret debug: false disable_auto_update: false disable_command_execute: false disable_force_update: false disable_nat: false disable_send_query: false gpu: false insecure_tls: false ip_report_period: 1800 report_delay: 1 server: data.example.com:8008 skip_connection_count: false skip_procs_count: false temperature: false tls: false use_gitee_to_upgrade: false use_ipv6_country_code: false uuid: your_uuid
Save the Configuration File
Ensure the configuration file is saved at/etc/nezha/config.yml
.
4. Run the Agent
Grant Execute Permissions and Start the Agent
bashchmod +x /etc/nezha/nezha-agent /etc/nezha/nezha-agent -c /etc/nezha/config.yml
Verify Agent Connection
- Log in to the Dashboard Admin Panel and check if a new device has come online.
- Ensure the Agent is running correctly.
5. Configure the Agent to Start on Boot
Create a Service Script
Create a service script at/etc/init.d/nezha-service
:bashvi /etc/init.d/nezha-service
Add the Following Content
Replace/etc/nezha/nezha-agent
and/etc/nezha/config.yml
with the correct paths if different:bash#!/bin/sh /etc/rc.common START=99 USE_PROCD=1 start_service() { procd_open_instance procd_set_param command /etc/nezha/nezha-agent -c /etc/nezha/config.yml procd_set_param respawn procd_close_instance } stop_service() { killall nezha-agent } restart() { stop sleep 2 start }
Grant Execute Permissions
bashchmod +x /etc/init.d/nezha-service
Enable and Start the Service
bash/etc/init.d/nezha-service enable /etc/init.d/nezha-service start
Verify Service Status
Check if the service is running correctly:bashps | grep nezha-agent
Note
- Configuration File Path: Ensure the paths to the configuration files (e.g.,
/etc/nezha/config.yml
) are correct in the service scripts. - Service Management: You can manage the service using the following commands:
- Manually start the service:bash
/etc/init.d/nezha-service start
- Stop the service:bash
/etc/init.d/nezha-service stop
- Restart the service:bash
/etc/init.d/nezha-service restart
- Manually start the service:
- Log Troubleshooting: If the Agent fails to start correctly, check relevant logs using
logread
to identify issues.
Uninstalling the Agent
Uninstalling the Agent involves stopping the service, uninstalling it, and removing related files. Below are the steps for Ubuntu:
Stop and uninstall the service:
bashcd /opt/nezha/agent/ ./nezha-agent service uninstall
Remove the Agent folder:
bashrm -rf /opt/nezha/agent/
If multiple services are installed and removing all of them would be necessary, the Agent installation script can be used to simplify the process.
./agent.sh uninstall