Files
42_105/README.md

147 lines
4.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CT105 — ip.lotimmy.com (echoip)
主機 `192.168.42.105`hostname `CT105`Ubuntu 24.04 LXC跑在 Proxmox 上。
對外提供一個 echoip 服務:回傳來訪者的 IP 與 GeoIP 資訊。
## 連線
設定在 `~/.ssh/config.d/timmy`,皆內建 `ProxyJump timmy_home_server`(遠端免打 `-J`)。
```sh
ssh ct105 # User: timmy
ssh ct105-root # User: root
```
內網直連(在 LAN 上時):`ssh 192.168.42.105`
- root 與 timmy 皆已裝公鑰(`~/.ssh/id_ecdsa.pub`),免密碼。
- sshd `PermitRootLogin without-password`root 僅允許金鑰登入,密碼登入關閉。
## 服務鏈路
```
https://ip.lotimmy.com
└─ Nginx Proxy Manager (Let's Encrypt 憑證, Public)
└─ http://192.168.42.105:8080 (echoip 容器)
```
- NPM 反代位置另一台主機NPM 管理介面proxy host `ip.lotimmy.com``http://192.168.42.105:8080`
- 反代帶 `X-Real-IP` 標頭echoip 以 `-H X-Real-IP` 信任之,故回傳的是真實外網 IP 而非反代內網 IP。
### 端點
| URL | 回傳 |
|-----|------|
| `https://ip.lotimmy.com` | 純文字 IP |
| `https://ip.lotimmy.com/json` | 完整 JSONIP + GeoIPcity/region/asn 等) |
## Docker 容器
兩個容器compose 檔在主機 `/opt` 下。
### echoip — `/opt/echoip/docker-compose.yml`
```yaml
services:
echoip:
image: mpolden/echoip
container_name: echoip
restart: unless-stopped
ports:
- "8080:8080"
volumes:
- /opt/geoip/GeoLite2-City.mmdb:/data/city.mmdb
- /opt/geoip/GeoLite2-ASN.mmdb:/data/asn.mmdb
command: -c /data/city.mmdb -a /data/asn.mmdb -H X-Real-IP
```
- GeoIP 資料庫掛載自 `/opt/geoip/`
- `/opt/echoip/` 另有 GeoLite2 原始壓縮檔與 `download_geolite2_databases.sh`(更新 GeoIP 用)。
### watchtower — `/opt/watchtower/docker-compose.yml`
```yaml
services:
watchtower:
container_name: watchtower
image: containrrr/watchtower
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: --cleanup --label-enable --interval 300
```
- 每 5 分鐘檢查、清舊 image**只更新有 `com.centurylinklabs.watchtower.enable=true` 標籤的容器**。
## 已知狀況
- ⚠️ watchtower 開了 `--label-enable`,但 echoip **沒貼** `com.centurylinklabs.watchtower.enable=true` 標籤,所以 echoip 不會被自動更新watchtower 目前沒管任何容器)。
要啟用自動更新,在 echoip 的 compose 加:
```yaml
labels:
- com.centurylinklabs.watchtower.enable=true
```
然後 `cd /opt/echoip && docker compose up -d`。
## Tailscaleheadscale 節點)
以 Docker 方式部署,結構比照 CT102`/Users/timmy/dev/42_102`),檔案在 `/opt/tailscale`。
| 項目 | 值 |
|------|-----|
| Tailscale IP | `100.64.0.16`hostname `ct105`user `mainnet`|
| 控制平面 | `https://headscale.lotimmy.com`headscale 容器在 CT126|
| Image | `tailscale/tailscale:latest``restart: unless-stopped` |
```yaml
# /opt/tailscale/docker-compose.yml
services:
tailscale:
image: tailscale/tailscale:latest
container_name: tailscale
hostname: ct105
restart: unless-stopped
network_mode: host
environment:
- TS_AUTHKEY=${TS_AUTHKEY}
- TS_EXTRA_ARGS=--login-server ${TS_LOGIN_SERVER} --reset
- TS_USERSPACE=true # 無 /dev/net/tun → userspace 模式
- TS_STATE_DIR=/var/lib/tailscale
- TS_HOSTNAME=ct105
volumes:
- ./state:/var/lib/tailscale
labels:
- "com.centurylinklabs.watchtower.enable=true"
```
`.env` 放 `TS_AUTHKEY`headscale reusable preauth key與 `TS_LOGIN_SERVER`。
常用:
```sh
docker exec tailscale tailscale status
docker exec tailscale tailscale ip -4
cd /opt/tailscale && docker compose up -d # 改設定後重建
```
### 與 CT102 的差異CT105 無 `/dev/net/tun`
CT105 是無 TUN 的 LXC故與 CT102 的版本不同:
- `TS_USERSPACE=true`、不掛 `/dev/net/tun`、無 `cap_add` / `privileged`。
- 拿掉 `--advertise-routes` / exit-nodeuserspace 模式做不到)。
- ⚠️ 副作用:其他節點能 ping、能看到 CT105但**無法直接連到 CT105 本機服務**(如 echoip `:8080`——userspace 模式不轉發入站到 localhost。
- 升級路徑要完整功能subnet router / exit node / 入站到本機服務須在母機PVE node替此 LXC 開 TUN再把 compose 改成 CT102 那版(`TS_USERSPACE=false` + 掛 `/dev/net/tun` + `cap_add` + `--advertise-routes`)。
### preauth key 來源
headscale 容器在 CT126用 CLI 產生(公開端點的 API token 已失效):
```sh
ssh ct126 'docker exec headscale headscale preauthkeys create --user 1 --reusable --ephemeral=false --expiration 87600h'
```
## 其他
- 本機服務sshd:22、Postfix僅 `127.0.0.1:25`、systemd-resolved本機 DNS。對外僅 echoip:8080。