clawcloudrun-vps

[up主专用,视频内嵌代码贴在这]

1 Claw cloud 容器改造 VPS, 实现 SSH 远程登录

Claw cloud 注册地址:
https://console.run.claw.cloud/signin?link=2L5PAUQS0LNO
项目地址:
https://github.com/vevc/ubuntu

1.1容器特点

容器一般只运行一个前台进程(PID=1)
容器重启后,未挂载存储的数据会丢失
容器内部端口需要映射到外部,才可以访问

1.2家目录初始化

1.2.1、权限设置

1
2
ls -l /home
sudo chown -R $USER:$USER /home/$USER

1.2.2、终端字体颜色美化、ls -l 命令别名设置等

1
2
curl -sk -o ~/.bashrc https://raw.githubusercontent.com/vevc/ubuntu/refs/heads/main/.bashrc
curl -sk -o ~/.profile https://raw.githubusercontent.com/vevc/ubuntu/refs/heads/main/.profile

注意事项

需要长期保存的数据,请一定存放在用户家目录,重要数据定期备份
通过 apt install 安装的应用重启后会丢失(需要在构建镜像时安装)

1.2.3、Claw cloud 搭建 3x-ui xhttp 节点

3x-ui 项目地址:
https://github.com/MHSanaei/3x-ui
3x-ui 默认端口:2053
3x-ui 默认用户名/密码:admin/admin

2 Claw cloud 容器改造 VPS, 使用 supervisor 管理容器进程,实现应用开机自启、自动保活、cron 规则持久化

项目地址:
https://github.com/vevc/ubuntu

Supervisor 官网及项目地址:
https://supervisord.org
https://github.com/Supervisor/supervisor
进程管理工具选择

❌ systemctl: 宿主机一般不会给特权模式
✅ supervisor: 作为1号进程启动,管理其他进程,让容器拥有多进程自启、保活功能
改造前

2.1.1启动测试进程

1
2
3
sudo /usr/sbin/cron
nohup python3 -m http.server 8080 1>/dev/null 2>&1 &
ps aux

2.1.2添加一个定时任务

1
2
3
4
5
6
cat > /home/$USER/cron.sh << EOF
#!/usr/bin/env sh
date >> /home/$USER/cron.log
EOF
chmod +x /home/$USER/cron.sh
(crontab -l 2>/dev/null; echo "* * * * * /home/$USER/cron.sh") | crontab -

2.1.3、重启容器,cron 进程停止、http.server 服务进程停止、cron 定时任务规则丢失

改造

2.2.1、准备配置文件

1
mkdir ~/boot  # 家目录文件可持久化保存
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
cat > /home/$USER/boot/supervisord.conf << EOF
[supervisord]
nodaemon=true
logfile=/tmp/supervisord.log
logfile_maxbytes=5MB
logfile_backups=3
loglevel=info

[program:sshd]
command=/usr/sbin/sshd -D
autostart=true
autorestart=true

[program:cron]
command=/usr/sbin/cron -f
autostart=true
autorestart=true

[program:init]
command=/home/$USER/boot/init.sh
autostart=true
; init.sh 开机自启仅运行一次
autorestart=false
startretries=0
user=$USER

[program:http-server]
command=python3 -m http.server 8080
autostart=true
autorestart=true
user=$USER
EOF
1
2
3
4
5
cat > /home/$USER/boot/init.sh << EOF
#!/usr/bin/env sh
(crontab -l 2>/dev/null; echo "* * * * * /home/$USER/cron.sh") | crontab -
EOF
chmod +x /home/$USER/boot/init.sh

2.2.2、更新容器启动参数

Arguments: [“supervisord”, “-c”, “/home/town/boot/supervisord.conf”](注意路径中的用户名)
改造后

重启容器测试
kill 进程保活测试

常见问题

supervisord.conf 配置文件不小心写错怎么恢复
删除爪云里面的Arguments参数保存重启,再加上保存重启

3 Claw cloud 容器 vps 优雅重启,supervisorctl 管理工具的使用

项目地址:
https://github.com/vevc/ubuntu

Supervisor 官网及项目地址:
https://supervisord.org
https://github.com/Supervisor/supervisor
容器重启
Claw cloud 改造的 vps 怎么重启?

  1. Web 页面
  2. reboot

为什么容器 reboot 命令不生效?
容器共享宿主机的内核,它没有自己独立的内核可以重启。

解决方案
结合容器的重启策略:–restart=unless-stopped,关闭所有进程,模拟 reboot 命令。

1
kill -SIGTERM 1

