Моя шпаргалка :)

Мануалы и настройки => Настройки *nix (почта, web, система etc) => Тема начата: George от Май 22, 2026, 02:01

Название: Rolling обновление HAProxy (keepalived, 2 ноды)
Отправлено: George от Май 22, 2026, 02:01
Rolling обновление HAProxy (keepalived, 2 ноды)

Описание
Обновляет обе ноды по очереди:

---

1. Скрипт

nano /usr/local/sbin/haproxy-ha-upgrade.sh

#!/bin/bash

set -euo pipefail
export DEBIAN_FRONTEND=noninteractive

LOG="/var/log/haproxy-upgrade.log"
LOCK="/var/run/haproxy-upgrade.lock"

VIP="10.10.1.100"
PEER="haproxy-2"   # поменять на вторую ноду

log() {
echo "[$(date '+%F %T')] $*" | tee -a "$LOG"
}

if [ -f "$LOCK" ]; then
exit 0
fi

touch "$LOCK"
trap "rm -f $LOCK" EXIT

# self check

curl -fs http://127.0.0.1/health || exit 1

# peer check

ssh "$PEER" "curl -fs http://127.0.0.1/health" || exit 1

# upgrade

apt update >> "$LOG" 2>&1
apt upgrade -y >> "$LOG" 2>&1

if [ -f /var/run/reboot-required ]; then
reboot
fi

sleep 30

curl -fs http://127.0.0.1/health || exit 1

---

2. systemd service

nano /etc/systemd/system/haproxy-upgrade.service

[Unit]
Description=HAProxy upgrade

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/haproxy-ha-upgrade.sh

---

3. systemd timer

nano /etc/systemd/system/haproxy-upgrade.timer

[Unit]
Description=HAProxy upgrade timer

[Timer]
OnCalendar=*-*-* 03:00:00
Persistent=true

[Install]
WantedBy=timers.target

---

4. Активация

systemctl daemon-reload
systemctl enable --now haproxy-upgrade.timer

---

Важно