docker_practice/mesos/installation.md

388 lines
15 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

## Mesos 使
Mesos Marathon Mesos
Marathon Mesos framework Scala
Mesos ZooKeeper Mesos master 3 5 使 supervisord
ZooKeeper `leader`
###
mesoszookeeper marathon
Mesos -mesos master zookeeper mesos slave marathon
Docker
####
apache.org
```sh
$ git clone https://git-wip-us.apache.org/repos/asf/mesos.git
```
`src` `frameworks` `docs` `include ` Mesos 使 API
Java Linux
```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
```
C++ configure Makefile
```sh
$ cd mesos
$ ./bootstrap
$ mkdir build
$ cd build && ../configure --with-network-isolator
$ make
$ make check && sudo make install
```
####
Ubuntu
```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
```sh
$ sudo apt-get -y update && sudo apt-get -y install zookeeper mesos marathon
```
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`
#### [ Docker](https://github.com/sekka1/mesosphere-docker)
* 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/
mesos-master master slave 使
```sh
$ docker pull garland/zookeeper
$ docker pull garland/mesosphere-docker-mesos-master
$ docker pull garland/mesosphere-docker-marathon
```
```sh
$ HOST_IP=10.0.0.2
```
Zookeepr
```sh
docker run -d \
-p 2181:2181 \
-p 2888:2888 \
-p 3888:3888 \
garland/zookeeper
```
Mesos Master
```sh
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
```
Marathon
```sh
docker run \
-d \
-p 8080:8080 \
garland/mesosphere-docker-marathon --master zk://${HOST_IP}:2181/mesos --zk zk://${HOST_IP}:2181/marathon
```
Mesos slave
```sh
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
###
#### ZooKeepr
ZooKeepr 2181 ZooKeeper
`/etc/zookeeper/conf/` `myid` `zoo.cfg`
myid ZooKeeper 1-255`/var/lib/zookeeper/myid`
1
```sh
$ echo 1 | sudo dd of=/etc/zookeeper/conf/myid
```
ZooKeeper
zoo.cfg ZooKeeper
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
`/etc/hosts`
ZooKeeper
```sh
$ sudo service zookeeper start
```
#### Mesos
Mesos
* /etc/mesos/ zk
* /etc/mesos-master/ mesos-master
* /etc/mesos-slave/ mesos-master
`/etc/mesos/zk` ZooKeeper
```sh
zk://10.0.0.2:2181,10.0.0.3:2181,10.0.0.4:2181/mesos
```
`/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`
mesos-master loopback `127.0.0.1:5050` /etc/mesos-master/ip
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
```
mesos-slave
#####
`/etc/mesos-slave/`
`/etc/mesos-slave/ip`
```sh
$ sudo service mesos-slave start
```
#### Marathon
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
```
marathon
```sh
$ sudo service marathon start
```
### 访 Mesos
Mesos Web 便
Mesos 访 5050 slave
![mesos slave ](_images/mesos.png)
Slaves
Marathon Frameworks
### 访 Marathon
Marathon Mesos web Frameworks marathon
访 8080 Marathon
![marathon ](_images/marathon.png)
REST API Marathon
![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
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
```