marathon-lb

官方:https://github.com/mesosphere/marathon-lb

一 简介

Marathon load balancer (Marathon-LB) is a proxy server and load balancer for TCP, HTTP, and HTTPS requests based on HAProxy open-source software.

marathon-lb是一个基于HAProxy的代理服务器和负载均衡器,支持TCP、HTTP、HTTPS请求;

背景

When your app is up and running, you need a way to send traffic to it, from other applications on the same cluster, and from external clients.

There are several ways to do this:

  • Mesos-DNS provides service discovery through the domain name system (DNS).
  • Marathon-lb provides port-based service discovery using HAProxy, a lightweight TCP/HTTP proxy.

当应用启动之后,需要一种方式使得其能够被调用方自动发现并发送请求,有两种方式可以实现:Mesos-DNS和Marathon-lb;

Marathon-LB locates applications through the Marathon framework port-based service discovery using a virtual or DNS-defined IP address and the frontend and backend configuration settings specified for the HAProxy program.

If you install and configure Marathon-LB, the load balancer runs the HAProxy TCP/HTTP proxy service on each host in the cluster. The HAProxy service listens for inbound connection requests on a service port on a public agent node. If clients connect to the service port to request access to an app, the HAProxy service transparently forwards the requests to a host name and port number associated with the individual application instances orchestrated by the Marathon service.

marathon-lb通过marathon框架基于端口的服务发现来定位应用,并且自动生成haproxy配置;

二 安装

1 docker

$ docker run -d --privileged -e PORTS=9090 --net=host docker.io/mesosphere/marathon-lb sse -m http://marathon1_ip:8080 -m http://marathon2_ip:8080 -m http://master3_ip:8080 --group external

2 marathon web

3 marathon api

# cat marathon-lb.json
{
"id":"marathon-lb",
"cpus": 1,
"mem": 128,
"instances": 1,
"constraints": [["hostname", "UNIQUE"]],
"container": {
"type":"DOCKER",
"docker": {
"image": "mesosphere/marathon-lb",
"privileged": true,
"network": "HOST"
}
},
"args": ["sse", "-m", "http://192.168.0.1:8080", "-m", "http://192.168.0.2:8080", "-m", "http://192.168.0.3:8080", "--group", "external"]
}
# curl -X POST http://192.168.0.1:8080/v2/apps -d@/path/to/marathon-lb.json -H "Content-type:application/json"

启动之后会绑定如下端口

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 23948/haproxy
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 23948/haproxy
tcp 0 0 0.0.0.0:9090 0.0.0.0:* LISTEN 23948/haproxy
tcp 0 0 0.0.0.0:9091 0.0.0.0:* LISTEN 23948/haproxy

访问:http://$marathon-lb_server:9090/haproxy?stats

haproxy常用接口如下:

http://$haproxy_server:9090/haproxy?stats
http://$haproxy_server:9090/_haproxy_health_check
http://$haproxy_server:9090/_haproxy_getconfig

详细接口如下:

monitor-uri /_haproxy_health_check
acl getpid path /_haproxy_getpids
http-request use-service lua.getpids if getpid
acl getvhostmap path /_haproxy_getvhostmap
http-request use-service lua.getvhostmap if getvhostmap
acl getappmap path /_haproxy_getappmap
http-request use-service lua.getappmap if getappmap
acl getconfig path /_haproxy_getconfig
http-request use-service lua.getconfig if getconfig

acl signalmlbhup path /_mlb_signal/hup
http-request use-service lua.signalmlbhup if signalmlbhup
acl signalmlbusr1 path /_mlb_signal/usr1
http-request use-service lua.signalmlbusr1 if signalmlbusr1

三 使用

1 http(比如nginx)

后端marathon application配置

"labels": {
"HAPROXY_0_MODE": "http",
"HAPROXY_0_BALANCE": "roundrobin",
"HAPROXY_0_GROUP": "external",
"HAPROXY_0_VHOST": "service-test.com"
},
...
"portMappings":[{"containerPort":80,"hostPort":0,"servicePort":10080,"protocol":"tcp"}]

其中HAPROXY_0_MODE默认为http,HAPROXY_0_BALANCE默认为roundrobin;生成的haproxy配置路径如下:

/marathon-lb/haproxy.cfg

然后可以通过 $marathon-lb_server:10080 来访问实际的一个或多个后端 $backend_server:80

2 tcp(比如redis)

后端marathon application配置

"labels": {
"HAPROXY_0_MODE": "tcp",
"HAPROXY_0_GROUP": "external"
},
...
"portMappings":[{"containerPort":6379,"hostPort":0,"servicePort":16379,"protocol":"tcp"}]

注意:HAPROXY_0_MODE=tcp时一定不要配置HAPROXY_0_VHOST(http mode时使用),否则会生成错误的haproxy配置导致marathon-lb启动失败

然后可以通过 $marathon-lb_server:16379 来访问实际的一个或多个后端 $backend_server:6379

参考:

https://docs.mesosphere.com/services/marathon-lb/

https://mesosphere.github.io/marathon/docs/service-discovery-load-balancing.html

