本帖最后由 charlzyx 于 2023-8-8 23:29 编辑
因为我软路由需求只有学英语, 所以没有采用常规的 iKuai + Op 主从路由配置, 而是使用了理论上讲更加绿色节能的 LXC 搭建了一个 clash 透明代理来处理. 机器配置如下:
因为不太会写 iptables 所以特别感谢以下开源项目! - tpclash TPClash 可以自动安装 Clash Premium/Meta, 并自动配置基于 Tun 的透明代理.
0# 虚拟机架构 & 路由规划
- 宿主机: PVE 119.119.119.120/24
- docker
- 虚拟机: iKuai 119.119.119.119 (作为网关)
- LXC <CT>: Debain 11 119.119.119.123/24 (使用 clash 作为透明代理服务器)
1# PVE 安装这个有很多现成的教程, 我贴几个参考吧
2# PVE 安装之后设置
2.1. 安装之后, 更新 apt 和 pve 源
- # 替换清华源, 注意一下 Debain 版本
- # apt 源 https://mirrors.tuna.tsinghua.edu.cn/help/debian/
- vim /etc/apt/sources.list
- # pve 源 https://mirrors.tuna.tsinghua.edu.cn/help/proxmox/
- vim /etc/apt/sources.list.d/pve-no-subscription.list
- apt update
复制代码 2.2. 安装 docker用处多多, 我直接装宿主机了 - # 官方教程 https://docs.docker.com/engine/install/debian/
- # 1. Update the apt package index and install packages to allow apt to use a repository over HTTPS:
- apt-get install ca-certificates curl gnupg
- # 2. Add Docker’s official GPG key:
- sudo install -m 0755 -d /etc/apt/keyrings
- curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
- sudo chmod a+r /etc/apt/keyrings/docker.gpg
- # 3. Use the following command to set up the repository:
- echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
- "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
- sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- # 4. Update the apt package index:
- sudo apt-get update
- # 5.To install the latest version, run:
- sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- # 6. Verify that the Docker Engine installation is successful by running the hello-world image:
- sudo docker run hello-world
- # docker 镜像加速 https://dockerproxy.com/docs
- # https://www.ioiox.com/archives/127.html
- # 写入配置
- echo "{ "registry-mirrors": [ "https://dockerproxy.com" ] }" >> /etc/docker/daemon.json
- # 配置完成需重载 daemon 并重启 docker
- sudo systemctl daemon-reload
- sudo systemctl restart docker
复制代码 3# iKuai
4# LXC <CT> 容器安装 Debain 11
Tips: 清华源支持 CT Templates 加速 可以使用如下命令修改: cp /usr/share/perl5/PVE/APLInfo.pm /usr/share/perl5/PVE/APLInfo.pm_backsed -i 's|http://download.proxmox.com|https://mirrors.tuna.tsinghua.edu.cn/proxmox|g' /usr/share/perl5/PVE/APLInfo.pm针对 /usr/share/perl5/PVE/APLInfo.pm 文件的修改,重启后生效。 1. 根据图示步骤点击下载对应 CT 模版
当然也可以使用 从URL下载 比如 Debain 11 使用清华源加速的地址是这样
https://mirrors.tuna.tsinghua.edu.cn/proxmox/images/system/debian-11-standard_11.7-1_amd64.tar.zst
2. 创建 LXC Debain 11
一定要去掉 无特权容器 的选择框, 因为下一步要使用的 clash 透明代理需要使用到 TUN 隧道转发, 需要提权
2.2. 选择刚才下载好的模版
2.3 磁盘给个 2G 足够了, 注意 PVE 8.0 版本磁盘在 UI 界面只能调大不能减少, 减少需要命令行还有风险, 所以考虑好大小
2.4 CPU 就看心情
2.5. 内存看心情, 这个后期可以随便调整, 可以先填大一点, 配置操作快一点
2.6. 防火墙记得去掉, IPv4 填写上面规划的 ip, 网关填写 iKuai ip, IPv6 跳过不理
2.7. DNS 默认值 -> 下一步 -> 完成
3. 配置 LXC Debain 系统3.1. 登录: 用户名 root, 密码就是刚才创建的时候填写的密码
3.2 第一步依然是更新 apt 源, 注意界面上的 Debain 版本要对应上https://mirrors.tuna.tsinghua.edu.cn/help/debian/3.3. 接下来的配置可以使用我这里的脚本 https://github.com/charlzyx/clash-for-linux.git 可以参考原始仓库操作, 也可以按照我的修改脚本来执行; - 你应该需要安装一下 git 和 curl apt install git curl
- clash-for-linux 下载airport订阅文件, 并转换成 clash 对应格式
- tpclash 一键创建 clash 透明代理
3.4. 创建工作目录 /etc/clash, 准备配置文件 /etc/clash.yaml (手动 or 自动)
3.5 安装 tpclash 可以直接参考 [color=var(--yq-ant-link-color)]https://github.com/mritd/tpclash 官方文档, 我的操作步骤如下
- # 下载二进制文件, 注意平台要对应
- wget https://github.com/mritd/tpclash/releases/download/v0.1.11/tpclash-premium-linux-amd64
- # 重命名, 非必须
- mv tpclash-premium-linux-amd64 tpclash
- # 添加可执行权限
- chmod ./tpclash
- # 执行安装
- ./tpclash install
复制代码
3.5 根据TPClash 文档的提示; 修改 /etc/systemd/resolve.conf, 添加下面 4 行进去
- # /etc/systemd/resolve.conf
- DNS=223.5.5.5
- DNS=119.29.29.29
- Domains=~.
- DNSStubListener=no
复制代码
之后 systemctl restart systemd-resolved
如果有看到 systemd-resolved.service: Main process exited, code=exited, status=226/NAMESPACE systemd-resolved.service: Failed with result 'exit-code'. 类似这样的报错,
请检查容器的 嵌套 功能是否开启
3.7. 第一次启动直接使用 tpclash 手动启动修改 /etc/clash.yaml 配置文件中的日志级别设置为 debug 来观察是否有报错
比方说这样就 TUN 隧道 开启失败 针对这个具体的问题, 可以这样: 打开宿主机 PVE 的控制台, 执行以下命令手动给 lxc 开启 tun, 修改之后重启当前容器 - cd /etc/pve/lxc && ls
- vim xxx.conf # xxx 为容器 id
- 在末尾添加如下配置
- lxc.cgroup.devices.allow: c 10:200 rwm
- lxc.cgroup2.devices.allow: c 10:200 rwm
- lxc.mount.entry: /dev/net dev/net none bind,create=dir
复制代码
重启之后 检查刚才报错的 /ev/net/tun 是否存在
3.8. 排除所有错误之后, 就可以安装 TPClash 成功提示操作 1. 开启自启动 2. 启动服务
- ? TPClash 安装完成, 您可以使用以下命令启动:
- - 启动服务: systemctl start tpclash
- - 停止服务: systemctl stop tpclash
- - 重启服务: systemctl restart tpclash
- - 开启自启动: systemctl enable tpclash
- - 关闭自启动: systemctl disable tpclash
- - 查看日志: journalctl -fu tpclash
- - 重载服务配置: systemctl daemon-reload
复制代码
验证一下 curl www.不存在的域名.com
3.9 验证, 参考 TPClash 官网
我们可以创建一个新的 CT 容器来验证是否可用
其他所有选项都可以用默认值, 只有在 ip 这里, 把网关配置为刚才透明代理 ip, 之后进入当前测试容器控制台 curl www. 不存在.com 即可验证
恭喜 ?! 至此, 透明 clash 代理 CT 容器配置完毕!
iKuai 配置, 网关指向clash 代理服务器即可
clash yacd 示意
第一次写教程, 欢迎讨论
顺便问一下最下面那个附件图是我传错了, 怎么删除
|