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":1724530785000}'),n={name:"en_US/guide/agent.md"},t=e(`
This document will introduce how to install the Agent on the monitored server and connect it to the Dashboard.
TIP
The repository for Agent binaries can be found at: https://github.com/nezhahq/agent/releases
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.
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".
WARNING
If you encounter errors when running the one-click installation command in PowerShell, try the Manual Installation of the Agent on Windows below.
curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install_en.sh -o nezha.sh && chmod +x nezha.sh && sudo ./nezha.sh
First, get a copy of Nezha Agent: https://github.com/nezhahq/agent/releases
After extracting the archive, run the following command to install the service (may require root permission):
./nezha-agent service install -s server_name:port -p password
You can also add other arguments except the server address and password. For more details, refer to the documentation: Customizing Agent Monitoring Items.
Uninstall the service:
./nezha-agent service uninstall
Start the service:
./nezha-agent service start
Stop the service:
./nezha-agent service stop
Restart the service:
./nezha-agent service restart
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:
/etc/sv/nezha-agent
:mkdir /etc/sv/nezha-agent
/etc/sv/nezha-agent/run
, with following content:#!/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.
/etc/sv/nezha-agent/log/run
:#!/bin/sh
exec vlogger -t nezha-agent -p daemon
sudo ln -s /etc/sv/nezha-agent/ /var/service
Use the sv
command to manage the service.
How to view logs:
socklog
and enable it:sudo xbps-install -S socklog-void
sudo ln -s /etc/sv/socklog-unix /var/service
svlogtail
:sudo svlogtail | grep nezha-agent
Refer to community articles:
Installing Nezha Monitoring Agent on Synology DSM 7.x (Chinese)
Nezha - Synology Client (Agent) Installation Tutorial (Chinese)
Using Systemd for DSM7 only:
# Agent path
EXEC="/PATH/TO/nezha-agent"
# Log path
LOG="\${EXEC}.log"
# Additional execution parameters, can be empty
ARGS=""
# Nezha server gRPC address
SERVER="HOST_OR_IP:gRPC_PORT"
# The secret key obtained in the previous step
SECRET="APP_SECRET"
# User running the service, *strongly recommended to use non-root user*
RUN_USER="nezha"
# Write to systemd service file
cat << EOF > /usr/lib/systemd/system/nezha.service
[Unit]
Description=Nezha Agent Service
After=network.target
[Service]
Type=simple
ExecStart=/bin/nohup \${EXEC} \${ARGS} -s \${SERVER} -p \${SECRET} &>> \${LOG} &
ExecStop=ps -fe |grep nezha-agent|awk '{print \\$2}'|xargs kill
User=\${RUN_USER}
Restart=on-abort
[Install]
WantedBy=multi-user.target
EOF
# Reload service
systemctl daemon-reload
# Start service
systemctl start nezha
# Enable service startup
systemctl enable nezha
‼️ Modify the corresponding information before running the above commands with the root
account to complete the installation.
This section is adapted from 🐿️松鼠收集🌰 with the author's permission
WARNING
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.
echo 'export HOMEBREW_NEZHA_AGENT_PASSWORD="Communication key, obtained from the service page"' >> ~/.zshrc
echo 'export HOMEBREW_NEZHA_AGENT_SERVER="Your server and port, format your.domain:5555 "' >> ~/.zshrc
source ~/.zshrc
DANGER
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!
Since it has not yet been submitted to the Homebrew Core official library, it is temporarily placed in the third-party Homebrew repository maintained by the author of the blog:
brew install brewforge/chinese/nezha-agent
brew services start nezha-agent
brew services info nezha-agent
brew services stop nezha-agent
brew rm nezha-agent
echo $HOMEBREW_NEZHA_AGENT_PASSWORD
echo $HOMEBREW_NEZHA_AGENT_SERVER
brew services stop nezha-agent
brew reinstall nezha-agent
brew services start nezha-agent
How to solve installation difficulties and issues in one step?
How to enable autostart on older OpenWRT/LEDE?
How to enable autostart on newer OpenWRT? Contributor: @艾斯德斯
/root
.chmod +x /root/nezha-agent
to grant execution permission, then create /etc/init.d/nezha-service
:#!/bin/sh /etc/rc.common
START=99
USE_PROCD=1
start_service() {
procd_open_instance
procd_set_param command /root/nezha-agent -s Dashboard communication domain:port -p Key -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
to grant execution permission./etc/init.d/nezha-service enable && /etc/init.d/nezha-service start
The Agent does not currently have a Docker image.
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.
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.