mac实战mesos

如果程序一直deploy说明一定有问题
mac安装

1
2
brew install mesos
brew upgrade mesos

启动zookeeper
启动master

1
2
3
4
HOST_IP=100.80.128.98
sudo /usr/local/Cellar/mesos/1.4.1/sbin/mesos-master --ip=${HOST_IP} \
--log_dir=/Users/lifei/dockerproject/mesos/master/log --work_dir=/Users/lifei/dockerproject/mesos/master/work \
--ZK=zk://${HOST_IP}:2181/mesos --quorum=1

启动slave(注意端口,如果marathon中用到80等端口,需要将ports范围足够大)

1
2
3
4
5
6
7
8
9
10
/usr/local/Cellar/mesos/1.4.1/sbin/mesos-slave --help  查看帮助
启动第一个slave
sudo /usr/local/Cellar/mesos/1.4.1/sbin/mesos-slave --master=${HOST_IP}:5050 \
--log_dir=/Users/lifei/dockerproject/mesos/slave/log --work_dir=/Users/lifei/dockerproject/mesos/slave/work \
--containerizers=docker,mesos --no-hostname_lookup --ip=${HOST_IP} --resources='ports:[1-32000];'

启动第二个slave
sudo /usr/local/Cellar/mesos/1.4.1/sbin/mesos-slave --master=${HOST_IP}:5050 \
--log_dir=/Users/lifei/dockerproject/mesos/slave/log2 --work_dir=/Users/lifei/dockerproject/mesos/slave/work2 \
--containerizers=docker,mesos --no-hostname_lookup --ip=${HOST_IP} --resources='ports:[1-32000];'

测试task

1
/usr/local/Cellar/mesos/1.4.1/bin/mesos-execute --master=localhost:5050 --name=hellomesos --command="echo 'hello,mesos'"

启动marathon

1
sudo ./bin/start --http_port 8088 --master ${HOST_IP}:5050 --zk zk://${HOST_IP}:2181/marathon -h ${HOST_IP}

测试marathon

1
2
3
Command

while [ true ] ; do echo 'Hello Marathon' ; sleep 5 ; done

从marathon中使用docker启动nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"type": "DOCKER",
"volumes": [],
"docker": {
"image": "library/nginx",
"network": "BRIDGE",
"portMappings": [
{
"containerPort": 80,
"hostPort": 0,
"servicePort": 2000,
"protocol": "tcp",
"labels": {}
}
],
"privileged": false,
"parameters": [],
"forcePullImage": false
}
}

使用docker inspect containerid,查看动态分配的hostport
ps:在container里边, 这个web服务运行的端口是8080(containerPort的值)。在container外,Marathon会分配一个随机端口(hostPort设置是0)

marathon-lb安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
采用bridge方式,host方式失败,不明白问题在哪儿**********
{
"id": "/marathon-lb",
"cmd": null,
"cpus": 1,
"mem": 128,
"disk": 0,
"instances": 1,
"constraints": [
[
"hostname",
"UNIQUE"
]
],
"container": {
"type": "DOCKER",
"volumes": [
{
"containerPath": "/var",
"hostPath": "/Users/lifei/dockerproject/marathon/marathon-lb-var",
"mode": "RW"
},
{
"containerPath": "/tmp",
"hostPath": "/Users/lifei/dockerproject/marathon/marathon-lb-tmp",
"mode": "RW"
}
],
"docker": {
"image": "docker.io/mesosphere/marathon-lb",
"network": "BRIDGE",
"portMappings": [
{
"containerPort": 80,
"hostPort": 80,
"servicePort": 10001,
"protocol": "tcp",
"labels": {}
},
{
"containerPort": 9090,
"hostPort": 9090,
"servicePort": 10002,
"protocol": "tcp",
"labels": {}
}
],
"privileged": true,
"parameters": [],
"forcePullImage": false
}
},
"portDefinitions": [
{
"port": 10001,
"protocol": "tcp",
"labels": {}
},
{
"port": 10002,
"protocol": "tcp",
"labels": {}
}
],
"args": [
"sse",
"-m",
"http://100.80.128.98:8088",
"--group",
"external"
]
}

测试marathon-lb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{
"id": "/test-lb-nginx",
"cmd": null,
"cpus": 0.2,
"mem": 20,
"disk": 0,
"instances": 2,
"container": {
"type": "DOCKER",
"volumes": [],
"docker": {
"image": "docker.io/nginx",
"network": "BRIDGE",
"portMappings": [
{
"containerPort": 80,
"hostPort": 0,
"servicePort": 80,
"protocol": "tcp",
"labels": {}
}
],
"privileged": false,
"parameters": [],
"forcePullImage": false
}
},
"healthChecks": [
{
"path": "/",
"protocol": "HTTP",
"portIndex": 0,
"gracePeriodSeconds": 300,
"intervalSeconds": 60,
"timeoutSeconds": 20,
"maxConsecutiveFailures": 3,
"ignoreHttp1xx": false
}
],
"labels": {
"HAPROXY_GROUP": "external",
"HAPROXY_0_VHOST": "nginx.marathon.mesos"
},
"portDefinitions": [
{
"port": 80,
"protocol": "tcp",
"labels": {}
}
]
}

测试url

1
2
http://100.80.128.98:9090/haproxy?stats
http://100.80.128.98