这个命令在 ghcr.io/vevc/ubuntu:25.7.14 版本已集成到镜像里。
tag 更新说明
在 Claw cloud 上,latest 标签并不总是实时指向最新的镜像,可能存在缓存。
GitHub 样例命令已调整为实际版本号,后续保持更新。
应用重启

supervisorctl 重启应用
/home/town/boot/supervisord.conf
添加修改以下内容

1
2
3
4
5
[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
1
2
3
4
5
6
7
8
9
[program:init]
command=/home/town/boot/init.sh
autostart=true
startsecs=0
exitcodes=0
; init.sh 开机自启仅运行一次
autorestart=false
startretries=0
user=town

完整配置参考:https://github.com/vevc/ubuntu/blob/main/supervisord.sample.conf
supervisorctl 常用命令

1
2
3
4
5
6
sudo supervisorctl status
sudo supervisorctl restart cron
sudo supervisorctl update http-server
sudo supervisorctl help
sudo supervisorctl help stop
sudo supervisorctl # 交互模式

supervisorctl 别名配置

1
2
echo "alias sctl='sudo supervisorctl'" >> ~/.bashrc
source ~/.bashrc

4 Claw cloud 容器 VPS 安装 xray | 提取复用 3x-ui 配置,手动部署 xray 代理 | All in one 容器 VPS

3x-ui 包含 Xray-core
3x-ui 和 Xray-core 的职责 类似jdk jre jvm
3x-ui: 配置管理
Xray-core: 代理、流量转发
安装 xray

4.1. 下载 Xray-core

1
2
3
4
5
mkdir ~/xray
cd ~/xray
wget https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-64.zip
unzip Xray-linux-64.zip
rm -f Xray-linux-64.zip

4.2. 提取 3x-ui 配置

https://github.com/vevc/one-node/blob/main/claw-cloud/xray-config.json
使用 xray 检查配置文件是否正确
3. 使用 supervisor 管理 xray

[program:xray]
command=/home/town/xray/xray -c /home/town/xray/config.json
autostart=true
autorestart=true
user=town

sudo supervisorctl update xray

  1. 添加端口映射

5 Claw cloud 容器 VPS 安装 ttyd,在浏览器 web 页面登录和使用 ssh 终端

下载

1
2
3
4
mkdir ~/ttyd
cd ~/ttyd
wget -O ttyd https://github.com/tsl0922/ttyd/releases/latest/download/ttyd.x86_64
chmod +x ttyd

启动命令

1
~/ttyd/ttyd -p 7681 -c  town:Ts123** -W bash

使用 nohup 后台启动

1
nohup ~/ttyd/ttyd -p 7681 -c town:Ts123** -W bash 1>/dev/null 2>&1 &

使用 Supervisor 管理并启动

1
2
3
4
5
6
7
[program:ttyd]
environment=HOME="/home/town",USER="town",LOGNAME="town"
command=/home/town/ttyd/ttyd -p 7681 -c town:Ts123** -W bash
directory=/home/town
autostart=true
autorestart=true
user=town

免密登录小技巧
Basic Auth 鉴权

GET /private/index.html HTTP/1.1
Host: vevc.dpdns.org
Authorization: Basic YWRtaW46cGFzc3dvcmQ=

echo -n ‘admin:password’ | base64

URL 地址中的格式
https://town:Ts123**@xqqxogmsncut.us-east-1.clawcloudrun.com/

6 Claw cloud 容器 VPS 安装 Node.js 开发环境,搭建 Uptime Kuma 免费开源监控神器

博文地址:https://vevc.dpdns.org/archives/10.html

容器 VPS 项目地址:
https://github.com/vevc/ubuntu

Uptime Kuma 官网及项目地址:
https://uptime.kuma.pet
https://github.com/louislam/uptime-kuma

Node.js 官网:
https://nodejs.org

nvm 项目地址:
https://github.com/nvm-sh/nvm
Why

  1. 网站监控(节点监控)

  2. 定时请求保活
    Uptime Kuma, Node.js, nvm 的关系

  3. Uptime Kuma 项目使用 Node.js 语言开发,运行在 Node.js 环境中

  4. nvm (Node Version Manager): Node.js 的版本管理工具
    nvm 优点

  5. 方便安装最新版 Node.js, apt install 安装的版本老旧

  6. 多版本 Node.js 任意切换

  7. 安装的所有文件存放在用户家目录
    使用 Supervisor 管理并启动

[program:uptime-kuma]
environment=PATH=”/home/town/.nvm/versions/node/v20.x/bin:/usr/sbin:/usr/bin:/sbin:/bin”
directory=/home/town/uptime-kuma
command=node server/server.js
autostart=true
autorestart=true
user=town

Node.js Release info

https://nodejs.org/en/about/previous-releases