forked from mtusi2026/mtusi2026lab6
Перенести реализацию lab5 в skeleton lab6
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
# Load balancer for the lab3 stand (HAProxy, container `lb`).
|
||||
#
|
||||
# Почему активные проверки, а не пассивные: nginx OSS умел только пассивные, и
|
||||
# реплика, которая осталась доступной по сети, но потеряла БД, продолжала получать
|
||||
# трафик и отвечала 503 (измерено: 20 из 40 запросов /health/live). HAProxy сам
|
||||
# опрашивает /health/ready и полностью убирает неготовую реплику из ротации.
|
||||
#
|
||||
# Почему повторы безопасны: `retry-on conn-failure` — повтор только когда
|
||||
# соединение не установилось и запрос НЕ ушёл. Если запрос уже передан серверу,
|
||||
# повтора нет, поэтому прозрачного дублирования POST (создание чата, сообщения)
|
||||
# балансировщик не делает. Неопределённый результат повторяет клиент, а сообщение
|
||||
# защищено обязательным Idempotency-Key (контракт 1.3.0).
|
||||
|
||||
global
|
||||
log stdout format raw local0
|
||||
maxconn 2048
|
||||
|
||||
defaults
|
||||
mode http
|
||||
log global
|
||||
option httplog
|
||||
option dontlognull
|
||||
timeout connect 1s
|
||||
timeout client 70s
|
||||
timeout server 45s
|
||||
# Проверка готовности: одна проба не может висеть дольше 1 с, поэтому при
|
||||
# inter 2s fall 2 реплика уходит из ротации максимум за ~4 с, даже если она
|
||||
# держит соединение открытым и не отвечает.
|
||||
#
|
||||
# timeout server увеличен для 10 MiB загрузок: spool + S3 Put не всегда
|
||||
# укладываются в прежние 5 с под конкурентной нагрузкой. Readiness-проба
|
||||
# остаётся с timeout check 1s, поэтому обнаружение мёртвой реплики не
|
||||
# замедляется.
|
||||
timeout check 1s
|
||||
retry-on conn-failure
|
||||
retries 2
|
||||
option redispatch
|
||||
|
||||
resolvers docker
|
||||
nameserver dns 127.0.0.11:53
|
||||
resolve_retries 3
|
||||
timeout resolve 1s
|
||||
timeout retry 1s
|
||||
hold valid 5s
|
||||
hold nx 2s
|
||||
hold timeout 1s
|
||||
hold refused 1s
|
||||
hold obsolete 5s
|
||||
|
||||
backend api_backend
|
||||
balance leastconn
|
||||
# Период проверки 2 с; реплика исключается после 2 неудач (<=4 с) и
|
||||
# возвращается в ротацию после 2 успехов (<=4 с).
|
||||
option httpchk
|
||||
http-check send meth GET uri /health/ready
|
||||
http-check expect status 200
|
||||
# Одно имя -> все адреса реплик (общий network alias в compose.yaml),
|
||||
# адреса переразрешаются каждые 5 с: масштабирование и замена контейнеров
|
||||
# не зависят от их номеров и IP.
|
||||
default-server check inter 2s fall 2 rise 2 resolvers docker resolve-prefer ipv4 init-addr none
|
||||
# Слотов больше, чем типовых реплик (1/2/4 в треке 1): свободный слот нужен
|
||||
# ещё и сценарию scripts/lb_readiness_check.sh, который поднимает рядом
|
||||
# «неготовую» реплику.
|
||||
server-template api 8 api-replica:8080
|
||||
|
||||
frontend http_front
|
||||
bind *:80
|
||||
default_backend api_backend
|
||||
|
||||
frontend stats_front
|
||||
# Только для оператора и доказательств: видно, какие реплики UP/DOWN и почему.
|
||||
bind *:8404
|
||||
stats enable
|
||||
stats uri /stats
|
||||
stats refresh 2s
|
||||
monitor-uri /healthz
|
||||
@@ -0,0 +1,27 @@
|
||||
# SeaweedFS identities
|
||||
|
||||
`infra/s3/s3.json` is mounted read-only into the `seaweedfs` container and is
|
||||
the single source of truth for S3 credentials and permissions.
|
||||
|
||||
- `admin` is used only by the one-shot `s3-init` service (bucket creation and
|
||||
probing). It is never given to the API and must not be placed in `.env`:
|
||||
the API service loads `.env` as an environment file. Compose supplies the
|
||||
synthetic admin values to `s3-init` directly.
|
||||
- `app` is used by the API and by presigned uploads. It can read/write only
|
||||
`messenger-attachments/attachments/*` and `messenger-attachments/staging/*`,
|
||||
and list the bucket for the orphan sweeper.
|
||||
|
||||
The credentials are synthetic values for the local stand. `.env.example`
|
||||
carries the same values for the API and `scripts/check_s3_creds.py` fails the
|
||||
offline check if they drift. Replace them in `.env` for any non-local run.
|
||||
|
||||
Verify manually:
|
||||
|
||||
```sh
|
||||
# anonymous requests are denied
|
||||
docker compose exec -T seaweedfs \
|
||||
wget -qO- http://127.0.0.1:8333/messenger-attachments/attachments/missing
|
||||
|
||||
# the app identity cannot write outside its prefixes
|
||||
docker compose run --rm s3-init # probes this and exits non-zero on violation
|
||||
```
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"identities": [
|
||||
{
|
||||
"name": "admin",
|
||||
"credentials": [
|
||||
{"accessKey": "lab4admin", "secretKey": "lab4admin-secret"}
|
||||
],
|
||||
"actions": ["Admin", "Read", "Write", "List", "Tagging"]
|
||||
},
|
||||
{
|
||||
"name": "app",
|
||||
"credentials": [
|
||||
{"accessKey": "lab4app", "secretKey": "lab4app-secret"}
|
||||
],
|
||||
"actions": [
|
||||
"Read:messenger-attachments/attachments/*",
|
||||
"Write:messenger-attachments/attachments/*",
|
||||
"Read:messenger-attachments/staging/*",
|
||||
"Write:messenger-attachments/staging/*",
|
||||
"List:messenger-attachments"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user