1) docker pull mesosphere/marathon-lbnginx
marathon-lb的鏡像配置json文件 重命名爲marathon-lb.json { "id": "marathon-lb", "instances": 1, "constraints": [["hostname", "UNIQUE"]], "container": { "type": "DOCKER", "docker": { "image": "docker.io/mesosphere/marathon-lb", "privileged": true, "network": "HOST" } }, "args": ["sse", "-m","http://master1_ip:8080","--group", "external"] } 部署 curl -i -H 'Content-Type: application/json' 172.31.17.71:8080/v2/apps -d@marathon-lb.json
注意裏面的master1_ip是marathon的ipgit
注意group後面的external參數github
這時候回過頭來看docker_nginx.json文件docker
[root@centos7 mywork]# cat docker_nginx.json { "id":"nginx", "labels": { "HAPROXY_GROUP":"external", "HAPROXY_0_VHOST":"nginx.marathon.mesos" }, "cpus":0.2, "mem":20.0, "instances": 2, "healthChecks": [{ "path": "/" }], "container": { "type":"DOCKER", "docker": { "image": "nginx", "network": "BRIDGE", "portMappings":[{"containerPort":80,"hostPort":0,"servicePort":80,"protocol":"tcp"}] } } }
注意json
1) containerPort爲80,是指容器內的端口後端
2) hostPort是當前主機映射到contenterPort的端口,對應的.centos
56fc5bb6d80d nginx "nginx -g 'daemon off" 10 minutes ago Up 10 minutes 443/tcp, 0.0.0.0:31757->80/tcp mesos-c3bcff71-e3ac-455f-b228-e350f7aa5035-S0.5914a1f4-378e-4b7d-a19d-caf07a563c9d
若是hostPort爲0的話,則說明是隨機的,app
3) serverPort是marathon-lb須要配置的haproxy代理暴露的端口,則設置爲80.frontend
這時候進入marathon-lb的容器裏面,查看生成的haproxy.cfg文件curl
這是最後面一段新生成的
frontend nginx_80 bind *:80 mode http use_backend nginx_80 backend nginx_80 balance roundrobin mode http option forwardfor http-request set-header X-Forwarded-Port %[dst_port] http-request add-header X-Forwarded-Proto https if { ssl_fc } option httpchk GET / timeout check 20s server centos7_1_10_57_137_131_31757 10.57.137.131:31757 check inter 60s fall 4 server centos7_1_10_57_137_131_31834 10.57.137.131:31834 check inter 60s fall 4
這時候訪問haproxy的80端口,則是請求到後端的2臺nginx的主機上了.
4) 查看haproxy的監控頁面
查看方法
Marathon-lb exposes a few endpoints on port 9090 (by default). They are:
Endpoint | Description |
---|---|
:9090/haproxy?stats |
HAProxy stats endpoint. This produces an HTML page which can be viewed in your browser, providing various statistics about the current HAProxy instance. |
:9090/haproxy?stats;csv |
This is a CSV version of the stats above, which can be consumed by other tools. For example, it's used in the zdd.py script. |
:9090/_haproxy_health_check |
HAProxy health check endpoint. Returns 200 OK if HAProxy is healthy. |
:9090/_haproxy_getconfig |
Returns the HAProxy config file as it was when HAProxy was started. Implemented ingetconfig.lua . |
:9090/_haproxy_getpids |
Returns the PIDs for all HAProxy instances within the current process namespace. This literally returns $(pidof haproxy) . Implemented in getpids.lua . This is also used by the zdd.py script to determine if connections have finished draining during a deploy. |
最痛苦的就是docker pull ,太慢了....