Unraid基于Docker实现内置科学上网

由于 Unraid 的商店、插件需要访问外网,而其并没有提供一个像 Windows 一样足够方便的代理地址配置。为了解决这个问题,我在网络上进行了大量搜索(配置好后有好一段时间了,一直忙没时间写博客,结果现在忘了参考来源了 QAQ)

Unraid /boot/config/go 脚本配置

由于 Unraid 好像不会持久化 linux 的大部分目录 (参考信息),因此有必要把代理配置过程在开机的时候给自动化部署,但这就导致 Unraid 的代理配置除了重启外无法更新。

/boot/config/go 文件开头添加以下内容:

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
33
34
35
36
37
38
39
40
41
#!/bin/bash

# Set up system proxy
proxy_host=127.0.0.1
proxy_port=7890

export http_proxy=http://$proxy_host:$proxy_port
export {https,ftp,rsync,all}_proxy=$http_proxy \
{HTTP,HTTPS,FTP,RSYNC,ALL}_PROXY=$http_proxy

cat >>/root/.bash_profile << __EOF__
export {http,https,ftp,rsync,all}_proxy=$http_proxy \
{HTTP,HTTPS,FTP,RSYNC,ALL}_PROXY=$http_proxy
__EOF__

cat >> /root/.wgetrc << __EOF__
use_proxy=yes
http_proxy=$http_proxy
https_proxy=$http_proxy
wait=10
__EOF__

mkdir /boot/config/plugins/community.applications
cat > /boot/config/plugins/community.applications/proxy.cfg << __EOF__
port=$proxy_port
tunnel=1
proxy=http://$proxy_host
__EOF__

# Set up docker proxy
mkdir /etc/docker
cat >> /etc/docker/daemon.json <<__EOF__
{
"proxies": {
"http-proxy": "$http_proxy",
"https-proxy": "$http_proxy"
}
}
__EOF__

# Set up unraider ...

这个配置中的代理地址在我们部署完 Docker 前,可以先用与 Unraid 处于同一个局域网下的电脑开放代理端口给 LAN 访问的方式临时提供代理服务,以方便插件和 docker 的安装。

而在代理容器配置好之后,则只需要修改 proxy_host 到 127.0.0.1,端口设置为容器代理端口即可 = ̄ω ̄=

科学上网容器配置

这里顺便提供一下我自己的 compose.yaml,由于网上如何使用 docker 部署科学上网客户端的教程很多,因此这里不再赘述(其实就是懒)(什么,怎么配置 docker?,懒得写喵

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# compose.yaml
services:
# 这里顺便部署一个web前端,方便修改服务器代理配置。地址 http://<server_ip>:6780
metacubexd:
container_name: metacubexd
image: ghcr.io/metacubex/metacubexd
network_mode: bridge
restart: unless-stopped
ports:
- '6780:80'

meta:
container_name: meta
image: metacubex/mihomo:Alpha
restart: unless-stopped
pid: host
ipc: host
network_mode: host
cap_add:
- ALL
volumes:
- ./config:/root/.config/mihomo
- /dev/net/tun:/dev/net/tun

更多信息可以参考这里的内容: https://github.com/MetaCubeX/metacubexd/discussions/638


Unraid基于Docker实现内置科学上网
https://blog.jsesnr.top/posts/6c526f3a/
作者
Jesse Senior
发布于
2024年7月3日
许可协议