From 1a884a5d75b02de4339c239bbe21a3eea3437422 Mon Sep 17 00:00:00 2001 From: ChowRex Date: Mon, 13 Feb 2023 15:33:41 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=BB=E5=A2=9E=E5=8A=A0=E7=BE=A4?= =?UTF-8?q?=E6=99=96DSM7=E4=BD=BF=E7=94=A8systemd=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E5=AE=89=E8=A3=85agent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加安装脚本, 实现修改变量执行安装nezha-agent --- docs/guide/agent.md | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/docs/guide/agent.md b/docs/guide/agent.md index 398b94a0..721d42f6 100644 --- a/docs/guide/agent.md +++ b/docs/guide/agent.md @@ -145,6 +145,54 @@ EOF - 请参考社区文章: [哪吒探针——群晖客户端(被控端)安装教程](https://wl.gta5pdx.cn/archives/546/) + +- Systemd实现 *仅适用于DSM7*: + ```sh + # 客户端路径 + EXEC="/PATH/TO/nezha-agent" + # 日志路径地址 + LOG="${EXEC}.log" + # 额外执行参数, 可留空 + ARGS="--disable-command-execute" + # 哪吒服务端GRPC地址 + SERVER="HOST_OR_IP:GRPC_PORT" + # 上一步获取的主机密钥 + SECRET="APP_SECRET" + # 服务运行用户名, *强烈建议使用非root用户执行* + RUN_USER="nezha" + + # 写入到systemd服务文件 + 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 + + # 重载服务 + systemctl daemon-reload + # 启动服务 + systemctl start nezha + # 服务自启动 + systemctl enable nezha + ``` + ‼️修改对应信息后‼️ + + ‼️修改对应信息后‼️ + + ‼️修改对应信息后‼️ + + 使用`root`账号执行上述命令即可安装完成 +
### 在 MacOS 中安装 Agent