大网数据广告活动
服务器运维问答

Maintenance of nginx server with zero downtime

· 52CE 我爱测

I manage a few servers and for the sake of the question let's consider these three: nginx server: it only runs nginx and serves static files, responses from the disk cache, or passes requests to the API server API server: it retu…

问题原文

原帖链接 · user168317 · CC BY-SA 4.0

I manage a few servers and for the sake of the question let's consider these three:

  • nginx server: it only runs nginx and serves static files, responses from the disk cache, or passes requests to the API server
  • API server: it returns data and it connects to the database server
  • database server: it hosts the database, Redis and some other stuff

This setup allows us to perform maintenance with zero downtime. That is also the case for upgrades. If we want to add more memory to the database server, we just spin up a new instance, physically clone the database, and destroy the old server.

Roughly the same thing can be done with the API server. However, sooner or later we will need to upgrade the nginx server. How do we do that without downtime, if the upgrades require a shutdown? The nginx instance has to have a fixed IP to be reached from the external world.

已采纳解答

原帖链接 · Oliver · CC BY-SA 4.0

One possibility is to install a second nginx server and set up keepalived on both of them.

Each server has its own unique IP address. In addition, keepalived allows you do define a floating IP address that is shared by both servers. That floating address is active on one server only at any time. By shutting down keepalived on the active server, the floating IP address becomes active on the other server automatically. The same also happens if the server is powered off or if it crashes for whatever reason.

This allows you to do maintenance on the webservers without interrupting your service.

Just focus on the VRRP part of keepalived, and don't let yourself distract with load balancing and other fancy features as you probably won't need them at this point. Maybe you will also need a notify script that gets called if the floating IP address is added or removed so you can reload nginx to make sure it listens on the new IP address.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-08-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。