書接上文《下一代雲計算平臺Apache Mesos之使用marathon發佈應用》 html
做爲一個簡單的PaaS(平臺即服務),應該具有發佈應用,調整應用個數,重啓應用,暫停應用(marathon提供)以及負載均衡和服務發現的功能。本文主要演示負載均衡和服務發現。 git
{ "container": { "type": "DOCKER", "docker": { "image": "192.168.1.103:5000/tomcat", "network": "BRIDGE", "portMappings": [ { "containerPort": 8080, "hostPort": 0, "protocol": "tcp" } ] } }, "id": "tomcat", "instances": 3, "cpus": 0.5, "mem": 512, "uris": [], "cmd":"/opt/tomcat/bin/deploy-and-run.sh" }
curl -X POST -H "Content-Type: application/json" http://192.168.1.110:8080/v2/apps -d@Docker.json github
本例發佈了2個docker images,另外是一個spring boot的可執行jar包。 spring
marathon的restful api 有查看當前程序信息的接口: docker
http://192.168.1.110:8080/v2/tasks json
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根據該接口生成haproxy的服務發現及負載均衡。 api
使用的ip是192.168.1.103 tomcat
yum -y install haproxy restful
wget https://raw.githubusercontent.com/mesosphere/marathon/master/bin/haproxy-marathon-bridge chmod +x haproxy-marathon-bridge
./haproxy-marathon-bridge 192.168.1.110:8080 > /etc/haproxy/haproxy.cfg app
生成內容:
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
systemctl start haproxy systemctl enable haproxy
tomcat:http://192.168.1.103:10000
demo:http://192.168.1.103:10001
docker發佈文檔地址:https://mesosphere.github.io/marathon/docs/native-docker.html
負載均衡服務發現文檔地址:https://mesosphere.github.io/marathon/docs/service-discovery-load-balancing.html
若有格式問題,請訪問: