本帖最后由 sires 于 2024-4-25 20:39 编辑
一、序言
PVE LXC容器效率高,占用资源小, 利用Alpine模版大小只有5M大小,完全安装sing-box、Mosdns、AdguardHome 后,占用空间160M左右, 内存分配128-256随意。
主要参考了 :
charlzyx
https://charlzyx.github.io/boom/0x06clash.html
https://www.right.com.cn/forum/thread-8303306-1-1.html
但也有些坑,留作记录吧。
两点小遗憾:
1、Alpine LXC 始终没有成功打开 sing-box 的TUN模式,估计Clash也一样不行,有高手请指导。
2、(这个解决了)因为是All IN 一个LXC, 无法本机代理, 下载一些插件和附件会被墙,办法就是其他主机docker建一个文件服务器
#创建一个docker 本地服务器 拉取文件用
4月3日 更新 改思路了,还是 sing-box + AdguardHome 吧, mosdns的分流 sing-box 已经集成的很好了。 参考
二、创建:Alpine LXC 容器。
PVE里有模版,直接拉取就行, 注意 1、要去掉无特权的 勾 ,2、不选安装防火墙 3、直接设置固定IP 记得 ip/24,网关可以先指向代理方便下载一些插件,后面可以改。
4月4日,补充 优化了DNS.json 见 32楼
https://www.right.com.cn/forum/forum.php?mod=redirect&goto=findpost&ptid=8358866&pid=20118588
三、准备 Alpine
#1、登录
root 密码是创建lxc设置的密码
#2、安装必要依赖
apk update apk add curl nftables iptables iproutes ip6tables openssh-server openssh vim
#3、#开启SSHD 方便连接和文件传输 apk add openssh-server #上一步已经安装过 # 开放Root登录 echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config #重启服务 rc-service sshd start # 设置开机启动 rc-update add sshd # 删除开机启动服务 不需 # rc-update del sshd
#4、开启流量转发 弄不弄都可以
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf echo "net.ipv6.conf.all.forwarding" >> /etc/sysctl.conf # 使修改生效 sysctl -p
#5、#PVE Apline 开启 Tun 网卡
这个始终没有打开sing-box tun模式,但是这步打开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 # PVE < 7.0 lxc.mount.entry: /dev/net dev/net none bind,create=dir
四、安装sing-box
用ShellCrash安装
一键脚本:
export url='https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master' && sh -c "$(curl -kfsSl $url/install.sh)" && source /etc/profile &> /dev/null
几点注意:
1、不要急着启动,第一步先下载sing-box核心,确定核心才能设置其他选项,我选的sing-box基础核心。 2、无法使用Tun模式, 我用的Tproxy模式。 3、关于基础DNS部分 ,不要指向 MOSDNS 会回流锁死内存。 4、要禁用 DNS 劫持。
五、安装 AdguardHome
一键脚本 "curl -s -S -L https://mirror.ghproxy.com/https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh -s -- -v"
curl -sSL https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh
chmod +x /etc/AdGuardHome/AdGuardHome /etc/AdGuardHome/AdGuardHome -s install
/etc/AdGuardHome/AdGuardHome -s start
rc-update add AdGuardHome
六、安装 Mosdns
# 创建 /etc/mosdns 工作目录 mkdir -p /etc/mosdns && cd /etc/mosdns unzip mosdns-linux-amd64.zip
#拉取 相关集合
mkdir -p /etc/mosdns/rule touch /etc/mosdns/rule/force-nocn.txt && \ touch /etc/mosdns/rule/hosts.txt && \ touch /etc/mosdns/rule/fake-ip-cidr.txt && \ touch /etc/mosdns/rule/force-cn.txt
配置 :/etc/mosdns/config.yaml
log:
level: error # debug
#file: "./log/mosdns.log" # 记录日志到文件。
production: true
# API 入口设置
api:
http: "0.0.0.0:9080" # 在该地址启动 api 接口。
# 从其他配置文件载入 plugins 插件设置。
# include 的插件会比本配置文件中的插件先初始化。
include: []
plugins:
- tag: "geosite-cn"
type: domain_set
args:
files:
- "./rule/direct-list.txt"
- "./rule/apple-cn.txt"
- "./rule/google-cn.txt"
- tag: "geosite-nocn"
type: domain_set
args:
files:
- "./rule/proxy-list.txt"
- "./rule/gfw.txt"
- tag: "geoip-cn"
type: ip_set
args:
files: "./rule/CN-ip-cidr.txt"
- tag: "fake-ip-clash"
type: ip_set
args:
files: "./rule/fake-ip-cidr.txt"
- tag: "force-cn"
type: domain_set
args:
files: "./rule/force-cn.txt"
- tag: "force-nocn"
type: domain_set
args:
files: "./rule/force-nocn.txt"
- tag: "hosts"
type: hosts
args:
files: "./rule/hosts.txt"
- tag: "cache"
type: "cache"
args:
size: 1024
lazy_cache_ttl: 0
dump_file: ./cache.dump
dump_interval: 600
# 转发至本地服务器的插件
- tag: forward_local
type: forward
args:
concurrent: 2
upstreams:
- addr: "https://dns.alidns.com/dns-query"
- addr: "tls://dns.alidns.com"
#- addr: "https://1.12.12.12/dns-query"
#- addr: "https://120.53.53.53/dns-query"
# 转发至远程服务器的插件
- tag: forward_remote
type: forward
args:
concurrent: 2
upstreams:
- addr: 127.0.0.1:1053 # 1053 是sing-box 监听的端口,如果不在同一主机 改为sing-box主机地址
# - addr: "https://cloudflare-dns.com/dns-query"
# - addr: "tls://1dot1dot1dot1.cloudflare-dns.com"
# - addr: "https://dns.google/dns-query"
# - addr: "tls://dns.google"
- tag: "primary_forward"
type: sequence
args:
- exec: $forward_local
- exec: ttl 60-3600
- matches:
- "!resp_ip $geoip-cn"
- "has_resp"
exec: drop_resp
- tag: "secondary_forward"
type: sequence
args:
- exec: prefer_ipv4
- exec: $forward_remote
- matches:
- rcode 2
exec: $forward_local
- exec: ttl 300-3600
- tag: "final_forward"
type: fallback
args:
primary: primary_forward
secondary: secondary_forward
threshold: 150
always_standby: true
- tag: main_sequence
type: sequence
args:
- exec: $hosts
- exec: query_summary hosts
- matches: has_wanted_ans
exec: accept
- exec: $cache
- exec: query_summary cache
- matches: has_wanted_ans
exec: accept
- exec: query_summary qtype65
- matches:
- qtype 65
# exec: black_hole 127.0.0.1 ::1 0.0.0.0
exec: reject 0
- matches:
- qname $geosite-cn
exec: $forward_local
- exec: query_summary geosite-cn
- matches: has_wanted_ans
exec: accept
- matches:
- qname $force-cn
exec: $forward_local
- exec: query_summary force-cn
- matches: has_wanted_ans
exec: accept
- matches:
- qname $geosite-nocn
exec: $forward_remote
- exec: query_summary geosite-nocn
- matches: has_wanted_ans
exec: accept
- matches:
- qname $force-nocn
exec: $forward_remote
- exec: query_summary force-nocn
- matches: has_wanted_ans
exec: accept
- exec: $final_forward
- tag: "udp_server"
type: "udp_server"
args:
entry: main_sequence
listen: 0.0.0.0:5233 #监听的dns端口 自定义 确定AdguardHome 上游指向这个端口
- tag: "tcp_server"
type: "tcp_server"
args:
entry: main_sequence
listen: 0.0.0.0:5233 #监听的dns端口 自定义
七、以上在同一alpine LXC主机 需要不同IP主机或 LXC 部署的可以更改相关配置文件中指向不同IP地址 (主要是127.0.0.1 或 0.0.0.0)。 唯一遗憾 Tun模式打不开,有高手还请指导。
|