docker_practice/mesos/installation.md

388 lines
15 KiB
Go
Raw Normal View History

2017-05-02 23:17:58 +08:00
## Mesos 使
Mesos Marathon Mesos
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
Marathon Mesos framework Scala
Mesos ZooKeeper Mesos master 3 5 使 supervisord
ZooKeeper `leader`
2015-06-29 18:20:31 +08:00
###
2017-05-02 23:17:58 +08:00
mesoszookeeper marathon
Mesos -mesos master zookeeper mesos slave marathon
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
Docker
2015-06-29 18:20:31 +08:00
####
2017-05-02 23:17:58 +08:00
apache.org
```sh
$ git clone https://git-wip-us.apache.org/repos/asf/mesos.git
2015-06-29 18:20:31 +08:00
```
2017-05-02 23:17:58 +08:00
`src` `frameworks` `docs` `include ` Mesos 使 API
Java Linux
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
```sh
$ sudo apt-get update
$ sudo apt-get install -y openjdk-8-jdk autoconf libtool \
build-essential python-dev python-boto libcurl4-nss-dev \
libsasl2-dev maven libapr1-dev libsvn-dev
2015-06-29 18:20:31 +08:00
```
2017-05-02 23:17:58 +08:00
C++ configure Makefile
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
```sh
$ cd mesos
2015-06-29 18:20:31 +08:00
$ ./bootstrap
$ mkdir build
2017-05-02 23:17:58 +08:00
$ cd build && ../configure --with-network-isolator
2015-06-29 18:20:31 +08:00
$ make
2017-05-02 23:17:58 +08:00
$ make check && sudo make install
2015-06-29 18:20:31 +08:00
```
2017-05-02 23:17:58 +08:00
####
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
Ubuntu
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
```sh
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv E56151BF
$ DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
$ CODENAME=$(lsb_release -cs)
$ echo "deb http://repos.mesosphere.io/${DISTRO} ${CODENAME} main" | \
sudo tee /etc/apt/sources.list.d/mesosphere.list
```
zookeepermesosmarathon
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
```sh
$ sudo apt-get -y update && sudo apt-get -y install zookeeper mesos marathon
2015-06-29 18:20:31 +08:00
```
2017-05-02 23:17:58 +08:00
Marathon jdk 1.8+ Java JDK
```sh
$ sudo update-alternatives --config java
```
Mesos `/usr/sbin/` `mesos-master` `mesos-slave`
`service` 便
Mesos
```sh
$ sudo service mesos-master restart
```
`service` `/usr/bin/mesos-init-wrapper`
2015-06-29 18:20:31 +08:00
#### [ Docker](https://github.com/sekka1/mesosphere-docker)
2017-05-02 23:17:58 +08:00
2015-06-29 18:20:31 +08:00
* ZooKeeperhttps://registry.hub.docker.com/u/garland/zookeeper/
* Mesoshttps://registry.hub.docker.com/u/garland/mesosphere-docker-mesos-master/
* Marathonhttps://registry.hub.docker.com/u/garland/mesosphere-docker-marathon/
2017-05-02 23:17:58 +08:00
mesos-master master slave 使
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
```sh
$ docker pull garland/zookeeper
$ docker pull garland/mesosphere-docker-mesos-master
$ docker pull garland/mesosphere-docker-marathon
2015-06-29 18:20:31 +08:00
```
2017-05-02 23:17:58 +08:00
```sh
$ HOST_IP=10.0.0.2
```
Zookeepr
```sh
2015-06-29 18:20:31 +08:00
docker run -d \
-p 2181:2181 \
-p 2888:2888 \
-p 3888:3888 \
garland/zookeeper
```
2017-05-02 23:17:58 +08:00
Mesos Master
```sh
2015-06-29 18:20:31 +08:00
docker run --net="host" \
-p 5050:5050 \
-e "MESOS_HOSTNAME=${HOST_IP}" \
-e "MESOS_IP=${HOST_IP}" \
-e "MESOS_ZK=zk://${HOST_IP}:2181/mesos" \
-e "MESOS_PORT=5050" \
-e "MESOS_LOG_DIR=/var/log/mesos" \
-e "MESOS_QUORUM=1" \
-e "MESOS_REGISTRY=in_memory" \
-e "MESOS_WORK_DIR=/var/lib/mesos" \
-d \
garland/mesosphere-docker-mesos-master
```
2017-05-02 23:17:58 +08:00
Marathon
```sh
2015-06-29 18:20:31 +08:00
docker run \
-d \
-p 8080:8080 \
garland/mesosphere-docker-marathon --master zk://${HOST_IP}:2181/mesos --zk zk://${HOST_IP}:2181/marathon
```
2017-05-02 23:17:58 +08:00
Mesos slave
```sh
2015-06-29 18:20:31 +08:00
docker run -d \
--name mesos_slave_1 \
--entrypoint="mesos-slave" \
-e "MESOS_MASTER=zk://${HOST_IP}:2181/mesos" \
-e "MESOS_LOG_DIR=/var/log/mesos" \
-e "MESOS_LOGGING_LEVEL=INFO" \
garland/mesosphere-docker-mesos-master:latest
```
访 8080 使 Marathon
###
2017-05-02 23:17:58 +08:00
2015-06-29 18:20:31 +08:00
#### ZooKeepr
2017-05-02 23:17:58 +08:00
ZooKeepr 2181 ZooKeeper
`/etc/zookeeper/conf/` `myid` `zoo.cfg`
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
myid ZooKeeper 1-255`/var/lib/zookeeper/myid`
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
1
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
```sh
$ echo 1 | sudo dd of=/etc/zookeeper/conf/myid
2015-06-29 18:20:31 +08:00
```
2017-05-02 23:17:58 +08:00
ZooKeeper
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
zoo.cfg ZooKeeper
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
ZooKeeper `10.0.0.2``10.0.0.3``10.0.0.4` `2``3``4`
```sh
server.2=10.0.0.2:2888:3888
server.3=10.0.0.3:2888:3888
server.4=10.0.0.4:2888:3888
```
2888 3888
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
`/etc/hosts`
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
ZooKeeper
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
```sh
$ sudo service zookeeper start
2015-06-29 18:20:31 +08:00
```
2017-05-02 23:17:58 +08:00
#### Mesos
Mesos
* /etc/mesos/ zk
* /etc/mesos-master/ mesos-master
* /etc/mesos-slave/ mesos-master
`/etc/mesos/zk` ZooKeeper
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
```sh
zk://10.0.0.2:2181,10.0.0.3:2181,10.0.0.4:2181/mesos
2015-06-29 18:20:31 +08:00
```
2017-05-02 23:17:58 +08:00
`/etc/default/mesos``/etc/default/mesos-master``/etc/default/mesos-slave` Mesos `MESOS_OPTION_NAME`
#####
`/etc/mesos-master/`
mesos-master `mesos-master --help`
`key` `value` mesos-master `--key=value`
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
mesos-master loopback `127.0.0.1:5050` /etc/mesos-master/ip
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
mesos-master `work_dir` () /etc/mesos-master/work_dir ` /var/lib/mesos` `replicated_log`
quorum ZooKeeper ZooKeeper `2`
Mesos `/etc/mesos-master/cluster` `MesosCluster`
`/etc/mesos-master` `ip``quorum``work_dir``cluster`
```sh
$ sudo service mesos-master start
2015-06-29 18:20:31 +08:00
```
2017-05-02 23:17:58 +08:00
mesos-slave
#####
`/etc/mesos-slave/`
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
`/etc/mesos-slave/ip`
```sh
$ sudo service mesos-slave start
```
2015-06-29 18:20:31 +08:00
#### Marathon
2017-05-02 23:17:58 +08:00
Marathon Mesos `--master` `--zk`
/usr/bin marathon shell marathon
`/etc/marathon/conf` `/etc/default/marathon`
Mesos Marathon Mesos
```sh
$ sudo mkdir -p /etc/marathon/conf
$ sudo cp /etc/mesos/zk /etc/marathon/conf/master
```
Marathon ZooKeeper `/etc/marathon/conf/zk` ZooKeeper
```sh
zk://10.0.0.2:2181,10.0.0.2:2181,10.0.0.2:2181/marathon
```
2015-06-29 18:20:31 +08:00
marathon
2017-05-02 23:17:58 +08:00
```sh
$ sudo service marathon start
2015-06-29 18:20:31 +08:00
```
2017-05-02 23:17:58 +08:00
### 访 Mesos
Mesos Web 便
Mesos 访 5050 slave
![mesos slave ](_images/mesos.png)
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
Slaves
2015-06-29 18:20:31 +08:00
2017-05-02 23:17:58 +08:00
Marathon Frameworks
### 访 Marathon
Marathon Mesos web Frameworks marathon
访 8080 Marathon
![marathon ](_images/marathon.png)
2015-06-29 18:20:31 +08:00
REST API Marathon
2017-05-02 23:17:58 +08:00
![marathon ](_images/marathon_basic0.png)
使 Marathon REST API
JSON API
basic-0
```json
{
"id": "basic-0",
"cmd": "while [ true ] ; do echo 'Hello Marathon' ; sleep 5 ; done",
"cpus": 0.1,
"mem": 10.0,
"instances": 1
}
```
0.1 CPU 10 MB shell `Hello Marathon`
basic-0 Marathon json
```sh
$ curl -X POST http://marathon_host:8080/v2/apps -d @basic-0.json -H "Content-type: application/json"
{"id":"/basic-0","cmd":"while [ true ] ; do echo 'Hello Marathon' ; sleep 5 ; done","args":null,"user":null,"env":{},"instances":1,"cpus":0.1,"mem":10,"disk":0,"executor":"","constraints":[],"uris":[],"storeUrls":[],"ports":[0],"requirePorts":false,"backoffSeconds":1,"backoffFactor":1.15,"maxLaunchDelaySeconds":3600,"container":null,"healthChecks":[],"dependencies":[],"upgradeStrategy":{"minimumHealthCapacity":1,"maximumOverCapacity":1},"labels":{},"acceptedResourceRoles":null,"version":"2015-12-28T05:33:05.805Z","tasksStaged":0,"tasksRunning":0,"tasksHealthy":0,"tasksUnhealthy":0,"deployments":[{"id":"3ec3fbd5-11e4-479f-bd17-813d33e43e0c"}],"tasks":[]}%
```
Marathon REST API `http://marathon_host:8080/api-console/index.html`
Docker Mesos slave slave `--containerizers=docker,mesos`
```json
{
"id": "basic-3",
"cmd": "python3 -m http.server 8080",
"cpus": 0.5,
"mem": 32.0,
"container": {
"type": "DOCKER",
"volumes": [],
"docker": {
"image": "python:3",
"network": "BRIDGE",
"portMappings": [
{
"containerPort": 8080,
"hostPort": 31000,
"servicePort": 0,
"protocol": "tcp"
}
],
"privileged": false,
"parameters": [],
"forcePullImage": true
}
}
}
```
`python:3` `python3 -m http.server 8080` web 宿 31000
hostPort servicePort Mesos slave 31000 ~ 32000使 Marathon
slave Docker `mesos-SLAVE_ID`
```sh
$ docker container ls
2017-05-02 23:17:58 +08:00
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1226b4ec8d7d python:3 "/bin/sh -c 'python3 " 3 days ago Up 3 days 0.0.0.0:10000->8080/tcp mesos-06db0fba-49dc-4d28-ad87-6c2d5a020866-S10.b581149e-2c43-46a2-b652-1a0bc10204b3
```