在Claw Cloud上部署哪吒探针并持久化

在Claw Cloud上部署哪吒探针并持久化

本文是对奶昔论坛帖子的补充说明(原帖地址:https://forum.naixi.net/thread-3525-1-1.html


原帖摘录(供参考)

DLC(不推荐的操作)

打开 Nginx 容器的 terminal 并执行:

1
2
apt update
apt install curl wget unzip -y

用正常方式安装探针 agent,会出现如下结果:
原截图

——
实际问题
Claw Cloud 会不时重启导致数据丢失,且哪吒 v1 使用相同密钥、自动注册机制,探针随机失联或被注册机制识别为新机,导致面板出现机器错乱。


经过研究后可用的解决方案

1️⃣ 在 Claw Cloud 创建容器

  • 最低内存128 MiB

容器配置 10889

2️⃣ 挂载持久化硬盘

  • 挂载路径/opt/nezha

挂载路径 10890

3️⃣ 部署步骤

打开容器控制台,依次执行下面的命令。

3.1 安装依赖

1
2
apt update && apt install curl wget unzip ca-certificates -y

3.2 切换工作目录

1
2
cd /opt/nezha

3.3 下载探针二进制文件

1
2
wget -O nezha-agent.zip https://github.com/nezhahq/agent/releases/latest/download/nezha-agent_linux_amd64.zip

3.4 解压

1
2
unzip nezha-agent.zip

3.5 赋予执行权限

1
2
chmod +x nezha-agent

3.6 写入配置文件(config.yml

1
2
3
4
5
6
7
cat <<EOF > /opt/nezha/config.yml
server: 探针地址:端口
client_secret: 密钥
tls: false
debug: true
EOF

3.7 启动探针(后台运行)

1
2
nohup ./nezha-agent > agent.log 2>&1 &

检查:如果一切正常,面板上应出现机器上线的状态。


4️⃣ 创建容器自启动脚本

4.1 脚本内容(start.sh

1
2
3
4
5
6
7
8
9
10
11
cat <<'EOF' > /opt/nezha/start.sh
#!/bin/bash
if [ ! -f /opt/nezha/config.yml ]; then
echo "server: 探针地址:端口" > /opt/nezha/config.yml
echo "client_secret: 密钥" >> /opt/nezha/config.yml
echo "tls: false" >> /opt/nezha/config.yml
fi
/opt/nezha/nezha-agent > /opt/nezha/agent.log 2>&1 &
nginx -g 'daemon off;'
EOF

4.2 赋予执行权限

1
2
chmod +x /opt/nezha/start.sh


5️⃣ 在 Claw Cloud 的容器配置页面填写启动命令

在 Command 部分填写以下内容:

1
2
3
/bin/bash
/opt/nezha/start.sh

命令
界面截图