Home/Server & Website Managed Operations/HAProxy Layer 4 Proxy
Server & Website Managed Operations

HAProxy Layer 4 Proxy

1. Installation

  1. #wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.22.tar.gz
  2. #tar zxvf haproxy-1.4.22.tar.gz
  3. #cd haproxy-1.4.22
  4. #uname -r
  5. #make TARGET=linux26 PREFIX=/usr/local/haproxy
  6. #make install PREFIX=/usr/local/haproxy
  7. #mkdir conf
  8. #/usr/local/haproxy/sbin/haproxy -f haproxy.cfg

HAProxy Configuration File (haproxy.cfg)

  1. ########### Global Configuration #########
  2. global
  3. chroot /usr/local/haproxy
  4. daemon
  5. nbproc 1
  6. group nobody
  7. user nobody
  8. pidfile /usr/local/haproxy/logs/haproxy.pid
  9. ulimit–n 65536
  10. #spread-checks 5m
  11. #stats timeout 5m
  12. #stats maxconn 100
  13. ######## Default Configuration ############
  14. defaults
  15. mode tcp #Default mode: { tcp|http|health }. TCP is Layer 4, HTTP is Layer 7, health only returns OK.
  16. retries 3 #If connection fails twice, the server is considered unavailable. This can also be configured later.
  17. option redispatch #When the server corresponding to serverId goes down, force redirection to another healthy server.
  18. option abortonclose #When server load is high, automatically terminate connections that have been in the queue for a long time.
  19. maxconn 32000 #Default maximum number of connections.
  20. timeout connect 5000ms #Connection timeout.
  21. timeout client 30000ms #Client timeout.
  22. timeout server 30000ms #Server timeout.
  23. #timeout check 2000 #Health check timeout
  24. log 127.0.0.1 local0 err #[err warning info debug]
  25. ######## SMTP Configuration #################
  26. listen smtp 192.168.1.68:25
  27. # bind 0.0.0.0:25
  28. mode tcp
  29. balance roundrobin
  30. server s1 192.168.1.118:25 weight 1 maxconn 10000 check inter 10s
  31. server s2 192.168.1.240:25 weight 1 maxconn 10000 check inter 10s
  32. ######## POP3 Configuration #################
  33. listen pop3 192.168.1.68:110
  34. # bind 0.0.0.0:25
  35. mode tcp
  36. balance roundrobin
  37. server s1 192.168.1.118:110 weight 1 maxconn 10000 check inter 10s
  38. server s2 192.168.1.240:110 weight 1 maxconn 10000 check inter 10s
  39. ######## IMAP Configuration #################
  40. listen imap 192.168.1.68:143
  41. # bind 0.0.0.0:25
  42. mode tcp
  43. balance roundrobin
  44. server s1 192.168.1.118:143 weight 1 maxconn 10000 check inter 10s
  45. server s2 192.168.1.240:143 weight 1 maxconn 10000 check inter 10s
  46. ######## Statistics Page Configuration ########
  47. listen admin_stats 192.168.1.68:8099
  48. # bind 0.0.0.0:8099 #Listening port
  49. mode http #HTTP Layer 7 mode
  50. option httplog #Use HTTP log format
  51. #log 127.0.0.1 local0 err
  52. maxconn 5
  53. stats refresh 30s #Auto-refresh interval for statistics page
  54. stats uri /stats #Statistics page URL
  55. stats realm XingCloud Haproxy #Prompt text on the statistics page password box
  56. stats auth admin:admin #Username and password settings for the statistics page
  57. stats hide–version #Hide HAProxy version information on the statistics page

Monitoring Diagram:

haproxy

FREE CHECKUP

Free server checkup

We will send a problem checklist and remediation advice within one business day — no obligation to engage.

135 410 16684
Weekdays Mon – Fri 10:00 – 22:00 (UTC+8) · 7×24 emergency response
Call now
CONTACT

Contact Us

How can we help?

* Required