Skip to content

Tailscale组网和自建Headscale

第一步:在 VPS 上部署 Headscale (控制端)

docker-compose 一键拉起 Headscale。

  1. 准备目录

    bash
    mkdir -p /opt/headscale/config
    cd /opt/headscale
  2. 创建配置文件:先从官方下载一个默认配置,或者直接创建一个简化版。

    bash
    mkdir -p /opt/headscale/config
    cd /opt/headscale/config
    
    # 下载官方默认配置模板
    wget https://raw.githubusercontent.com/juanfont/headscale/main/config-example.yaml -O config.yaml
    
    # 快速修改几个关键参数(适配 1G 内存和公网访问)
    sed -i 's|server_url: http://127.0.0.1:8080|server_url: http://你的VPS公网IP:8080|g' config.yaml
    sed -i 's/listen_addr: 127.0.0.1:8080/listen_addr: 0.0.0.0:8080/g' config.yaml

    使用反向代理的话http://你的VPS公网IP:8080 -> https://xxx.xxx.xxx 就不需要带端口了

  3. 编写 docker-compose.yml

    YAML

     version: '3.8'
     services:
       headscale:
         image: docker.io/headscale/headscale:latest
         container_name: headscale
         restart: always
         volumes:
           - ./config:/etc/headscale
           - ./data:/var/lib/headscale
           - ./run:/var/run/headscale
         ports:
           - "30000:30000"
           - "39090:9090"
         environment:
           - TZ=UTC
         command: serve
  4. 启动docker-compose up -d

  5. 生成 API Key:docker exec headscale headscale apikeys create --expiration 365d 记下生成的这一串字符。

  6. 创建一个网络用户:docker exec headscale headscale users create reinffy-net

第二步:在 VPS 上部署 本体

bash
# 下载安装脚本
curl -fsSL https://tailscale.com/install.sh | sh

# 启动并连接到你自己的 Headscale SSL证书必须能够信任
tailscale up --login-server https://hs.reinffy.cc --accept-dns=false

# 执行这条带参数的命令
TS_DEBUG_OMIT_LOCAL_CA_CERT=true tailscale up --login-server https://hs.reinffy.cc --accept-dns=false --force-reauth