Mesos —— 像用一台电脑(一个资源池)一样使用整个数据中心
分布式操作系统内核
Mesos是以与Linux内核同样的原则而创建的,不同点仅仅是在于抽象的层面。Mesos内核运行在每一个机器上,同时通过 API 为各种应用提供跨数据中心和云的资源管理调度能力。这些应用包括Hadoop、Spark、Kafka、Elastic Search。还可配合框架 Marathon 来管理大规模的Docker等容器化应用。
本篇内容翻译自http://mesos.apache.org/
Host | IP | 作用 |
---|---|---|
mesos-01 | 172.20.201.101 | master,slave1,marathon |
mesos-02 | 172.20.201.102 | slave2 |
mesos-03 | 172.20.201.103 | slave3 |
$num_instances = 3
$vm_gui = false
$vm_memory = 1024
$vm_cpus = 1
$instance_name_prefix = "mesos"
$vb_cpuexecutioncap = 100
def vm_gui
$vb_gui.nil? ? $vm_gui : $vb_gui
end
def vm_memory
$vb_memory.nil? ? $vm_memory : $vb_memory
end
def vm_cpus
$vb_cpus.nil? ? $vm_cpus : $vb_cpus
end
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
(1..$num_instances).each do |i|
config.vm.define vm_name = "%s-%02d" % [$instance_name_prefix, i] do |config|
config.vm.hostname = vm_name
config.vm.provider :virtualbox do |vb|
vb.gui = vm_gui
vb.memory = vm_memory
vb.cpus = vm_cpus
vb.customize ["modifyvm", :id, "--cpuexecutioncap", "#{$vb_cpuexecutioncap}"]
end
ip = "172.20.201.#{i+100}"
config.vm.network :private_network, ip: ip
# config.vm.synced_folder "./data", "/vagrant_data"
end
config.vm.provision "shell", inline: <<-SHELL
# apt-get update
curl -s https://get.docker.com/ | sudo sh
SHELL
end
end
vagrant up
vagrant ssh mesos-01
进入mesos-01后,执行以下操作:
sudo yum install docker-io
sudo yum -y install epel-release
sudo yum -y install python-pip
pip install docker-compose
service docker start
docker run --name zookeeper --restart always -d -p 2181:2181 zookeeper
sudo docker run -d --net=host --name mesos_master -e MESOS_PORT=5050 -e MESOS_ZK=zk://172.20.201.101:2181/mesos -e MESOS_QUORUM=1 -e MESOS_REGISTRY=in_memory -e MESOS_LOG_DIR=/var/log/mesos -e MESOS_WORK_DIR=/var/tmp/mesos -v "$(pwd)/log/mesos:/var/log/mesos" -v "$(pwd)/tmp/mesos:/var/tmp/mesos" mesosphere/mesos-master:1.1.0-2.0.107.ubuntu1404 --ip=172.20.201.101 --advertise_ip=172.20.201.101
sudo docker run -d --net=host --privileged --name mesos_slave -e MESOS_PORT=5051 -e MESOS_MASTER=zk://172.20.201.101:2181/mesos -e MESOS_SWITCH_USER=0 -e MESOS_CONTAINERIZERS=docker,mesos -e MESOS_LOG_DIR=/var/log/mesos -e MESOS_WORK_DIR=/var/tmp/mesos -v "$(pwd)/log/mesos:/var/log/mesos" -v "$(pwd)/tmp/mesos:/var/tmp/mesos" -v /var/run/docker.sock:/var/run/docker.sock -v /sys/fs/cgroup:/cgroup -v /sys:/sys -v /usr/bin/docker:/usr/local/bin/docker mesosphere/mesos-slave:1.1.0-2.0.107.ubuntu1404 --ip=172.20.201.101 --launcher=posix
sudo docker run -d --net=host --privileged --name mesos_marathon mesosphere/marathon:latest --master zk://172.20.201.101:2181/mesos --zk zk://172.20.201.101:2181/marathon --http_port 8080 —http_address 172.20.201.101
启动成功后访问http://172.20.201.101:5050
按照mesos-01中命令安装docker、docker-compose、pip、docker启动
sudo docker run -d --net=host --privileged --name mesos_slave -e MESOS_PORT=5051 -e MESOS_MASTER=zk://172.20.201.101:2181/mesos -e MESOS_SWITCH_USER=0 -e MESOS_CONTAINERIZERS=docker,mesos -e MESOS_LOG_DIR=/var/log/mesos -e MESOS_WORK_DIR=/var/tmp/mesos -v "$(pwd)/log/mesos:/var/log/mesos" -v "$(pwd)/tmp/mesos:/var/tmp/mesos" -v /var/run/docker.sock:/var/run/docker.sock -v /sys/fs/cgroup:/cgroup -v /sys:/sys -v /usr/bin/docker:/usr/local/bin/docker mesosphere/mesos-slave:1.1.0-2.0.107.ubuntu1404 --ip=172.20.201.102 --launcher=posix
sudo docker run -d --net=host --privileged --name mesos_slave -e MESOS_PORT=5051 -e MESOS_MASTER=zk://172.20.201.101:2181/mesos -e MESOS_SWITCH_USER=0 -e MESOS_CONTAINERIZERS=docker,mesos -e MESOS_LOG_DIR=/var/log/mesos -e MESOS_WORK_DIR=/var/tmp/mesos -v "$(pwd)/log/mesos:/var/log/mesos" -v "$(pwd)/tmp/mesos:/var/tmp/mesos" -v /var/run/docker.sock:/var/run/docker.sock -v /sys/fs/cgroup:/cgroup -v /sys:/sys -v /usr/bin/docker:/usr/local/bin/docker mesosphere/mesos-slave:1.1.0-2.0.107.ubuntu1404 --ip=172.20.201.103 --launcher=posix
安装完成后,打开地址http://172.20.201.101:5050,打开如下页面:
打开marathon地址http://172.20.201.101:8080,显示如下:
sudo docker logs mesos-slave 查看日志
SELinux: Could not open policy file <= /etc/selinux/targeted/policy/policy.31: No such file or directory
Failed to create a containerizer: Could not create DockerContainerizer: Failed to create docker: Failed to get docker version: Failed to execute 'docker -H unix:///var/run/docker.sock --version': exited with status 2