利用clawcloud部署frp服务


目录
  1. 1. clawcloud run云端设置
  2. 2. 客户端设置
  3. 3. frpc持久运行
  4. 4. 外部访问

clawcloud网站可用来部署应用,每月有5美元的免费额度。本文记录了部署frp服务端的过程及踩的坑。

clawcloud run云端设置

官方网站:https://run.claw.cloud/
使用 AI 构建、云部署,CLAWCLOUD Run 降低了技术堆栈的复杂性。从编码到生产,只需点击几下。


用github帐号登入,
免费额度:


App Store里面有很多应用,可直接添加,如alist,frp等。

添加frp,这是打开一个docker容器,frp是运行在容器中,



这里标红的地方是容器内7000端口穿透出来的端口,后面客户端从外界连接需要使用。
打开应用,


点击Manage Network,进去之后是容器内部端口的访问地址,可以给80端口设定自定义域名。

在自己的域名商处建立CNAME指向系统给的地址,注意cloudflare域名要取消代理,选仅DNS。
这里有坑,本来自动生成的地址是https的,自定义后就变成了http,不知道是不是故意的。
往下拉,是frps设置,

点进去,编辑frps.toml内容:

修改内容见下面的例子。完成后确认。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# frps.toml

bindPort = 7000
vhostHTTPPort = 80
#添加的内容
auth.method = "token"
auth.token = "xxxxxxx"
#------------
# The default value is 127.0.0.1. Change it to 0.0.0.0 when you want to access it from a public network.
webServer.addr = "0.0.0.0"
webServer.port = 7500
# dashboard's username and password are both optional
webServer.user = "admin"
webServer.password = "123456"

enablePrometheus = true

此处的token要与客户端的设置一致。
webServer.user = “admin”
webServer.password = “123456”是从7500端口访问面板的帐号。
此处有更改的话,需点右上方update,再restart项目。

客户端设置

  • 下载客户端
    本地主机是玩客云,在https://github.com/fatedier/frp/releases,选择arm hf。可能需要梯子。
    主要文件是4个,frpc,frpc.toml,frps,frps.toml,前两个是客户端及设置文件,后两个是服务端。这里用的是前两个文件。
    编辑frpc.toml:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    # frpc.toml
    serverAddr = "自定义域名或系统给的地址"
    serverPort = 32385
    auth.method = "token"
    auth.token = "xxxxxxxx"

    [[proxies]]
    name = "img"
    type = "http"
    localIP = "192.168.0.2"
    localPort = 80
    customDomains = ["自定义域名"]
    [[proxies]]
    name = "navidrom"
    type = "tcp"
    localIP = "192.168.0.2"
    localPort = 4533
    remotePort = 6000
    32385是容器穿透的端口,每个例子对应的不一样,刚建项目的时候会显示,也可以从App Launchpad进入,在应用列表里,点name处打开应用,例如显示frp-xxxxx的,点标红处,页面拉到最下方。

    token与前文服务端一致,是自己设定的。
    proxies部分是穿透设置。
    例子里是穿了两个端口,
本地端口 远程端口 穿透类型
80 80 http
4533 6000 tcp

指定http类需要customDomains,指定tcp类需要remotePort,对应需要在服务端添加6000端口,并生成一个外部访问地址。
如果要从外部指定端口连接客户端,只能穿透22端口。比如ssh连接。
remotePort需要在服务器端增加出口。

  • 运行:
    ./frpc -c ./frpc.toml
    会显示连接进程。成功的话就穿透成功。昨天折腾的时候由于玩客云上安装了adguardhome,导致与服务器连接不上,折腾了好久。在windows上一试又可以,才发现是玩客云上adguardhome的锅,删了就好了。
    从clawcloud给的7500端口地址进入面板,显示连接信息。

云端服务使用的镜像snowdreamtech/frps:0.59,CPU限制0.1核心,内存限制128M,个人使用应该可以。
容器版本可以更新至最新版本0.62。

frpc持久运行

直接运行,在退出ssh时就会退出。
有多种方法可以保持运行。

  • tmux
    打开tmux命令,在里面运行./frpc -c ./frpc.toml,在按ctrl B,D退出,tmux会保持运行。下次进入使用tmux attach -t 0
  • systemd服务
    主机是玩客云,支持systemd。
    在/etc/systemd/system/下建立frpc.service文件,内容如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [Unit]
    Description=frpc

    [Service]
    ExecStart=/root/frp/frpc -c /root/frp/frpc.toml
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s TERM $MAINPID
    Restart=always

    [Install]
    WantedBy=default.target
    此处frp文件在/root/frp目录,如果不同,做相应改动。
    打开服务:
    1
    2
    systemctl enable frpc
    systemctl start frpc
    查看状态:
    systemctl status frpc
    正常显示如下:

    出错的话,修改service文件,
    1
    2
    systemctl  daemon-reload
    systemctl restart frpc
    先要确保frpc命令能正常连接。

外部访问

由系统生成对应端口的访问地址,7500对应的是面板地址,其他端口是穿透后从外部访问的地址,直接使用就可以,还是https连接。自定义域名会变成http连接。
https://frp-ekssprzl.ap-northeast-1.clawcloudrun.com 类似这样的,有点长,暂时国内可以直接访问,无需自定义域名。
8181
https://yflkngrorbsa.ap-northeast-1.clawcloudrun.com
5230
https://dtlfgygpbbue.ap-northeast-1.clawcloudrun.com
5244
https://keojrxujkccp.ap-northeast-1.clawcloudrun.com
8124
https://juzfkhyjvapr.ap-northeast-1.clawcloudrun.com