Installing haproxy load balancing for http and https--转载

时间:2022-01-12 15:55:16

This example will guide you through a simple IP based load balancing solution that handles ssl traffic.

The Configuration =

  • Load Balancer:  <192.168.0.2>  // will be our haproxy server
  • Web Server 1: <192.168.0.10>  // web application server 1
  • Web Server 2: <192.168.0.20>  // web application server 2
  • Admin Panel Port 8080: <192.168.0.2>  // Statistics Panel on port 8080

Web Server 1
Load Balancer   <
                                       Web Server 2

Step 1: Get and Install haproxy

We’ll be using the 1.3.17 src files to install haproxy. You can get them from http://haproxy.1wt.eu/

  1. wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.17.tar.gz
  2. cd haproxy-1.3.17
  3. make TARGET=linux26
  4. cp /path/to/haproxy-1.3.17/examples/haproxy.init /etc/init.d/haproxy
  5. chmod +x /etc/init.d/haproxy

We’re going to add a haproxy user and run it in a chroot jail. Be sure to read up on other security measures for your server.

  1. useradd haproxy
  2. mkdir /var/chroot/haproxy
  3. chown haproxy:haproxy /var/chroot/haproxy
  4. chmod 700 /var/chroot/haproxy

This will be a simple load balancing. The HAProxy server will listen to 1 IP and distribute to 2 servers.

  1. global
  2. maxconn     10000 # Total Max Connections.
  3. log     127.0.0.1   local0
  4. log     127.0.0.1   local1 notice
  5. daemon
  6. nbproc      1 # Number of processes
  7. user        haproxy
  8. group       haproxy
  9. chroot      /var/chroot/haproxy
  10. defaults
  11. log     global
  12. option      httplog
  13. mode        tcp
  14. clitimeout  60000
  15. srvtimeout  30000
  16. contimeout  4000
  17. retries     3
  18. redispatch
  19. option      httpclose
  20. listen  load_balanced   192.168.0.2:80,192.168.0.2:443
  21. balance     source
  22. option      ssl-hello-chk
  23. option      forwardfor
  24. server webserver1 192.168.0.10 weight 1 maxconn 5000 check
  25. server webserver2 192.168.0.20 weight 1 maxconn 5000 check
  26. listen  admin_stats 192.168.0.2:8080
  27. mode        http
  28. stats uri   /my_stats
  29. stats realm     Global\ statistics
  30. stats auth  username:password

Step 4: Configuring logging

Edit /etc/sysconfig/syslog

  1. SYSLOGD_OPTIONS=”-m 0 -r”