标签:
书接上文《下一代云计算平台Apache Mesos之使用marathon发布应用》
作为一个简单的PaaS(平台即服务),应该具备发布应用,调整应用个数,重启应用,暂停应用(marathon提供)以及负载均衡和服务发现的功能。本文主要演示负载均衡和服务发现。
{ "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
本例发布了2个docker images,另外是一个spring boot的可执行jar包。
marathon的restful api 有查看当前程序信息的接口:
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根据该接口生成haproxy的服务发现及负载均衡。
使用的ip是192.168.1.103
yum -y install haproxy
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
生成内容:
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
如有格式问题,请访问:
下一代云计算平台Apache Mesos定制自己的PaaS(应用发布+负载均衡+服务发现)
标签:
原文地址:http://my.oschina.net/u/2273085/blog/410664