HAproxy Document
HAproxy Document.
I have use 2 machine and running OS is RHEL6.4 or CentOS 6.4.64Bit
Machine Details
IP 192.168.0.100 Hostname node1.example.com
IP 192.168.0.101 Hostname node2.example.com
Virtual IP 192.168.0.200
# yun install haproxy httpd* -y (in both Machine node1 and node2)
Configure httpd
NODE1
# vim /etc/httpd/conf/httpd.conf
Listen 192.168.0.100:8080
ServerName example.com
# vim /var/www/html/index.html
haproxy node1
# /etc/init.d/httpd restart
# chkconfig httpd on
NODE2
# vim /etc/httpd/conf/httpd.conf
Listen 192.168.0.101:8080
ServerName example.com
# vim /var/www/html/index.html
haproxy node2
# /etc/init.d/httpd restart
# chkconfig httpd on
# cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg-ORG ( copy haproxy.conf file backup in both machine node1 and node2 )
configure haproxy node1 Server
# vim /etc/haproxy/haproxy.cfg
global
log 192.168.0.200 local2 debug
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4096
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
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
# option http-server-close
option forwardfor
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
#frontend main *:5000
# acl url_static path_beg -i /static /images /javascript /stylesheets
# acl url_static path_end -i .jpg .gif .png .css .js
# use_backend static if url_static
# default_backend app
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
#backend static
# balance roundrobin
# server static 127.0.0.1:4331 check
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
#backend app
# balance roundrobin
# server app1 127.0.0.1:5001 check
# server app2 127.0.0.1:5002 check
# server app3 127.0.0.1:5003 check
# server app4 127.0.0.1:5004 check
listen Haproxy-APP 192.168.0.200:80
balance roundrobin
option httpclose
# option forwardfor
option forwardfor header X-Real-IP
server APPSERVER1 192.168.0.100:8080 check
server APPSERVER2 192.168.0.101:8080 check
listen admin
bind *:5050
stats enable
stats realm Haproxy\ Statistics
stats uri /
stats auth admin:wapstatus@123
# scp /etc/haproxy/haproxy.cfg 192.168.0.101:/etc/haproxy/haproxy.cfg
# cd /etc/sysconfig/network-scripts/
# cp ifcfg-eth0 ifcfg-eth0:0
# vim ifcfg-eth0:0
DEVICE=eth0:0
HWADDR=08:00:27:02:01:35
TYPE=Ethernet
UUID=be6391e4-9ce2-4a6f-b1dd-105a3af4666b
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.0.200
NETMASK=255.255.255.0
# ifup eth0:0
# /etc/init.d/haproxy restart
Test
go to Browser and type ( http://192.168.0.200 )
Comments
Post a Comment