在 Debian 上实现 Docker 高可用的总体思路
方案一 Docker Swarm 多节点编排
docker swarm init --advertise-addr <MANAGER-IP>;其他节点加入:docker swarm join --token <TOKEN> <MANAGER-IP>:2377。docker network create --driver overlay --attachable my-overlay。docker service create --name nginx --replicas 3 --publish published=8080,target=80 --network my-overlay nginx:latest。docker service update --restart-condition any --restart-delay 5s nginx。docker service update --update-parallelism 2 --update-delay 10s --image nginx:1.25 nginx。docker service update --health-cmd "curl -f http://localhost || exit 1" --health-interval 5s --health-retries 3 --health-timeout 2s nginx。docker node update --availability drain <NODE>;恢复:docker node update --availability active <NODE>。/var/lib/docker/swarm/(Raft 数据),必要时 docker swarm ca --rotate 轮换证书后在新节点恢复。方案二 入口高可用与负载均衡
docker service ls | grep my-service)。upstream backend { server 10.0.1.11:8080; server 10.0.1.12:8080; }listen 80; location / { proxy_pass http://backend; }有状态服务的高可用实践
replicaof 配置。sentinel monitor <master-name> <master-ip> <master-port> <quorum>,quorum 建议设为 2。数据持久化与运维监控
--mount type=volume,source=nfsvolume,target=/data,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/web,"volume-opt=o=addr=<NFS-IP>,rw,nfsvers=4,async"。docker swarm ca --rotate 轮换证书;限制管理端口 2377 的访问来源。