Hproxy provides high availability, load balancing, and reverse proxies based on TCP and HTTP applications, especially for those web sites that are heavily loaded, which typically require session hold or seven-tier processing. Haproxy runs on the current hardware, fully supports tens of thousands of concurrent connections, and its operating mode makes it easy and secure to integrate into the architecture, while protecting your Web server from being exposed to the network.
Environmental planning:
tong1:192.168.1.247 Haproxy
tong2:192.168.1.248 Web1
tong3:192.168.1.249 WEB2
1. Network Configuration
TONG1 node:
[Email protected] ~]# hostname
Tong1
[Email protected] ~]# Ifconfig | grep Mask
inet addr:192.168.1.247 bcast:192.168.1.255 mask:255.255.255.0
inet addr:127.0.0.1 mask:255.0.0.0
[Email protected] ~]# vim/etc/hosts
192.168.1.247 tong1
192.168.1.248 tong2
192.168.1.249 Tong3
[Email protected] ~]#
The TONG2 node is configured just like the TONG3 node
2. Install the Haproxy software on the TONG1 node and turn on the Haproxy log function
[email protected] ~]# Yum install haproxy-y
[[email protected] ~]# Vim/etc/sysconfig/rsyslog--add-R parameter record Haproxy log
Syslogd_options= "-r-c 2"
[[email protected] ~]# vim/etc/rsyslog.conf--Define the path of log storage
local2.*/var/log/haproxy.log
[Email protected] ~]#/etc/init.d/rsyslog restart
Shutting down system logger: [OK]
Starting system logger: [OK]
[Email protected] ~]#
[Email protected] ~]# cd/etc/haproxy/
[Email protected] haproxy]# vim haproxy.cfg
Global
Log 127.0.0.1 Local2--Turn on log function
Chroot/var/lib/haproxy--Path to run
Pidfile/var/run/haproxy.pid--pid File storage location
Maxconn 4000--Maximum number of connections
User Haproxy--users who belong to the run
Group Haproxy--the user group that belongs to run
Daemon--running the service in the background
Defaults
Mode HTTP--processing pattern (HTTP is layer seven, TCP is layer four)
Log Global--Enable global logging
Option Httplog--Log category HTTP format
Option Dontlognull--Do not log health check logs
Option Http-server-close
Option Forwardfor except 127.0.0.0/8
Option Redispatch--serverid The corresponding server is hung and then forcibly directed to another server
Retries 3--3 connections failed to define server not available
Timeout Http-request 10s
Timeout Queue 1m
Timeout Connect 10s--server connection timed out
Timeout client 1m--Clients connection timed out
Timeout server 1m--service-side Connection timeout
Timeout Http-keep-alive 10s--Persistent connection
Timeout Check 10s--Heartbeat check timeout
Maxconn 3000
Listen Admin_status--Custom listener name, arbitrary fetch
Bind 0.0.0.0:80--bind port
Mode HTTP--pattern
Log 127.0.0.1 Local3 Err--Log error logs
Stats Refresh 20s--Every 20s refresh
Stats Hide-version--Hide Haproxy version information
Stats Uri/haproxy-stats--add/haproxy-stats after domain name to view haproxy monitoring status
Stats Auth Haproxy:system--user name and password stats hide-version
Stats Admin If TRUE--can start and stop services manually
Frontend Main_status--Define ACL rules
Bind 0.0.0.0:80--bind to port 80
Mode http
Log Global
Option Httplog
Option Forwardfor
ACL Web1 Hdr_reg (host)-I ^ (www.itnihao.cn|ww1.itnihao.cn) $--matches www.itnihao.cn and WW1. Itnihao. cn two domain names are placed in the WEB1 variable
ACL web2 url_sub-i killall=--killall= is included in the request into the WEB2 variable
ACL web3 path_beg-i/static/images/javascript/stylesheets
Use_backend server_web1 If web1--a virtual host that satisfies the WEB1 variable and drops it into server_web1
Use_backend server_web2 If web2--a virtual host that satisfies the WEB1 variable and drops it into server_web1
Use_backend server_web3 if web3
Default_backend SERVER_WEB4--not satisfied with the virtual host that was thrown into the SERVER_WEB4
Backend SERVER_WEB3
Mode http
Balance Roundrobin
option httpchk get/test. HTML--Define home page address
Server Tong2 192.168.1.248:81 check Inter rise 3 Fall 3 weight 1--back end server, Inter 1500 is check heartbeat frequency, Rise 3 is 3 times correctly available, Fall 3 is 3 failures are not available, weight 1 is the weight
Server Tong3 192.168.1.249:82 check Inter rise 3 Fall 3 weight 1
Backend SERVER_WEB4
Mode http
Balance Roundrobin
option httpchk get/index. Html
Server Tong2 192.168.1.248:80 check Inter rise 3 Fall 3 weight 1
Server Tong3 192.168.1.249:80 check Inter rise 3 Fall 3 weight 1
This article is from the "Days Together" blog, please be sure to keep this source http://tongcheng.blog.51cto.com/6214144/1597364
Haproxy+apache of load Balancing software in Linux system