用Docker、Vagrant搭建Mesos实验环境
1.准备实验环境
主机名 | IP | 内存 | CPU核心 | 角色 | Docker镜像 |
MesosMaster1 | 172.30.1.101 | 4G | 2 | 主 |
mesos-master zookeeper marathon |
MesosSlave1 | 172.30.1.111 | 2G | 4 | 从 | mesos-slave |
vagrant配置
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box="centos/7"
config.ssh.insert_key = false
config.vm.provision "shell", inline: "ifup eth1"
config.vm.define "MesosMaster1" do |config|
config.vm.hostname="MesosMaster1"
config.vm.network "private_network", ip: "172.30.1.101"
config.vm.provider "virtualbox" do |v|
v.memory = 4096
v.cpus = 2
end
end
config.vm.define "MesosSlave1" do |config|
config.vm.hostname="MesosSlave1"
config.vm.network "private_network", ip: "172.30.1.111"
config.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 4
end
end
end
SSH登录虚拟机
# 所有节点
curl -fsSL https://get.docker.com/ | sh && systemctl start docker && systemctl status docker
curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
# 主节点
docker pull mesosphere/mesos-master:1.7.1 && docker pull zookeeper:3.4.14 && docker pull mesosphere/marathon:v1.9.34
# 从节点
docker pull mesosphere/mesos-slave:1.7.1
2.搭建Mesos + Marathon + Docker
主节点下载 https://github.com/mesosphere/marathon-ui/tree/master/resources 目录到docker-compose.xml目录
主节点docker-compose.yml
version: "2"
services:
zookeeper:
network_mode: host
image: zookeeper:3.4.14
hostname: zookeeper
restart: always
container_name: zookeeper
ports:
- "2181:2181"
mesos-master:
network_mode: host
image: mesosphere/mesos-master:1.7.1
hostname: mesos-master
restart: always
container_name: mesos-master
entrypoint: [ "mesos-master" ]
ports:
- "5050:5050"
depends_on:
- zookeeper
environment:
- MESOS_CLUSTER=local
- MESOS_HOSTNAME=mesos-master.docker
- MESOS_LOG_DIR=/var/log
- MESOS_QUORUM=1
- MESOS_WORK_DIR=/var/lib/mesos
- MESOS_ROLES=public
- MESOS_ZK=zk://zookeeper:2181/mesos
- MESOS_ACLS=file:///mesos-config/acls
- MESOS_CREDENTIALS=file:///mesos-config/credentials
volumes:
- ./resources/mesos-config:/mesos-config
mesos-slave:
image: mesosphere/mesos-slave:1.7.1
network_mode: host
restart: always
entrypoint:
- mesos-slave
privileged: true
hostname: mesos-slave
container_name: mesos-slave
ports:
- "5051:5051"
depends_on:
- zookeeper
- mesos-master
environment:
- MESOS_SYSTEMD_ENABLE_SUPPORT=false
- MESOS_CONTAINERIZERS=docker
- MESOS_ISOLATOR=cgroups/cpu, cgroups/mem
- MESOS_LOG_DIR=var/log
- MESOS_MASTER=zk://zookeeper:2181/mesos
- MESOS_PORT=5051
- MESOS_WORK_DIR=/var/lib/mesos
- MESOS_EXECUTOR_REGISTRATION_TIMEOUT=5mins
- MESOS_EXECUTOR_SHUTDOWN_GRACE_PERIOD=90secs
- MESOS_DOCKER_STOP_TIMEOUT=60secs
- MESOS_RESOURCES=cpus:4;mem:1280;disk:25600;ports(*):[12000-12999]
volumes:
- /var/run/docker.sock:/var/run/docker.sock
marathon:
image: mesosphere/marathon:v1.9.34
network_mode: host
restart: always
hostname: marathon
container_name: marathon
ports:
- "8080:8080"
depends_on:
- zookeeper
- mesos-master
environment:
- MARATHON_ZK=zk://zookeeper:2181/marathon
- MARATHON_MASTER=zk://zookeeper:2181/mesos
- MARATHON_DECLINE_OFFER_DURATION=3600000
- MARATHON_PLUGIN_DIR=/plugins
- MARATHON_PLUGIN_CONF=/plugin-conf.json
- MARATHON_MESOS_AUTHENTICATION_PRINCIPAL=marathon
- MARATHON_MESOS_AUTHENTICATION_SECRET_FILE=/marathon.secret
- MARATHON_MESOS_ROLE=public
volumes:
- ./resources/marathon-plugins:/plugins
- ./resources/marathon.plugin-conf.json:/plugin-conf.json
- ./resources/marathon.secret:/marathon.secret
从节点docker-compose.yml
version: "2"
services:
mesos-slave:
image: mesosphere/mesos-slave:1.7.1
network_mode: host
restart: always
entrypoint:
- mesos-slave
privileged: true
hostname: mesos-slave1
container_name: mesos-slave
ports:
- "5051:5051"
environment:
- MESOS_SYSTEMD_ENABLE_SUPPORT=false
- MESOS_CONTAINERIZERS=docker
- MESOS_ISOLATOR=cgroups/cpu, cgroups/mem
- MESOS_LOG_DIR=var/log
- MESOS_MASTER=172.30.1.101:5050
- MESOS_IP=172.30.1.111
- MESOS_PORT=5051
- MESOS_WORK_DIR=/var/lib/mesos
- MESOS_EXECUTOR_REGISTRATION_TIMEOUT=5mins
- MESOS_EXECUTOR_SHUTDOWN_GRACE_PERIOD=90secs
- MESOS_DOCKER_STOP_TIMEOUT=60secs
- MESOS_RESOURCES=cpus:4;mem:1280;disk:25600;ports(*):[12000-12999]
volumes:
- /var/run/docker.sock:/var/run/docker.sock
3.创建无状态服务
浏览器打开 http://172.30.1.101:8080/ui/#/apps
随便创建一个应用,可以观察从节点行为(应用经常重启,好像是docker状态丢失).
4.总结
因为是实验环境,有一些报错也就不深入研究了,毕竟学了就忘,用了才能记住