debian 搭建家庭服务器过程记录

背景

最近入手了一台小主机,折腾了快一个月,记录一下过程。 主要需求

  • 旁路由/透明代理
  • 去广告
  • 手机照片同步备份
  • mac time machine 备份
  • 笔记、配置文件同步
  • 各种自建服务,rss

硬件配置

硬件没有研究,感觉性能应该是过剩的,买的比较随意

  • 主机: 天钡 WTR Pro,1350 rmbrmb
  • 机械硬盘:官换新盘希捷银河16T,1080 rmbrmb
  • SSD:光威 256G, 119 rmbrmb
  • 内存:英睿达 16G DDR4,210 rmbrmb

debian 安装

就是比较常规的系统安装,首先在官网 https://www.debian.org/releases/bookworm/releasenotes 下载 amd64 位版本镜像。(最开始选了minimal 版本,安装的时候从网络下载依赖,结果下了半天没下好,最后还是重新下载了 dvd 版本) 然后刻录到 U 盘,开机的使用 DEL 进入 bios, 选择从 U 盘启动。

透明代理

之前在路由器上刷了 openwrt , 但是最终感觉不稳定并且不想也不想折腾,又刷回了官方系统。 现在直接用 debian 作旁路由,将需要代理的设备网关地址改为 debian 的 ip,即可实现透明代理。

主要步骤

首先通过 ip a 查看设备网卡名,这里为 enp3s0,然后编辑 /etc/network/interfaces 文件,其中 gateway 是路由器 ip。

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

auto enp3s0
iface enp3s0 inet static
        address 192.168.6.16
        netmask 255.255.255.0
        gateway 192.168.6.1
	dns-nameservers 192.168.6.16

iface enp3s0 inet6 auto

接着重启网络服务 sudo systemctl restart networking.service。 最后编辑 /etc/sysctl.conf ,将 net.ipv4.ip_forward=1 取消注释,允许流量转发。 再执行 sudo sysctl -p 使配置生效。

singbox 配置

执行 bash <(curl -fsSL https://sing-box.app/deb-install.sh) 安装 sing-box。 然后在 /etc/sing-box 目录创建 config.json 文件,最后执行 sudo systemctl start sing-box.service

注意点:

  1. 开启 tun 模式会与 docker 网络冲突,开启 tun 后局域网无法访问 docker 端口,原因还未知,目前只能先 exclude docker0 网卡。
  2. stack 为 mixed 时,debian 机器无法访问外网,其他设备可以,改为 gvisor 解决。
  3. inbound 中监听 530 端口,作为 ADGuard Home 的上游 dns 服务器。

可以用 clash2sfa 将机场订阅链接结合下面模板,生成一份新的配置文件。

json
{
  "dns": {
    "disable_cache": false,
    "disable_expire": false,
    "final": "google",
    "independent_cache": false,
    "rules": [
      {
        "outbound": "any",
        "server": "default-dns"
      },
      {
        "query_type": "HTTPS",
        "server": "block-dns"
      },
      {
        "clash_mode": "direct",
        "server": "default-dns"
      },
      {
        "clash_mode": "global",
        "server": "google"
      },
      {
        "rule_set": "cnsite",
        "server": "default-dns"
      }
    ],
    "servers": [
      {
        "address": "223.5.5.5",
        "detour": "direct",
        "tag": "default-dns"
      },
      {
        "address": "local",
        "detour": "direct",
        "tag": "system-dns"
      },
      {
        "address": "rcode://name_error",
        "tag": "block-dns"
      },
      {
        "address": "https://dns.google/dns-query",
        "address_resolver": "default-dns",
        "address_strategy": "ipv4_only",
        "client_subnet": "1.0.1.0",
        "strategy": "ipv4_only",
        "tag": "google"
      }
    ],
    "strategy": "ipv4_only"
  },
  "experimental": {
    "cache_file": {
      "enabled": true
    },
    "clash_api": {
      "default_mode": "rule",
      "external_controller": "192.168.6.16:9090"
    }
  },
  "inbounds": [
    {
      "listen": "0.0.0.0",
      "listen_port": 530,
      "tag": "dns-in",
      "type": "direct"
    },
    {
      "auto_route": true,
      "exclude_interface": [
        "docker0"
      ],
      "gso": true,
      "inet4_address": "172.19.0.1/30",
      "mtu": 9000,
      "sniff": true,
      "sniff_override_destination": false,
      "stack": "gvisor",
      "strict_route": false,
      "tag": "tun-in",
      "type": "tun"
    }
  ],
  "log": {
    "disabled": true,
    "level": "trace",
    "output": "/etc/sing-box/singbox.log",
    "timestamp": true
  },
  "outbounds": [
    
  ],
  "route": {
    "auto_detect_interface": true,
    "rule_set": [
      {
        "download_detour": "direct",
        "format": "binary",
        "tag": "cnip",
        "type": "remote",
        "url": "https://github.com/MetaCubeX/meta-rules-dat/raw/sing/geo-lite/geoip/cn.srs"
      },
      {
        "download_detour": "direct",
        "format": "binary",
        "tag": "cnsite",
        "type": "remote",
        "url": "https://github.com/MetaCubeX/meta-rules-dat/raw/sing/geo-lite/geosite/cn.srs"
      }
    ],
    "rules": [
      {
        "inbound": "dns-in",
        "outbound": "dns-out"
      },
      {
        "outbound": "dns-out",
        "protocol": "dns"
      },
      {
        "outbound": "block",
        "protocol": "quic"
      },
      {
        "clash_mode": "direct",
        "outbound": "direct"
      },
      {
        "outbound": "direct",
        "rule_set": [
          "cnip",
          "cnsite"
        ]
      }
    ]
  }
}

配置完之后,将需要代理的设备,网关和 dns 设置成 debian 的 ip 即可进行透明代理。

docker 应用

这里主要记录最近折腾的一些 docker 容器

casaos

casaos 是一个家庭服务器管理面板,包含容器管理,文件管理/分享,服务器状态展示等功能。 我主要用来管理 docker 容器,以及发现一些好玩的镜像。 他的应用市场包含了很多镜像以及推荐配置,支持一键安装,并且能通过第三方市场安装更多镜像。

第三方市场入口比较隐蔽,一开始没找到,路径在 app store -> 右上角 x apps -> more apps -> 问号,可以把里面的三方市场链接都配置上。

AdGuard Home

用来去广告,network 为 bridge 时,似乎也会和 tun 模式冲突,导致无法查看 dns 记录。所以 network 改为 host 。 安装完之后将上游 dns 服务器改为本地 530 端口,配合 sing-box 使用。

Cloudflared

cloudflare tunnel 的客户端,用于内网穿透。原本是使用 cloudflare cdn 加 rules ,配合本地的 nginx 来进行公网访问,但是速度太慢。现在用 tunnel 快了很多。

rsshub + freshrss

rsshub 将不支持 rss 的内容转成 rss 格式,freshrss 管理 rss 订阅。 安卓上使用 FeedMe 作为阅读器。

WireGuard Easy

组网工具,用来在外面访问家里的服务。

immich+nextcloud

用 nextcloud 将手机照片同步到服务器,immich 用来浏览照片

Syncthing

用来在多个设备直接同步配置文件,obsidian 笔记等内容。

memos

记录一些短笔记,可以当做个人版微博。

在Android实现语音播报金额的功能
Valaxy v0.19.7 驱动 | 主题 - Yun v0.19.7