haproxy-marathon-bridge is used locally for load balancing and service discovery

haproxy-marathon-bridge is used locally for load balancing and service discovery

2.1 Principle

Marathon's restful api has an interface for viewing current program information:

http://192.168.1.110:8080/v2/tasks

demo    10001   192.168.1.113:31001 192.168.1.115:31001 192.168.1.114:31001
tomcat  10000   192.168.1.113:31000 192.168.1.115:31000 192.168.1.114:31000

haproxy-marathon-bridge generates service discovery and load balancing of haproxy based on this interface.

2.2 Select any machine in the LAN

The ip used is192.168.1.103

2.3 Install haproxy

yum -y install haproxy

2.4 Install haproxy-marathon-bridge

wget https://raw.githubusercontent.com/mesosphere/marathon/master/bin/haproxy-marathon-bridge

chmod +x haproxy-marathon-bridge

2.5 Generate haproxy.cfg

./haproxy-marathon-bridge 192.168.1.110:8080 > /etc/haproxy/haproxy.cfg

Generate content:

global
  daemon
  log 127.0.0.1 local0
  log 127.0.0.1 local1 notice
  maxconn 4096

defaults
  log            global
  retries             3
  maxconn          2000
  timeout connect  5000
  timeout client  50000
  timeout server  50000

listen stats
  bind 127.0.0.1:9090
  balance
  mode http
  stats enable
  stats auth admin:admin

listen demo-10001
  bind 0.0.0.0:10001
  mode tcp
  option tcplog
  balance leastconn
  server demo-3 192.168.1.113:31001 check
  server demo-2 192.168.1.115:31001 check
  server demo-1 192.168.1.114:31001 check

listen tomcat-10000
  bind 0.0.0.0:10000
  mode tcp
  option tcplog
  balance leastconn
  server tomcat-3 192.168.1.113:31000 check
  server tomcat-2 192.168.1.115:31000 check
  server tomcat-1 192.168.1.114:31000 check

2.5 Start haproxy

systemctl start haproxy
systemctl enable haproxy

2.6 Access test

tomcat:http://192.168.1.103:10000

demo:http://192.168.1.103:10001 

 

 

 

http://wiselyman.iteye.com/blog/2208515

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326638266&siteId=291194637