服务器架构
主机名 |
IP |
安装服务 |
mesos-master |
192.168.56.7 |
docker、mesos-master、mesos-slave、marathon、zookeeper |
mesos-slave |
192.168.56.8 |
docker、mesos-slave、zookeeper |
系统环境
# uname -r
3.10.0-229.el7.x86_64
# cat /etc/redhat-release
CentOS Linuxrelease 7.1.1503 (Core)
配置hosts
# vim /etc/hosts
192.168.56.7 mesos-master
192.168.56.8 mesos-slave
安装docker
mesos-master
安装docker
[[email protected]~]# yum install -y docker
[[email protected]~]# systemctl enable docker
[[email protected]~]# systemctl start docker
创建nginx镜像
[[email protected]~]# docker pull nginx
mesos-slave
安装docker
[[email protected]~]# yum install -y docker
[[email protected]~]# systemctl enable docker
[[email protected]~]# systemctl start docker
创建nginx镜像
[[email protected]~]# docker pull nginx
部署zookeeper
mesos-master
安装依赖
[[email protected]~]# yum install -y java-1.8.0-openjdk-devel java-1.8.0-openjdk
下载zookeeper
[[email protected]~]# mkdir /application
[email protected]~]# cd /application/
[[email protected]]# curl -O http://apache.fayea.com/zookeeper/stable/zookeeper-3.4.6.tar.gz
[[email protected]]# tar xf zookeeper-3.4.6.tar.gz
[[email protected]]# ln -s /application/zookeeper-3.4.6 /application/zookeeper
配置zookeeper
[[email protected]]# cd zookeeper/conf/
[[email protected]]# grep -v "#" zoo_sample.cfg >zoo.cfg
[[email protected]]# vim zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/application/zookeeper/data
clientPort=2181
server.1=192.168.56.7:2333:3222
server.2=192.168.56.8:2333:3222
[[email protected]]# mkdir ../data
[[email protected]]# echo 1 >../data/myid
[[email protected]]# cd
启动zookeeper
[[email protected]~]# /application/zookeeper/bin/zkServer.sh start
JMX enabled bydefault
Using config:/application/zookeeper/bin/../conf/zoo.cfg
Startingzookeeper ... STARTED
[[email protected]~]# /application/zookeeper/bin/zkServer.sh status
JMX enabled bydefault
Using config:/application/zookeeper/bin/../conf/zoo.cfg
Error contactingservice. It is probably not running.
**出现Error主要是由于mesos-slave没有启动
mesos-slave
安装依赖
[[email protected]~]# yum install -y java-1.8.0-openjdk-devel java-1.8.0-openjdk
下载zookeeper
[[email protected]~]# mkdir /application
[[email protected]~]# cd /application/
[[email protected]]# curl -O http://apache.fayea.com/zookeeper/stable/zookeeper-3.4.6.tar.gz
[[email protected]]# tar xf zookeeper-3.4.6.tar.gz
[[email protected]]# ln -s /application/zookeeper-3.4.6 /application/zookeeper
配置zookeeper
[[email protected]]# cd zookeeper/conf/
[[email protected]]# grep -v "#" zoo_sample.cfg >zoo.cfg
[[email protected]]# vim zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/application/zookeeper/data
clientPort=2181
server.1=192.168.56.7:2333:3222
server.2=192.168.56.8:2333:3222
[[email protected]]# mkdir ../data
[[email protected]]# echo 2 >../data/myid
[[email protected]]# cd
启动zookeeper
[[email protected]~]# /application/zookeeper/bin/zkServer.sh start
部署mesos、marathon
mesos-master
下载mesosphere仓库
[[email protected]~]# rpm -ivh http://repos.mesosphere.com/el/7/noarch/RPMS/mesosphere-el-repo-7-1.noarch.rpm
安装mesos marathon
[[email protected]~]# yum install -y mesos marathon
配置marathon使用mesos调用docker
[[email protected]~]# echo ‘docker,mesos‘ >/etc/mesos-slave/containerizers
启动mesos、marathon
[[email protected]~]# systemctl enable mesos-master mesos-slave marathon
[[email protected]~]# systemctl start mesos-master mesos-slave marathon
mesos-slave
下载mesosphere仓库
[[email protected]~]# rpm -ivh http://repos.mesosphere.com/el/7/noarch/RPMS/mesosphere-el-repo-7-1.noarch.rpm
安装mesos
[[email protected]~]# yum install -y mesos
添加zookeeper配置
[[email protected]~]# vim /etc/mesos/zk
zk://192.168.56.7:2181,192.168.56.8:2181/mesos
配置marathon使用mesos调用docker
[[email protected]~]# echo ‘docker,mesos‘ > /etc/mesos-slave/containerizers
启动mesos
[[email protected]~]# systemctl enable mesos-slave
[[email protected] ~]# systemctl startmesos-slave
检查mesos和marathon
在浏览器中输入http://192.168.56.7:5050看到如下图,表示mesos安装成功
在浏览器中输入http://192.168.56.7:8080看到如下图,表示marathon安装成功
使用marathon调度mesos创建docker容器
编辑json文件
[[email protected]~]# vim nginx.json
{
"id":"nginx",
"cpus":0.1,
"mem":10,
"instances": 1,
"constraints":[["hostname", "UNIQUE",""]],
"container": {
"type":"DOCKER",
"docker": {
"image": "nginx",
"network": "BRIDGE",
"portMappings": [
{"containerPort": 80,"hostPort": 0,"servicePort": 0, "protocol":"tcp" }
]
}
}
}
调用json
[[email protected] ~]# curl -X POSThttp://192.168.56.7:8080/v2/apps-d @nginx.json -H "Content-type:application/json"
查看mesos
查看marathon
使用docker查看
[[email protected]~]# docker ps
CONTAINERID IMAGE COMMAND CREATED STATUS PORTS NAMES
5df80cefaee8 nginx "nginx -g ‘daemonoff" 6 minutes ago Up 6 minutes 443/tcp, 0.0.0.0:31125->80/tcp mesos-8a9358e1-275d-46ec-ba5c-e57e0578f354-S1.071c4b7a-55d0-41f6-9259-077373fb8e18