High-availability cluster for HAproxy Based on Keepalived

Source: Internet
Author: User
Tags haproxy

High-availability cluster for HAproxy Based on Keepalived

1. Introduction to Keepalived

Keepalived is used to detect the status of a web server. If a web server crashes or fails to work, Keepalived will detect it and remove the faulty web server from the system, when the web server is working normally, Keepalived automatically adds the web server to the server group. All these tasks are completed automatically without manual interference. All you need to do is to manually repair the faulty web server.

Layer 3, 4 & 7 work on the IP layer, TCP layer, and application layer of the IP/TCP protocol stack. The principles are as follows:

When Layer3: Keepalived works in Layer3 mode, Keepalived periodically sends an ICMP packet (which is the Ping program we usually use) to the server in the server group ), if the IP address of a service is not activated, Keepalived reports that the server is invalid and removes it from the server group. In this case, a server is shut down illegally. Layer3 is based on whether the IP address of the server is valid as the standard for whether the server works normally. This method will be used in this article.

Layer4: If you understand the Layer3 method, Layer4 is easy. Layer4 mainly determines whether the server works normally based on the TCP port status. For example, the Service port of the web server is usually 80. If Keepalived detects that port 80 is not started, Keepalived removes the server from the server group.

Layer7: Layer7 is used at the specific application layer. It is more complex than Layer3 and Layer4, and the bandwidth occupied by the network is also larger. Keepalived checks whether the server program runs properly according to the user's settings. If it does not match the user's settings, Keepalived removes the server from the server group.

Haproxy + Keepalived build Weblogic high-availability server Load balancer Cluster

Keepalived + HAProxy configure high-availability Load Balancing

Haproxy + Keepalived + Apache configuration notes in CentOS 6.3

Haproxy + KeepAlived WEB Cluster on CentOS 6

Haproxy + Keepalived build high-availability Load Balancing

Haproxy implements fully transparent Exchange proxy service

Ii. installation and configuration

1. Topology

Note: 1. Two proxy servers provide data externally through VIP

2. Both proxy servers can proxy backend servers

3. For the convenience of testing, the backend server provides a static page

2. ip planning

Functions IP address Install software
VIP 192.168.1.99  
Reverse Proxy 1 192.168.1.201 Keepalived, haproxy
Reverse Proxy 2 192.168.1.204 Keepalived, haproxy
Web Server 1 192.168.1.202 Httpd
Web Server 2 192.168.1.203 Httpd

3. install and configure haproxy

For detailed configuration of haproxy, see

[Root @ node1 ~] # Cat/etc/haproxy. cfg
#---------------------------------------------------------------------
# Example configuration for a possible web application. See
# Full configuration options online.
#
# Http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
Global
# To have these messages end up in/var/log/haproxy. log you will
# Need:
#
#1) configure syslog to accept network log events. This is done
# By adding the '-R' option to the SYSLOGD_OPTIONS in
#/Etc/sysconfig/syslog
#
#2) configure local2 events to go to the/var/log/haproxy. log
# File. A line like the following can be added
#/Etc/sysconfig/syslog
#
# Local2. */var/log/haproxy. log
#
Log 127.0.0.1 local2
Chroot/var/lib/haproxy
Pidfile/var/run/haproxy. pid
Maxconn 4000
User haproxy
Group haproxy
Daemon
# Turn on stats unix socket
Stats socket/var/lib/haproxy/stats
#---------------------------------------------------------------------
# Common defaults that all the 'listen' and 'backend' sections will
# Use if not designated in their block
#---------------------------------------------------------------------
Ults
Mode http
Log global
Option httplog
Option dontlognull
Option http-server-close
Option forwardfor partition t 127.0.0.0/8
Option redispatch
Retries 3
Timeout http-request 10 s
Timeout queue 1 m
Timeout connect 10 s
Timeout client 1 m
Timeout server 1 m
Timeout http-keep-alive 10 s
Timeout check 10 s
Maxconn 3000
#---------------------------------------------------------------------
# Main frontend which proxys to the backends
#---------------------------------------------------------------------
Frontend main *: 80
Default_backend static
#---------------------------------------------------------------------
# Static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
Backend static
Balance roundrobin
Server node2 192.168.1.202: 80 check maxconn 2000
Server node3 192.168.1.203: 80 check maxconn 2000
#---------------------------------------------------------------------
# Round robin balancing between the various backends
#---------------------------------------------------------------------

Note: The configuration files of HAproxy on the two nodes should be the same.

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.