Keepalived高可用集群来实现Web服务器负载均衡集群(3)

六、keepalived配置文件的详解
  (1)RS1里面的keepalived.conf上的配置
  Keepalived.conf的脚本
! Configuration File for keepalived
 
global_defs {
  notification_email {
        root@localhost
}
  notification_email_from root@localhost
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id LVS_DEVEL
}
 
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass keepalivedpass
    }
    virtual_ipaddress {
        172.16.9.1
    }
}
 
virtual_server 172.16.9.1 80  {
    delay_loop 6
    lb_algo rr
    lb_kind NAT
    nat_mask 255.255.0.0
    persistence_timeout 50
    protocol TCP
 
    real_server 192.168.0.54 80 {
        weight 1
        SSL_GET {
            url {
              path /
              status_code 200
 
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}
 
virtual_server 172.16.9.1 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.0.0
  # persistence_timeout 50
    protocol TCP
 
 
    real_server 192.168.0.54 80 {
        weight 2
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 1
        }
    }
 
    real_server 192.168.0.55 {
        weight 2
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 1
            connect_port 80
        }
    }
}
 

Keepalived高可用集群来实现Web服务器负载均衡集群

Keepalived高可用集群来实现Web服务器负载均衡集群

Keepalived高可用集群来实现Web服务器负载均衡集群

然后把RS1上的keepalived.com复制到RS2上,并把其中的stata改成BACKUP,priority修改为100,其他内容不变
 
RS2里面的keepalived.conf脚本
! Configuration File for keepalived
 
global_defs {
  notification_email {
        root@localhost
}
  notification_email_from root@localhost
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id LVS_DEVEL
}
 
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass keepalivedpass
    }
    virtual_ipaddress {
        172.16.9.1
    }
}
 
virtual_server 172.16.9.1 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.0.0
  # persistence_timeout 50
    protocol TCP
 
 
    real_server 192.168.0.54 80 {
        weight 2
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 1
        }
    }
 
    real_server 192.168.0.55 {
        weight 2
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 1
            connect_port 80
        }
    }
}

Keepalived高可用集群来实现Web服务器负载均衡集群

启动keepalived服务;

Keepalived高可用集群来实现Web服务器负载均衡集群

Keepalived高可用集群来实现Web服务器负载均衡集群

Keepalived高可用集群来实现Web服务器负载均衡集群

访问虚拟IP地址

Keepalived高可用集群来实现Web服务器负载均衡集群

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

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