【原创】大数据基础之Marathon(2)marathon-lb的更多相关文章

  1. 【原创】大数据基础之Zookeeper(2)源代码解析

    核心枚举 public enum ServerState { LOOKING, FOLLOWING, LEADING, OBSERVING; } zookeeper服务器状态:刚启动LOOKING,f ...

  2. 【原创】大数据基础之词频统计Word Count

    对文件进行词频统计,是一个大数据领域的hello word级别的应用,来看下实现有多简单: 1 Linux单机处理 egrep -o "\b[[:alpha:]]+\b" test ...

  3. 【原创】大数据基础之Impala(1)简介、安装、使用

    impala2.12 官方:http://impala.apache.org/ 一 简介 Apache Impala is the open source, native analytic datab ...

  4. 【原创】大数据基础之Benchmark(2)TPC-DS

    tpc 官方:http://www.tpc.org/ 一 简介 The TPC is a non-profit corporation founded to define transaction pr ...

  5. 大数据基础知识:分布式计算、服务器集群[zz]

    大数据中的数据量非常巨大,达到了PB级别.而且这庞大的数据之中,不仅仅包括结构化数据(如数字.符号等数据),还包括非结构化数据(如文本.图像.声音.视频等数据).这使得大数据的存储,管理和处理很难利用 ...

  6. 大数据基础知识问答----spark篇,大数据生态圈

    Spark相关知识点 1.Spark基础知识 1.Spark是什么? UCBerkeley AMPlab所开源的类HadoopMapReduce的通用的并行计算框架 dfsSpark基于mapredu ...

  7. 大数据基础知识问答----hadoop篇

    handoop相关知识点 1.Hadoop是什么? Hadoop是一个由Apache基金会所开发的分布式系统基础架构.用户可以在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力进行高速 ...

  8. hadoop大数据基础框架技术详解

    一.什么是大数据 进入本世纪以来,尤其是2010年之后,随着互联网特别是移动互联网的发展,数据的增长呈爆炸趋势,已经很难估计全世界的电子设备中存储的数据到底有多少,描述数据系统的数据量的计量单位从MB ...

  9. 大数据基础总结---HDFS分布式文件系统

    HDFS分布式文件系统 文件系统的基本概述 文件系统定义:文件系统是一种存储和组织计算机数据的方法,它使得对其访问和查找变得容易. 文件名:在文件系统中,文件名是用于定位存储位置. 元数据(Metad ...

  10. 学习大数据基础框架hadoop需要什么基础

    什么是大数据?进入本世纪以来,尤其是2010年之后,随着互联网特别是移动互联网的发展,数据的增长呈爆炸趋势,已经很难估计全世界的电子设备中存储的数据到底有多少,描述数据系统的数据量的计量单位从MB(1 ...

随机推荐

  1. vue加载本地json文件

    背景:做地区跟行业级联下拉选择,因为想做成可以搜索的,所以必须一次加载数据,后台有做memcache缓存,但因为数据量大,还是比较费时间,所以做成本地文件,简单记录一下 准备数据,放到static下 ...

  2. 什么是CMD

    cmd是command的缩写.命令提示符是在操作系统中,提示进行命令输入的一种工作提示符.在不同的操作系统环境下,命令提示符各不相同. 在windows环境下,命令行程序为cmd.exe,是一个32位 ...

  3. opencv实现坐标旋转(教你框住小姐姐)

    一.项目背景 最近在做一个人脸检测项目,需要接入百度AI的系统进行识别和检测.主要流程就是往指定的URL上post图片上去,之后接收检测结果就好了. 百度的检测结果包含这样的信息: left - 人脸 ...

  4. 对xml进行数据查询时发生NoClassDefFoundError,dom4j和jaxen

    xml可扩展标记语言,标准通用标记语言的子集,是一种用于标记电子文件使其具有结构性的标记语言. 在web中,今天我本想测试一下用xml做为数据库存储用户信息,但是在查询用户信息的时候一直发生: jav ...

  5. [译]Nuget.Server

    原文 NuGet.Server是一个包,可用于使一个ASP.NET应用host一个package feed . 使用VS创建一个新的空WEB应用,添加Nuget.Server包. 配置应用的Packa ...

  6. js去掉某一属性

    将某一属性赋值为空就行了. 例如: document.getElementById('second').style.color = '';

  7. AspectJ开发

    aspectJ 是基于java语言的aop框架,提供了强大的aop功能. aspectJ的实现主要有两种,一种是基于xml的声明式aspectJ,另一种是基于注解的aspectJ. 1.基于xml的声 ...

  8. MongoDB初探-基本语句和数据结构

    MySQL: 1 金老板 18 15512351234 2 小哪吒 20 15312341234 3 Alex 73 15512341234 MongoDB: { { id : 1, name:金老板 ...

  9. luogu P3238 [HNOI2014]道路堵塞

    传送门 这什么题啊,乱搞就算了,不知道SPFA已经死了吗 不对那个时候好像还没死 暴力就是删掉边后跑Dijkstra SPFA 然后稍微分析一下,可以发现题目中要求的不经过最短路某条边的路径,一定是先 ...

  10. python 07

    1.文件操作: f=open(...) 是由操作系统打开文件,那么如果我们没有为open指定编码,那么打开文件的默认编码很明显是操作系统说了算了 操作系统会用自己的默认编码去打开文件,在windows ...