一. 簡介
二. 搭建Mesos/Marathon集群
三. 測(cè)試Mesos/Marathon集群
四. 存在的問題
五. 其他
六. 參考
一. 簡介
Mesos是集群資源管理系統(tǒng),Marathon是運(yùn)行在Mesos之上的集群計(jì)算架構(gòu)。將Mesos和Marathon打包到Docker鏡像中,開發(fā)者便可以在本機(jī)上快速搭建Mesos/Marathon集群,進(jìn)行學(xué)習(xí)和測(cè)試。
kiwenlau/single-mesos鏡像非常簡單。Docker容器運(yùn)行在Ubuntu主機(jī)之上,Mesos和Marathon運(yùn)行在該容器之中。具體來講,Docker容器中運(yùn)行了一個(gè)Mesos Master和一個(gè)Mesos Slave,以及Marathon和ZooKeeper。集群架構(gòu)如下圖:

二. 搭建Mesos/Marathon集群
1. 下載Docker鏡像:
sudo docker pull kiwenlau/single-mesos:3.0
2. 運(yùn)行Docker容器:
sudo docker run -p 5050:5050 -p 8080:8080 --name mesos -it -w /root kiwenlau/single-mesos:3.0
docker run命令運(yùn)行成功后即進(jìn)入容器內(nèi)部,以下為輸出:
Start ZooKeeper...
Start Mesos master...
Start Mesos slave...
Start Marathon...
三. 測(cè)試Mesos/Marathon集群
1. 通過curl命令調(diào)用Marathon的REST API, 創(chuàng)建一個(gè)hello程序:
curl -v -H "Content-Type: application/json" -X POST --data "@hello.json" http://127.0.0.1:8080/v2/apps
下面為hello.json。由cmd可知,該程序每隔1秒往output.txt文件中寫入hello。
{
"id": "hello",
"cmd": "while [ true ] ; do echo hello >> /root/output.txt; sleep 1; done",
"cpus": 0.1,
"mem": 10.0,
"instances": 1
}
curl執(zhí)行結(jié)果:
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> POST /v2/apps HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8080
> Accept: */*
> Content-Type: application/json
> Content-Length: 139
>
* upload completely sent off: 139 out of 139 bytes
< HTTP/1.1 201 Created
< X-Marathon-Leader: http://ec054cabb9af:8080
< Cache-Control: no-cache, no-store, must-revalidate
< Pragma: no-cache
< Expires: 0
< Location: http://127.0.0.1:8080/v2/apps/hello
< Content-Type: application/json; qs=2
< Transfer-Encoding: chunked
* Server Jetty(8.y.z-SNAPSHOT) is not blacklisted
< Server: Jetty(8.y.z-SNAPSHOT)
<
* Connection #0 to host 127.0.0.1 left intact
{"id":"/hello","cmd":"while [ true ] ; do echo hello >> /root/output.txt; sleep 1; done","args":null,"user":null,"env":{},"instances":1,"cpus":0.1,"mem":10.0,"disk":0.0,"executor":"","constraints":[],"uris":[],"storeUrls":[],"ports":[0],"requirePorts":false,"backoffFactor":1.15,"container":null,"healthChecks":[],"dependencies":[],"upgradeStrategy":{"minimumHealthCapacity":1.0,"maximumOverCapacity":1.0},"labels":{},"acceptedResourceRoles":null,"version":"2015-09-16T11:22:27.967Z","deployments":[{"id":"2cd2fdd4-e5f9-4088-895f-7976349b7a19"}],"tasks":[],"tasksStaged":0,"tasksRunning":0,"tasksHealthy":0,"tasksUnhealthy":0,"backoffSeconds":1,"maxLaunchDelaySeconds":3600}
2. 查看hello程序的運(yùn)行結(jié)果:
tail -f output.txt
當(dāng)你看到終端不斷輸出"hello"時(shí)說明運(yùn)行成功。
3. 使用瀏覽器查看Mesos和Marathon的網(wǎng)頁管理界面
注意將IP替換運(yùn)行Docker容器的主機(jī)IP地址
Mesos網(wǎng)頁管理界面地址:http://192.168.59.10:5050
Mesos網(wǎng)頁管理界面如圖,可知hello程序正在運(yùn)行:

Marathon網(wǎng)頁管理界面地址:http://192.168.59.10:8080
Marathon網(wǎng)頁管理界面如圖,可知hello程序正在運(yùn)行:

4. 通過Marathon網(wǎng)頁管理界面創(chuàng)建測(cè)試程序
在Marathon的網(wǎng)頁管理界面上點(diǎn)擊"New APP",在彈框中配置測(cè)試程序。ID為"hello", Command為"echo hello >> /root/output.txt", 然后點(diǎn)擊"Create"即可。如下圖:

四. 存在的問題
其實(shí),參考Setting up a Single Node Mesosphere Cluster,可以很快地在ubuntu主機(jī)上直接搭建一個(gè)單節(jié)點(diǎn)的Mesos/Marathon集群。但是,當(dāng)我安裝該教程的步驟將Mesos/Marathon集群打包到Docker鏡像中時(shí),遇到了一個(gè)比較奇怪的問題。
在Docker容器中使用"sudo service mesos-master start"和"sudo service mesos-slave start"命令啟動(dòng)Mesos Master和Mesos Slave時(shí),出現(xiàn)"mesos-master: unrecognized service"和"mesos-slave: unrecognized service"錯(cuò)誤。但是,我在ubuntu主機(jī)上安裝Mesos/Marathon集群后,使用同樣的命令啟動(dòng)Mesos并沒有問題。后來,我是通過直接執(zhí)行mesos-master和mesos-slave命令啟動(dòng)Mesos,命令如下:
/usr/sbin/mesos-master --zk=zk://127.0.0.1:2181/mesos --quorum=1 --work_dir=/var/lib/mesos --log_dir=/log/mesos
/usr/sbin/mesos-slave --master=zk://127.0.0.1:2181/mesos --log_dir=/log/mesos
由這個(gè)問題可知,雖然在Docker容器幾乎可以運(yùn)行任意程序,似乎和Ubuntu主機(jī)沒有區(qū)別。但是事實(shí)上,Docker容器與ubuntu主機(jī)并非完全一致,而且這些細(xì)節(jié)的不同點(diǎn)比較坑。這一點(diǎn)很值得探討,可以讓大家在使用Docker時(shí)少走些彎路。對(duì)于提到的問題,雖然是解決了,然而我仍然不清楚其中的原因:(
五. Docker鏡像備份
我將Docker鏡像上傳到了靈雀云(Alaudo)的Docker倉庫,可以通過以下命令下載和運(yùn)行:
sudo docker pull index.alauda.cn/kiwenlau/single-mesos:3.0
sudo docker run -p 5050:5050 -p 8080:8080 --name mesos -it -w /root index.alauda.cn/kiwenlau/single-mesos:3.0
六. 參考
- Setting up a Single Node Mesosphere Cluster
- Setting up a Cluster on Mesos and Marathon
- An Introduction to Mesosphere
- How To Configure a Production-Ready Mesosphere Cluster on Ubuntu 14.04
- Deploy a Mesos Cluster with 7 Commands Using Docker
- sekka1/mesosphere-docker
- Marathon: Application Basics
- Marathon: REST API
版權(quán)聲明
轉(zhuǎn)載時(shí)請(qǐng)注明作者KiwenLau以及本文URL地址:
http://kiwenlau.com/2015/09/18/150918-single-mesos-docker/