Keepalived高可用集群应用场景与配置

1.Keepalived单实例主备模式集群方案

这是最简单的模式,不只考虑高可用集群,先不考虑后方的Nginx负载均衡集群,即后端的服务器集群,参考下面的图示:

Keepalived高可用集群应用场景与配置

其对应的Keepalived核心配置如下:

lb01

global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id lb01    # 用来标识一个Keepalived高可用集群中的一个节点服务器,因此是唯一的
}
 
vrrp_instance VI_1 {
state MASTER      # 主
interface eth0
virtual_router_id 55    # 主备两台服务器的该值应该要相同
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.12/24 dev eth0 label eth0:1
}
}

lb02

global_defs {
  notification_email {
    acassen@firewall.loc
    failover@firewall.loc
    sysadmin@firewall.loc
  }
  notification_email_from Alexandre.Cassen@firewall.loc
  smtp_server 192.168.200.1
  smtp_connect_timeout 30
  router_id lb02
}
 
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 55
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.12/24 dev eth0 label eth0:1
    }
}

2.Nginx负载均衡集群配合Keepalived单实例主备模式集群方案

在1的基础上,同时考虑后端的Nginx负载均衡集群,参考下面的图示:

Keepalived高可用集群应用场景与配置

其对应的Keepalived和Nginx配置如下:

lb01

Keepalive配置:

failover@firewall.loc
    sysadmin@firewall.loc
  }
  notification_email_from Alexandre.Cassen@firewall.loc
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id lb01
}
 
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 55
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.12/24 dev eth0 label eth0:1
    }
}

Nginx配置:

[root@lb01 conf]# cat nginx.conf
worker_processes 1;
events {
    worker_connections 1024;
}
http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;
    upstream www_server_pools {
        server 10.0.0.9:80 weight=1;
        server 10.0.0.10:80 weight=1;
    }
    server {
        listen 10.0.0.12:80;
        server_name ;
        location / {
        proxy_pass ;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        }
    }
}

lb02

Keepalived配置:

failover@firewall.loc
    sysadmin@firewall.loc
  }
  notification_email_from Alexandre.Cassen@firewall.loc
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id lb02
}
 
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 55
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.12/24 dev eth0 label eth0:1
    }
}

Nginx配置:

[root@lb02 conf]# cat nginx.conf
worker_processes 1;
events {
    worker_connections 1024;
}
http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;
    upstream www_server_pools {
        server 10.0.0.9:80 weight=1;
        server 10.0.0.10:80 weight=1;
    }
    server {
        listen 10.0.0.12:80;
        server_name ;
        location / {
        proxy_pass ;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        }
    }
}

3.Keepalived双实例双主模式集群方案

参考下面图示:

Keepalived高可用集群应用场景与配置

其对应的Keepalive核心配置如下:

lb01

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/af4d9bcf9df96f71718d98edd2d12391.html