Сборка: добавить production packaging flow через .deb
Добавлен package-режим в tools/build.sh: --package, --dist-dir, --version. Реализована сборка Debian-пакета, metadata/control, postinst/postrm и SHA256SUMS. Установочные пути унифицированы под /usr/sbin и /lib/systemd/system для production-модели.
This commit is contained in:
@@ -115,3 +115,17 @@
|
||||
- [ ] Известно, как остановить `awg2-harness.service`.
|
||||
- [ ] Известно, как вернуть `amnezia-tc.service` и `amnezia-tc-watcher.service`.
|
||||
- [ ] Rollback проверен на тестовом сервере.
|
||||
|
||||
## K. Packaging / release
|
||||
|
||||
- [ ] Package собирается на отдельной Debian 13 amd64 build-machine.
|
||||
- [ ] Production host не требует Rust/cargo/source tree.
|
||||
- [ ] `./tools/build.sh --package` создаёт `dist/awg2-harness_<version>_amd64.deb`.
|
||||
- [ ] `dist/SHA256SUMS` валидирует checksum пакета.
|
||||
- [ ] Пакет ставит бинарь в `/usr/sbin/awg2-harness`.
|
||||
- [ ] Пакет ставит unit в `/lib/systemd/system/awg2-harness.service`.
|
||||
- [ ] Пакет не устанавливает `/etc/awg2-harness/config.toml` автоматически.
|
||||
- [ ] Пакет не включает/не стартует сервис автоматически.
|
||||
- [ ] `apt install ./awg2-harness_<version>_amd64.deb` проходит на clean Debian 13 Amnezia host.
|
||||
- [ ] После ручной установки config `awg2-harness validate-config` проходит.
|
||||
- [ ] Сервис стартует только после явного `systemctl enable --now awg2-harness.service`.
|
||||
|
||||
@@ -26,7 +26,7 @@ It does not replace Amnezia. It controls the surrounding system state that the o
|
||||
One systemd service runs:
|
||||
|
||||
```bash
|
||||
/usr/local/bin/awg2-harness daemon --config /etc/awg2-harness/config.toml
|
||||
/usr/sbin/awg2-harness daemon --config /etc/awg2-harness/config.toml
|
||||
```
|
||||
|
||||
The daemon starts as root and keeps running. On startup it performs initial reconcile. During runtime it reacts to Docker events and also runs a periodic reconcile loop.
|
||||
@@ -311,7 +311,7 @@ table inet awg2_harness {
|
||||
|
||||
Target namespace: the same Amnezia network namespace where `tc` shaping is applied. Do not assume the initial host namespace sees original peer source addresses. If Amnezia performs NAT inside the container namespace, the host Docker bridge may only see the container address, not `10.8.1.x`.
|
||||
|
||||
Default threshold: `200` concurrent flows per peer IP. `250` is the conservative compatibility setting if there are complaints from unusually connection-heavy WebSocket/WebRTC/trading-browser workloads. `150` is more aggressive and should only be used after real traffic observation.
|
||||
Default threshold: `100` concurrent flows per peer IP. `150` is the conservative compatibility setting if there are complaints from unusually connection-heavy WebSocket/WebRTC/trading-browser workloads. `70` is more aggressive and should only be used after real traffic observation.
|
||||
|
||||
Rule placement: use `forward` hook with priority `filter` or any priority after conntrack lookup. Restrict evaluation to `ct state new` so established flows continue normally and only new flow attempts beyond the threshold are dropped.
|
||||
|
||||
|
||||
+37
-120
@@ -1,156 +1,73 @@
|
||||
# Установка AWG2 Harness на production-хост
|
||||
# Installation
|
||||
|
||||
## 1. Предусловия
|
||||
## Deployment contract
|
||||
|
||||
Хост:
|
||||
- Build выполняется на отдельной Debian 13 amd64 build-machine.
|
||||
- Production-хост получает готовый Debian-пакет.
|
||||
- На production-хосте не требуются Rust/cargo/source tree.
|
||||
- Amnezia должна быть уже установлена и работать через Docker.
|
||||
- Production-конфиг создаётся вручную; [`config.example.toml`](../config.example.toml) не копируется автоматически как боевой конфиг.
|
||||
|
||||
- Debian 13 amd64;
|
||||
- root-доступ;
|
||||
- SSH настроен заранее;
|
||||
- AmneziaWG/AWG 2.0 установлена официальным способом;
|
||||
- контейнер Amnezia запускается через Docker;
|
||||
- сервер выделенный, без соседних сервисов, чьи сетевые правила нужно сохранять.
|
||||
## A. Build machine
|
||||
|
||||
На хосте должны быть доступны:
|
||||
|
||||
```bash
|
||||
docker
|
||||
systemctl
|
||||
ip
|
||||
tc
|
||||
wg
|
||||
nsenter
|
||||
modprobe
|
||||
nft
|
||||
```
|
||||
|
||||
`tc/ip/wg` внутри контейнера полезны для fallback, но целевая модель — host tools + вход в network namespace контейнера.
|
||||
|
||||
## 2. Сборка бинаря
|
||||
|
||||
Сборку лучше выполнять на отдельной build-машине с тем же целевым ABI.
|
||||
### A1. Подготовка build environment
|
||||
|
||||
```bash
|
||||
./tools/build.sh --prepare-build-env --bootstrap-rust --yes
|
||||
./tools/build.sh
|
||||
```
|
||||
|
||||
Альтернатива (ручной запуск cargo из корня репозитория):
|
||||
### A2. Build и тесты
|
||||
|
||||
```bash
|
||||
cargo build --locked --manifest-path traffic_core/Cargo.toml --release
|
||||
./tools/build.sh --build
|
||||
```
|
||||
|
||||
Проверки перед переносом:
|
||||
### A3. Сборка пакета
|
||||
|
||||
```bash
|
||||
cargo fmt --manifest-path traffic_core/Cargo.toml --all --check
|
||||
cargo clippy --locked --manifest-path traffic_core/Cargo.toml --all-targets -- -D warnings
|
||||
cargo test --locked --manifest-path traffic_core/Cargo.toml --release
|
||||
file traffic_core/target/release/awg2-harness
|
||||
ldd traffic_core/target/release/awg2-harness
|
||||
./tools/build.sh --package
|
||||
sha256sum -c dist/SHA256SUMS
|
||||
```
|
||||
|
||||
## 3. Установка файлов
|
||||
## B. Transfer artifacts
|
||||
|
||||
```bash
|
||||
scp dist/awg2-harness_*_amd64.deb root@vpn-host:/root/
|
||||
scp config.toml root@vpn-host:/root/awg2-harness.config.toml
|
||||
```
|
||||
|
||||
## C. Production host
|
||||
|
||||
### C1. Install package
|
||||
|
||||
```bash
|
||||
apt install ./awg2-harness_*_amd64.deb
|
||||
```
|
||||
|
||||
### C2. Install config
|
||||
|
||||
```bash
|
||||
install -m 0755 traffic_core/target/release/awg2-harness /usr/local/bin/awg2-harness
|
||||
install -d -m 0755 /etc/awg2-harness
|
||||
install -m 0644 config.toml /etc/awg2-harness/config.toml
|
||||
install -m 0644 /root/awg2-harness.config.toml /etc/awg2-harness/config.toml
|
||||
```
|
||||
|
||||
Важно: production-установка **не должна** автоматически копировать [`config.example.toml`](../config.example.toml) как боевой конфиг.
|
||||
Если используется [`tools/build.sh`](../tools/build.sh), режим `--install` завершится ошибкой при отсутствии `/etc/awg2-harness/config.toml`.
|
||||
Режим `--install` копирует только бинарь и unit, выполняет `systemctl daemon-reload`, но не делает `systemctl enable --now`.
|
||||
Сначала подготовьте осознанный production-конфиг вручную.
|
||||
|
||||
Проверка конфига:
|
||||
### C3. Validate and apply
|
||||
|
||||
```bash
|
||||
awg2-harness validate-config --config /etc/awg2-harness/config.toml
|
||||
```
|
||||
|
||||
## 4. Первичное применение traffic topology
|
||||
|
||||
```bash
|
||||
awg2-harness apply-limits --config /etc/awg2-harness/config.toml
|
||||
awg2-harness apply-firewall --config /etc/awg2-harness/config.toml
|
||||
awg2-harness status --config /etc/awg2-harness/config.toml
|
||||
```
|
||||
|
||||
Ожидается:
|
||||
|
||||
- найден контейнер `amnezia-awg2` или `amnezia-awg`;
|
||||
- найден network namespace контейнера;
|
||||
- найден AWG/WG-интерфейс;
|
||||
- найдены peers из `wg show all allowed-ips`;
|
||||
- создана egress topology на AWG/WG-интерфейсе;
|
||||
- создан `ifb0`;
|
||||
- создан ingress redirect в `ifb0`;
|
||||
- на каждого peer есть egress и ingress class/filter;
|
||||
- если anti-torrent включён, в Amnezia netns есть `table inet awg2_harness` и drop counter отображается в status.
|
||||
|
||||
## 5. Настройка swap
|
||||
### C4. Enable daemon
|
||||
|
||||
```bash
|
||||
awg2-harness ensure-swap --config /etc/awg2-harness/config.toml
|
||||
swapon --show
|
||||
cat /proc/sys/vm/swappiness
|
||||
```
|
||||
|
||||
Ожидается `/swapfile` размером 2 ГБ, права `0600`, запись в `/etc/fstab`, низкая склонность к использованию.
|
||||
|
||||
## 6. Установка systemd unit
|
||||
|
||||
`/etc/systemd/system/awg2-harness.service`:
|
||||
|
||||
Reference unit в репозитории: [`awg2-harness.service`](../awg2-harness.service).
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=AWG2 Harness multi-orchestrator
|
||||
After=network-online.target docker.service
|
||||
Wants=network-online.target
|
||||
Requires=docker.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
ExecStart=/usr/local/bin/awg2-harness daemon --config /etc/awg2-harness/config.toml
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
Активация:
|
||||
|
||||
```bash
|
||||
systemd-analyze verify /etc/systemd/system/awg2-harness.service
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now awg2-harness.service
|
||||
```
|
||||
|
||||
## 7. Проверка после запуска daemon
|
||||
## D. Manual source-tree install (staging/debug only)
|
||||
|
||||
```bash
|
||||
systemctl status awg2-harness.service
|
||||
journalctl -u awg2-harness.service -n 100 --no-pager
|
||||
awg2-harness status --config /etc/awg2-harness/config.toml
|
||||
```
|
||||
Режим [`./tools/build.sh --install`](../tools/build.sh) предназначен для staging/debug с checkout-репозиторием.
|
||||
|
||||
## 8. Проверка auto-healing
|
||||
|
||||
```bash
|
||||
docker restart amnezia-awg2
|
||||
sleep 30
|
||||
awg2-harness status --config /etc/awg2-harness/config.toml
|
||||
```
|
||||
|
||||
Затем проверить Docker restart и host reboot. После каждого события status должен показывать healthy state без ручного запуска old bash.
|
||||
|
||||
## 9. Rollback
|
||||
|
||||
Production-путь AWG2 Harness не включает возврат к old bash в штатный процесс выкладки.
|
||||
Это **не** основной production deployment path.
|
||||
|
||||
+1
-1
@@ -233,7 +233,7 @@ Requires=docker.service
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
ExecStart=/usr/local/bin/awg2-harness daemon --config /etc/awg2-harness/config.toml
|
||||
ExecStart=/usr/sbin/awg2-harness daemon --config /etc/awg2-harness/config.toml
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
StandardOutput=journal
|
||||
|
||||
Reference in New Issue
Block a user