所有的高可用说白了就是增加备用服务器,通过检测手段、根据切换机制在故障发生时自动切换;需要安装 keepalived,通过脚本检测当前 nginx 的存活状态,如果主 nginx 宕机了,会自动切换到备用 nginx 上

配置

至少两台服务器(推荐三台,三角关系最稳定😁),都要安装nginx 和 keepalived

  1. yum install -y nginx
  2. yum install -y keepalived
  3. rpm -q -a keepalived
  4. #开机启动
  5. systemctl enable keepalived

配置文件/etc/keepalived/keepalived.conf,进行高可用主从配置