虚拟机使用ubuntu/trusty64镜像
vagrant init ubuntu/trusty64
vagrant up
启动后安装docker, 参见https://docs.docker.com/engine/installation/linux/ubuntulinux/
# docker version
Version: 1.10.3
拉取mesoscloud的docker image
docker pull mesoscloud/mesos-master
docker pull mesoscloud/mesos-slave
docker pull mesoscloud/marathon
docker pull mesoscloud/zookeeper
创建docker网络(后面的操作不能用bridge网络)
docker network create --subnet 172.18.0.1/16 mybridge
启动zookeeper1/2/3
# docker run -d -P --net=mybridge \
-e MYID=1 --ip 172.18.0.11 --name=zookeeper1 \
-e SERVERS=node-1,node-2,node-3 \
--add-host=node-1:172.18.0.11 --add-host=node-2:172.18.0.12 --add-host=node-3:172.18.0.13 \
--restart=always mesoscloud/zookeeper
# docker run -d -P --net=mybridge \
-e MYID=2 --ip 172.18.0.12 --name=zookeeper2 \
-e SERVERS=node-1,node-2,node-3 \
--add-host=node-1:172.18.0.11 --add-host=node-2:172.18.0.12 --add-host=node-3:172.18.0.13 \
--restart=always mesoscloud/zookeeper
# docker run -d -P --net=mybridge \
-e MYID=3 --ip 172.18.0.13 --name=zookeeper3 \
-e SERVERS=node-1,node-2,node-3 \
--add-host=node-1:172.18.0.11 --add-host=node-2:172.18.0.12 --add-host=node-3:172.18.0.13 \
--restart=always mesoscloud/zookeeper
运行mesos-master1
# docker run -d -P --net mybridge \
--ip 172.18.0.21 --name mesos-master1 \
-e MESOS_HOSTNAME=172.18.0.21 -e MESOS_IP=172.18.0.21 \
-e MESOS_QUORUM=1 \
-e MESOS_ZK=zk://node-1:2181,node-2:2181,node-3:2181/mesos \
--add-host=node-1:172.18.0.11 --add-host=node-2:172.18.0.12 --add-host=node-3:172.18.0.13 \
--restart always mesoscloud/mesos-master
运行mesos-master2
# docker run -d -P --net mybridge \
--ip 172.18.0.22 --name mesos-master2 \
-e MESOS_HOSTNAME=172.18.0.22 -e MESOS_IP=172.18.0.22 \
-e MESOS_QUORUM=2 \
-e MESOS_ZK=zk://node-1:2181,node-2:2181,node-3:2181/mesos \
--add-host=node-1:172.18.0.11 --add-host=node-2:172.18.0.12 --add-host=node-3:172.18.0.13 \
--restart always mesoscloud/mesos-master
运行mesos-slave1/2/3
# docker run -d -P --net mybridge \
--name mesos-slave1 --ip 172.18.0.31 \
-e MESOS_HOSTNAME=172.18.0.31 -e MESOS_IP=172.18.0.31 \
-e MESOS_MASTER=zk://node-1:2181,node-2:2181,node-3:2181/mesos \
--add-host=node-1:172.18.0.11 --add-host=node-2:172.18.0.12 --add-host=node-3:172.18.0.13 \
-v /sys/fs/cgroup:/sys/fs/cgroup \ ???
-v /var/run/docker.sock:/var/run/docker.sock \ ??? 容器内的docker和host的容器服务通讯,在本测试中不合适
--privileged --restart always mesoscloud/mesos-slave
# docker run -d -P --net mybridge \
--name mesos-slave2 --ip 172.18.0.32 \
-e MESOS_HOSTNAME=172.18.0.32 -e MESOS_IP=172.18.0.32 \
-e MESOS_MASTER=zk://node-1:2181,node-2:2181,node-3:2181/mesos \
--add-host=node-1:172.18.0.11 --add-host=node-2:172.18.0.12 --add-host=node-3:172.18.0.13 \
-v /sys/fs/cgroup:/sys/fs/cgroup \
-v /var/run/docker.sock:/var/run/docker.sock \
--privileged --restart always mesoscloud/mesos-slave
# docker run -d -P --net mybridge \
--name mesos-slave3 --ip 172.18.0.33 \
-e MESOS_HOSTNAME=172.18.0.33 -e MESOS_IP=172.18.0.33 \
-e MESOS_MASTER=zk://node-1:2181,node-2:2181,node-3:2181/mesos \
--add-host=node-1:172.18.0.11 --add-host=node-2:172.18.0.12 --add-host=node-3:172.18.0.13 \
-v /sys/fs/cgroup:/sys/fs/cgroup \
-v /var/run/docker.sock:/var/run/docker.sock \
--privileged --restart always mesoscloud/mesos-slave
运行marathon
# docker run -d --net mybridge \
--name marathon --ip 172.18.0.41 \
-e MARATHON_HOSTNAME=172.18.0.41 \
-e MARATHON_HTTPS_ADDRESS=172.18.0.41 \
-e MARATHON_HTTP_ADDRESS=172.18.0.41 \
--add-host=node-1:172.18.0.11 --add-host=node-2:172.18.0.12 --add-host=node-3:172.18.0.13 \
-e MARATHON_MASTER=zk://node-1:2181,node-2:2181,node-3:2181/mesos \
-e MARATHON_ZK=zk://node-1:2181,node-2:2181,node-3:2181/marathon \
--restart always mesoscloud/marathon
访问控制界面
vagrant使用默认的端口映射(Forwarded port)方式,Vagrantfile加上
config.vm.network "forwarded_port", guest: 5050, host: 5050
config.vm.network "forwarded_port", guest: 8080, host: 5051
再在虚拟机中安装nginx反向代理到docker
server {
listen 5050;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://172.18.0.21:5050;
}
}
server {
listen 8080;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://172.18.0.41:8080;
}
}
在host中访问mesos和marathon
http://127.0.0.1:5050
http://127.0.0.1:5051
通过marathon部署任务
点“+New App”按钮,弹出对话框,输入Command:python -m SimpleHTTPServer 9977, Instances:2
启动一个web程序,2个实例
TODO
部署docker image任务 ? (mesoscloud/mesos-slave 中有docker , 用多个虚拟机?)
haproxy ?
多mesos-master