Appearance
群晖安装哪吒agent
切到root
shell
sudo -i
设置变量
shell
# 客户端路径
EXEC="/volume2/docker/nezha/nezha-agent"
# 日志路径地址
LOG="${EXEC}.log"
# 额外执行参数, 可留空
ARGS="--disable-command-execute"
# 哪吒服务端gRPC地址
SERVER=""
# 上一步获取的主机密钥
SECRET=""
# 服务运行用户名, *强烈建议使用非root用户执行*
RUN_USER=""
写入到systemd服务文件
shell
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
重载服务
shell
systemctl daemon-reload
启动服务
shell
systemctl start nezha
服务自启动
shell
systemctl enable nezha