forked from mtusi2026/mtusi2026lab3
solution
This commit is contained in:
+8
-5
@@ -1,7 +1,10 @@
|
||||
# Инфраструктура студента
|
||||
# Инфраструктура lab3
|
||||
|
||||
Здесь разместите конфигурации выбранных сервисов; основную топологию — в корневом compose.yaml/stack.yaml. `compose.example.yaml` — только worksheet ролей и намеренно не запускается. `contracts/infrastructure.json` задаёт минимальные роли, не готовые образы/пароли.
|
||||
`nginx/nginx.conf` — proxy, round robin, DNS и таймауты.
|
||||
`nginx/entrypoint.sh` — активные readiness-пробы и reload upstream.
|
||||
Топология, сети, ресурсы, одноразовый migrate и volumes — в корневом compose.yaml.
|
||||
|
||||
В REPORT.md сопоставьте роль → service name → версия/digest → health/readiness → volume → сеть/порт → способ передачи credentials. Приведите bootstrap (schema, bucket, broker topology, а с lab6 provisioning) и безопасное повторение этих команд.
|
||||
|
||||
Приложение строится из исходников. Не используйте заранее существующий образ преподавательского сервера вместо своей реализации. Restart hook перезапускает все соответствующие stores с volumes; failover hook останавливает только заданную API-реплику.
|
||||
Nginx OSS используется без коммерческих health_check-директив. Docker socket
|
||||
в контейнеры не монтируется. Внешний порт опубликован только на LB; marker drain
|
||||
позволяет scripts/replicas.py исключать одну API для плановой замены.
|
||||
Подробные интервалы и границы — REPORT.md.
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
render() {
|
||||
printf 'upstream api_backend {\n zone api_backend 64k;\n'
|
||||
count=0
|
||||
for host in api-a api-b; do
|
||||
if [ ! -e "/tmp/drain-$host" ] && wget -q -T 1 -O /dev/null "http://$host:8080/health/ready"; then
|
||||
printf ' server %s:8080 resolve max_fails=1 fail_timeout=2s;\n' "$host"
|
||||
count=$((count + 1))
|
||||
fi
|
||||
done
|
||||
if [ "$count" -eq 0 ]; then
|
||||
printf ' server 127.0.0.1:9;\n'
|
||||
fi
|
||||
printf '}\n'
|
||||
}
|
||||
|
||||
render > /tmp/backends.conf
|
||||
nginx -c /opt/lb/nginx.conf -g 'daemon off;' &
|
||||
master=$!
|
||||
|
||||
shutdown() {
|
||||
kill -QUIT "$master" 2>/dev/null || true
|
||||
wait "$master" || true
|
||||
exit 0
|
||||
}
|
||||
trap shutdown TERM INT QUIT
|
||||
|
||||
while kill -0 "$master" 2>/dev/null; do
|
||||
sleep 1 &
|
||||
wait $! || true
|
||||
render > /tmp/backends.next
|
||||
if ! cmp -s /tmp/backends.next /tmp/backends.conf; then
|
||||
cp /tmp/backends.conf /tmp/backends.previous
|
||||
mv /tmp/backends.next /tmp/backends.conf
|
||||
if nginx -t -c /opt/lb/nginx.conf; then
|
||||
kill -HUP "$master"
|
||||
printf 'LB ready backends: %s\n' "$(tr '\n' ' ' < /tmp/backends.conf)"
|
||||
else
|
||||
mv /tmp/backends.previous /tmp/backends.conf
|
||||
fi
|
||||
fi
|
||||
done
|
||||
wait "$master"
|
||||
@@ -0,0 +1,33 @@
|
||||
worker_processes 1;
|
||||
pid /tmp/nginx.pid;
|
||||
error_log /dev/stderr warn;
|
||||
worker_shutdown_timeout 5s;
|
||||
events { worker_connections 1024; }
|
||||
http {
|
||||
log_format upstream '$request_method $uri status=$status upstream=$upstream_addr upstream_status=$upstream_status time=$request_time';
|
||||
access_log /dev/stdout upstream;
|
||||
resolver 127.0.0.11 valid=1s ipv6=off;
|
||||
resolver_timeout 1s;
|
||||
include /tmp/backends.conf;
|
||||
server {
|
||||
listen 8080;
|
||||
server_tokens off;
|
||||
client_max_body_size 256k;
|
||||
client_header_timeout 5s;
|
||||
client_body_timeout 5s;
|
||||
keepalive_timeout 2s;
|
||||
location / {
|
||||
proxy_pass http://api_backend;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_connect_timeout 1s;
|
||||
proxy_read_timeout 8s;
|
||||
proxy_send_timeout 8s;
|
||||
proxy_next_upstream error timeout http_502 http_503 http_504;
|
||||
proxy_next_upstream_tries 2;
|
||||
proxy_next_upstream_timeout 9s;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user