linux redisk: linux+keepalived+lvs+tomcat dual-port load balancing scheme

Keywords: Nginx vim Java Tomcat

Let's first feel the keepalived configuration file without reverse proxy if services are provided separately: (ps configuration is not panicky)

vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
    state BACKUP
    interface ens192
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass password
    }
    virtual_ipaddress {
        192.168.14.13
    }
}
virtual_server 192.168.14.13 80 {
    delay_loop 10
    lb_algo wlc
    lb_kind DR
    persistence_timeout 180
    protocol TCP
    real_server 192.168.14.127 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
    real_server 192.168.14.128 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
     real_server 192.168.14.129 80 {
         weight 100
         TCP_CHECK {
         connect_timeout 10
         nb_get_retry 3
         delay_before_retry 3
         connect_port 80
         }
      }
}
virtual_server 192.168.14.13 8080 {
    delay_loop 10
    lb_algo wlc
    lb_kind DR
    persistence_timeout 180
    protocol TCP
    real_server 192.168.14.127 8080 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
    real_server 192.168.14.128 8080 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
     real_server 192.168.14.129 8080 {
         weight 100
         TCP_CHECK {
         connect_timeout 10
         nb_get_retry 3
         delay_before_retry 3
         connect_port 80
         }
      }
}

Well, to explain, this is not only the 80 port load balancing, after adding the 8080 port load balancing, it is certainly not advocated to do so, but if you do not forget that machine 2 state is changed to BACKUP, priority is set to 90.

Now let's talk about the load balancing application scenario:

Keepalived+LVS High-Capability + Load Balancing Cluster Architecture, rs runs both httpd (port 80) and Java (port 8080) services, using Keepalived load balancing multiple ports. If you want to be served by 80 ports, the Keepalived+LVS load balancing layer only opens 80 ports, and the internal node uses nginx to proxy 8080 ports, then the reverse proxy 8080 is done first.

nginx reverse proxy Tomcat

#Create a nginx proxy virtual host named zrlog.conf on rs and configure it as follows:

vim /usr/local/nginx/conf/vhosts/zrlog.conf
server {
    listen 80;
    server_name www.3zuzrlog.com; #Define domain names (generally consistent with proxy ip domain names)

location / {
    proxy_pass http://localhost:8080; # Specifies the IP (web server IP) to be proxied (accessed)
    proxy_redirect default;
    proxy_set_header Host   $host; #$host refers to the server name of the proxy server (also the domain name of the proxy IP)
    proxy_set_header X-Real-IP      $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

#Note: Because the virtual host is only used as a proxy server and does not need to access local files, there is no need to set the root directory.

Well, Keepalived+LVS only needs to listen on port 80:

vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
    state BACKUP
    interface ens192
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass password
    }
    virtual_ipaddress {
        192.168.14.13
    }
}
virtual_server 192.168.14.13 80 {
    delay_loop 10
    lb_algo wlc
    lb_kind DR
    persistence_timeout 180
    protocol TCP
    real_server 192.168.14.127 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
    real_server 192.168.14.128 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
     real_server 192.168.14.129 80 {
         weight 100
         TCP_CHECK {
         connect_timeout 10
         nb_get_retry 3
         delay_before_retry 3
         connect_port 80
         }
      }
}

Posted by kulikedat on Fri, 08 Feb 2019 06:27:17 -0800