Differences

This shows you the differences between two versions of the page.

Link to this comparison view

how-to:set-up-haproxy [2016-02-25 11:28:51] (current)
rory.blanchard created
Line 1: Line 1:
 +====== How to Set up HAProxy on CentOS ======
 +HAProxy is a service that can help with load balancing of web servers, or just proxying traffic. We recommend installing through the Epel repository to keep the packages updated.
 +\\
 +\\
 +===== Install Epel: =====
  
 +Run the following commands:
 +
 +<​code>​
 +yum -y install epel-release
 +</​code>​
 +
 +If yum does not find the epel-release package, please see [[https://​www.ndchost.com/​wiki/​guides/​how-to-enable-epel-with-rpm|How to enable epel with RPM]] for installing it via RPM.
 +\\
 +\\
 +===== Install HAProxy =====
 +
 +Run the following command:
 +
 +<​code>​
 +yum -y install haproxy
 +</​code>​
 +
 +Once it has been installed, you can edit the config file by running the following:
 +
 +<​code>​
 +nano /​etc/​haproxy/​haproxy.cfg
 +</​code>​
 +\\
 +\\
 +===== Sample configuration for Web Server Proxy =====
 +
 +<​code>​
 +global
 +    # Where to save the logs, 
 +    log         ​127.0.0.1 local2 info
 +    chroot ​     /​var/​lib/​haproxy
 +    pidfile ​    /​var/​run/​haproxy.pid
 +    # Max connections per process
 +    maxconn ​    256
 +    # User and group process runs under
 +    user        haproxy
 +    group       ​haproxy
 +    daemon
 +
 +defaults
 +    # Mode the server is running in
 +    mode               http
 +    log                global
 +    option ​            ​httplog
 +    timeout connect ​   10s
 +    timeout client ​    30s
 +    timeout server ​    30s
 +
 +# Define Frontend (set any name for http-in section)
 +frontend http-in
 +    # Set server to listen on port 80
 +    bind *:80
 +    # Set default backend to forward traffic to
 +    default_backend ​   backend_servers
 +    option ​            ​forwardfor
 +
 +# Define Backend server with roundrobin mode
 +backend backend_servers
 +    # Set balance type as roundrobin
 +    balance ​           roundrobin
 +    # Define backend servers
 +    server ​            <​hostname>​ 10.0.0.31:​80 check
 +    server ​            <​hostname>​ 10.0.0.32:​80 check
 +</​code>​
 +
 +===== Auto-start for CentOS 7 =====
 +
 +To get HAproxy to run automatically after configuration run the following commands:
 +
 +<​code>​
 +systemctl start haproxy
 +systemctl enable haproxy
 +</​code>​
 +\\
 +\\