有关的文章:
<QNAP 453D QTS-5.x> 日志记录:Cloudflare tunnels ( 也叫: Argo Tunnel )实践, 网络加速 应用/服务公网访问-优快云博客
< OS 有关 > 阿里云:轻量应用服务器 的使用 安装 Tailscale 后DNS 出错, 修复并替换 apt 数据源_tailscale会更改dns吗-优快云博客
目标:
在阿里 vps 创建 Cloudflared 隧道,让 9000 端口的 web 服务可以被正常访问。
Cloudflared tunnel 优点:
它是出站连接,通过 HTTPS(443端口)建立连接,无需在防火墙上开放额外入站端口。
实践过程
所有操作需要在 vps 与 cloudflare.com 中执行
1. 确定当前 Cloudflared 版本
cloudflared version
如果有安装,会返回“版本号”,要检查 Cloudflared 有关配置,再继续。这篇文章描述的是从未有安装的环境。
2. 下载并安装 Cloudflared
curl -L --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
dpkg -i cloudflared.deb
验证安装
3. 配置 Argo Tunnel
1) 让 vpn 登录 Cloudflare
cloudflared tunnel login
把屏幕上提示的 url 复制到浏览器,在账号中激活,成功后如下:
2) 创建名为 myalitunnel 的隧道
cloudflared tunnel create myalitunnel
3) 创建 config.yml 配置文件
vi ~/.cloudflared/config.yml
内容:(根据自己情况修改) 应用本机的 web 9000 端口
tunnel: c47e<你的 tunnel id>26dbc
credentials-file: /root/.cloudflared/c47e85d<你的 tunnel id>26dbc.json
ingress:
- hostname: js.<你的域名如 cctv.cao>
service: http://localhost:9000
- service: http_status:404
上面有注释,再提一下,在哪儿可以看到 "你的 tunnel ID": Cloudflare 控制台,或上面第二行系统创建的 json 文件的文件名。
4) 启动新建的 myalitunnel 隧道
cloudflared tunnel run myalitunnel
5) 配置自启动运行
a. 安装服务
cloudflared service install
b. 启动并设置开机自启
cloudflared service install
systemctl enable cloudflared
c. 检看 cloudflared 状态
systemctl status cloudflared
e. 在 cloudflare 控制台查看:
因是命令行创建,第一行会有提示
6) 添加 cloudflared CNAME 记录 (DNS)
cloudflared tunnel route dns c47ee<你的 tunnel id>26dbc js.cctv.cao(在 Internet 上需要服务的 DNS 名)
在 Cloudflared 控制台,可以看到一条新的 桔色云朵 DNS 记录
结束:
应用 cloudflared tunnel ( Argo Tunnel )优点:
- 自带 SSL 无需申请。
- 不需要开放入站端口。
- 绕过防火墙的限制。
- 介绍里写到 argo tunnel 可以有多个源服务器,可做负载均衡与高可用。(付费版功能)
缺点:
- 隧道技术 Tunnel 会增加延时。
- 免费版也是有流量限制的。
- 配置上稍微复杂。