大数据基础之Marathon(2)marathon-lb
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
如果不想绑定80和443端口,启动参数中增加 --dont-bind-http-https,即
sse -m http://marathon1_ip:8080 -m http://marathon2_ip:8080 -m http://master3_ip:8080 --group external --dont-bind-http-https
访问: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 getconfigacl 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
请注意不要直接访问9090端口,否则是这样的
# curl http://localhost:9090 <html><body><h1>503 Service Unavailable</h1> No server is available to handle this request. </body></html>
其实marathon-lb已经正常启动;
参考:
https://docs.mesosphere.com/services/marathon-lb/
https://mesosphere.github.io/marathon/docs/service-discovery-load-balancing.html
相关文章
- 【测试基础】每天这么忙,到底写不写测试用例?
- JAVA面试中的SSM框架基础面试题[通俗易懂]
- 存储数据的基础存储数组
- 3.Jenkins进阶之流水线pipeline基础使用实践
- web基础知识_Web开发基础
- H3C | 设备基础命令
- 大数据必学Java基础(七十八):线程安全问题
- 大数据必学Java基础(八十二):基于UDP的网络编程
- 猿创征文|数据导入与预处理-第3章-pandas基础
- pandas基础:数据显示格式转换
- (四)算法基础——二分算法
- 大数据必学Java基础(九十五):预编译语句对象
- 干货 | 数字经济创新创业——数据是数字经济的基础
- MySql基础-笔记12 -重复数据处理、SQL注入、导入导出数据
- 【愚公系列】2023年03月 其他-Web前端基础面试题(CSS_42道)
- IM开发者的零基础通信技术入门(十一):为什么WiFi信号差?一文即懂!
- Linux基础权限管理
- 以数据为中心的数据安全基础能力建设探索
- Oracle基础学习之子查询
- 【Hadoop基础】hadoop fs 命令详解大数据
- JavaScript基础详解编程语言
- xhEditor入门基础详解编程语言
- 高效率的 Oracle 数据工程师:卓越表现的基础(oracle数据工程师)
- Redis语法入门:学习使用它的基础(redis的语法)
- 建立Oracle中间库给数据传递奠定基础(oracle中间库建立)
- Redis入门零基础学习视频教程(redis零基础教学视频)