import{_ as s,c as i,o as a,a4 as n}from"./chunks/framework.BmdFiWrL.js";const c=JSON.parse('{"title":"Install Agent","description":"","frontmatter":{"outline":"deep"},"headers":[],"relativePath":"en_US/guide/agent.md","filePath":"en_US/guide/agent.md","lastUpdated":1719239024000}'),t={name:"en_US/guide/agent.md"},e=n(`
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
This section is contributed by unknown0054.
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
chmod +x /etc/init.d/nezha-agent
rc-service nezha-agent start
rc-update add 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 Mitsea Blog 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.
nezha_agent.plist
and save it with the following content:<?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>
launchctl load /Users/123/Desktop/nezha_agent.plist
launchctl start nezha_agent
launchctl list | grep nezha_agent
launchctl stop nezha_agent
launchctl remove nezha_agent
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.