thesuhu

Haproxy Docker

Feb 17th, 2020 (edited)
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.63 KB | None | 0 0
  1. # Create a Dockerfile
  2. FROM haproxy:1.7
  3. COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
  4.  
  5. # Build the container
  6. docker build -t my-haproxy .
  7.  
  8. # Test the configuration file
  9. docker run -it --rm --name haproxy-syntax-check my-haproxy haproxy -c -f /usr/local/etc/haproxy/haproxy.cfg
  10.  
  11. # Run the container
  12. docker run -d --name my-running-haproxy my-haproxy
  13.  
  14. # Contoh simple haproxy config, single port
  15. #---------------------------------------------------------------------
  16. # common defaults that all the 'listen' and 'backend' sections will
  17. # use if not designated in their block
  18. #---------------------------------------------------------------------
  19. global
  20.         daemon
  21.         maxconn 256
  22.  
  23.     defaults
  24.         mode http
  25.         timeout connect 5000ms
  26.         timeout client 50000ms
  27.         timeout server 50000ms
  28.  
  29.     frontend http-in
  30.         bind *:80
  31.         default_backend servers
  32.  
  33.     backend servers
  34.         server gpptraining 10.xxx.xxx.xx:30017 check
  35.  
  36. #---------------------------------------------------------------------
  37. #HAProxy Monitoring Config
  38. #---------------------------------------------------------------------
  39. listen stats
  40.     bind *:8404
  41.  
  42.     mode http
  43.     log global
  44.  
  45.     maxconn 10
  46.  
  47.     stats enable
  48.     stats hide-version
  49.     stats show-node
  50.     stats auth username:pwd
  51.     stats uri /monit
  52.     stats refresh 30s
  53.     #stats admin if LOCALHOST
  54.  
  55. # contoh multi port
  56. #---------------------------------------------------------------------
  57. # common defaults that all the 'listen' and 'backend' sections will
  58. # use if not designated in their block
  59. #---------------------------------------------------------------------
  60. global
  61.         daemon
  62.         maxconn 256
  63.  
  64.     defaults
  65.         mode http
  66.         timeout connect 5000ms
  67.         timeout client 50000ms
  68.         timeout server 50000ms
  69.  
  70.     frontend http-in
  71.         bind *:80
  72.     bind *:81
  73.         acl p1 dst_port 80
  74.         acl p2 dst_port 81
  75.         use_backend servers1 if p1
  76.         use_backend servers2 if p2
  77.  
  78.     backend servers1
  79.         balance roundrobin
  80.         server gpptraining 10.xxx.xxx.xxx:30017 check
  81.  
  82.     backend servers2
  83.         balance roundrobin
  84.         server gpptraining 10.xxx.xxx.xxx:30018 check
  85.  
  86. #---------------------------------------------------------------------
  87. #HAProxy Monitoring Config
  88. #---------------------------------------------------------------------
  89. listen stats
  90.     bind *:8404
  91.  
  92.     mode http
  93.     log global
  94.  
  95.     maxconn 10
  96.  
  97.     stats enable
  98.     stats hide-version
  99.     stats show-node
  100.     stats auth username:pwd
  101.     stats uri /monit
  102.     stats refresh 30s
  103.     #stats admin if LOCALHOST
  104.  
  105.  
Add Comment
Please, Sign In to add comment