import{_ as s,o as n,c as a,R as l}from"./chunks/framework.1625126e.js";const h=JSON.parse('{"title":"","description":"","frontmatter":{},"headers":[],"relativePath":"en_US/guide/agent.md","filePath":"en_US/guide/agent.md","lastUpdated":1687756292000}'),o={name:"en_US/guide/agent.md"},e=l(`

The service in the monitored server is called Agent. This document will describe how to install the Agent on the monitored server and connect it with Dashboard

Install Agent using one-click script

Nezha Monitoring now supports one-click installation of the Agent on Windows and Linux. Follow the steps in this document and you can easily deploy it on your server

Preparation

First of all, you need to set up the communication domain name in the settings page of the admin panel, this domain name can not connect to the CDN, here is the sample communication domain name "data.example.com" mentioned earlier for demonstration
Enter the administration panel, go to the "Settings" page, in the item "CDN Bypassed Domain/IP ", fill in the communication domain name, and then click "Save"

One-click installation on Linux (Ubuntu, Debian, CentOS)

One-click installation on Windows

Other ways to install Agent


Installing Agent on Linux (Ubuntu, Debian, CentOS)

bash
curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install_en.sh  -o nezha.sh && chmod +x nezha.sh && sudo ./nezha.sh

Installing Agent on other Linux (such as alpine use oprec not systemd)

Contributed by unknown0054

shell
cat >/etc/init.d/nezha-agent<< EOF
#!/sbin/openrc-run
SERVER="" #Dashboard address ip:port
SECRET="" #SECRET
TLS="" # Enable tls?  yes:"--tls" 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/naiba/nezha/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/naiba/nezha/" | grep "option\\.value" | awk -F "'" '{print $2}' | sed 's/naiba\\/nezha@/v/g')
		fi
		if [ ! -n "$version" ]; then
			version=$(curl -m 10 -sL "https://gcore.jsdelivr.net/gh/naiba/nezha/" | grep "option\\.value" | awk -F "'" '{print $2}' | sed 's/naiba\\/nezha@/v/g')
		fi
		if [ ! -n "$version" ]; then
			echo -e "Failed to get the version number, please check if the network can connect to https://api.github.com/repos/naiba/nezha/releases/latest"
			return 0
		else
			echo -e "The current latest version is: \${version}"
		fi
		wget -t 2 -T 10 -O nezha-agent_linux_\${os_arch}.zip https://\${GITHUB_URL}/naiba/nezha/releases/download/\${version}/nezha-agent_linux_\${os_arch}.zip >/dev/null 2>&1
		if [[ $? != 0 ]]; then
			echo -e "Release download failed, please check if the network can connect to \${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

Installing Agent on Windows

Installing Agent on Synology DSM


Installing Agent on MacOS

This section is adapted from Mitsea Blog, with permission from the original author

WARNING

If you are prompted with "macOS cannot verify this app" during installation, please go to system settings to allow the app to run.

xml
<?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>Change the path of the Agent binary here, e.g. /Users/123/Downloads/nezha-agent</string>
	<key>ProgramArguments</key>
	<array>
		<string>Change the path of the Agent binary here, e.g. /Users/123/Downloads/nezha-agent</string>
		<string>--password</string>
		<string>Communication Secret, eg: 529664783eeb23cc25</string>
		<string>--server</string>
		<string>Communication URL and RPC port, eg:data.example.com:5555</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
</dict>
</plist>
shell
launchctl load /Users/123/Desktop/nezha_agent.plist
shell
launchctl start nezha_agent
shell
launchctl list | grep nezha_agent
shell
launchctl stop nezha_agent
shell
launchctl remove nezha_agent

Installing Agent on OpenWRT

How to solve various problems during the installation process in one step

How to make the old version of OpenWRT/LEDE self-boot?

How to make the new version of OpenWRT self-boot? By @艾斯德斯

shell
#!/bin/sh /etc/rc.common

START=99
USE_PROCD=1

start_service() {
 procd_open_instance
 procd_set_param command /root/nezha-agent -s data.example.com:5555 -p secreat -d
 procd_set_param respawn
 procd_close_instance
}

stop_service() {
    killall nezha-agent
}

restart() {
 stop
 sleep 2
 start
}

FAQ

Is there a Docker image for Agent?

There is currently no Docker image for Agent.
The Agent is designed to be the opposite of the Dashboard, in that the Dashboard is designed to work without affecting the server as much as possible, while the Agent needs to execute monitoring services and run commands in the server.
Putting the Agent in a container does continue to execute monitoring services, but features such as WebShell do not work, so we do not provide Docker image of the Agent.

`,52),p=[e];function t(r,c,i,D,y,C){return n(),a("div",null,p)}const u=s(o,[["render",t]]);export{h as __pageData,u as default};