- GitHub地址:kiwenlau/single-mesos-docker
- 博客地址:基于Docker快速搭建單節點Mesos/Marathon集群
一. 簡介
二. 搭建Mesos/Marathon集群
三. 測試Mesos/Marathon集群
四. 存在的問題
五. 其他
六. 參考
一. 簡介
Mesos是集群資源管理系統,Marathon是運行在Mesos之上的集群計算架構。將Mesos和Marathon打包到Docker鏡像中,開發者便可以在本機上快速搭建Mesos/Marathon集群,進行學習和測試。
kiwenlau/single-mesos鏡像非常簡單。Docker容器運行在Ubuntu主機之上,Mesos和Marathon運行在該容器之中。具體來講,Docker容器中運行了一個Mesos Master和一個Mesos Slave,以及Marathon和ZooKeeper。集群架構如下圖:
二. 搭建Mesos/Marathon集群
1. 下載Docker鏡像:
sudo docker pull kiwenlau/single-mesos:3.0
2. 運行Docker容器:
sudo docker run -p 5050:5050 -p 8080:8080 --name mesos -it -w /root kiwenlau/single-mesos:3.0
docker run命令運行成功后即進入容器內部,以下為輸出:
Start ZooKeeper...
Start Mesos master...
Start Mesos slave...
Start Marathon...
三. 測試Mesos/Marathon集群
1. 通過curl命令調用Marathon的REST API, 創建一個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執行結果:
* 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程序的運行結果:
tail -f output.txt
當你看到終端不斷輸出"hello"時說明運行成功。
3. 使用瀏覽器查看Mesos和Marathon的網頁管理界面
注意將IP替換運行Docker容器的主機IP地址
Mesos網頁管理界面地址:http://192.168.59.10:5050
Mesos網頁管理界面如圖,可知hello程序正在運行:
Marathon網頁管理界面地址:http://192.168.59.10:8080
Marathon網頁管理界面如圖,可知hello程序正在運行:
4. 通過Marathon網頁管理界面創建測試程序
在Marathon的網頁管理界面上點擊"New APP",在彈框中配置測試程序。ID為"hello", Command為"echo hello >> /root/output.txt", 然后點擊"Create"即可。如下圖:
四. 存在的問題
其實,參考Setting up a Single Node Mesosphere Cluster,可以很快地在ubuntu主機上直接搭建一個單節點的Mesos/Marathon集群。但是,當我安裝該教程的步驟將Mesos/Marathon集群打包到Docker鏡像中時,遇到了一個比較奇怪的問題。
在Docker容器中使用"sudo service mesos-master start"和"sudo service mesos-slave start"命令啟動Mesos Master和Mesos Slave時,出現"mesos-master: unrecognized service"和"mesos-slave: unrecognized service"錯誤。但是,我在ubuntu主機上安裝Mesos/Marathon集群后,使用同樣的命令啟動Mesos并沒有問題。后來,我是通過直接執行mesos-master和mesos-slave命令啟動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
由這個問題可知,雖然在Docker容器幾乎可以運行任意程序,似乎和Ubuntu主機沒有區別。但是事實上,Docker容器與ubuntu主機并非完全一致,而且這些細節的不同點比較坑。這一點很值得探討,可以讓大家在使用Docker時少走些彎路。對于提到的問題,雖然是解決了,然而我仍然不清楚其中的原因:(
五. Docker鏡像備份
我將Docker鏡像上傳到了靈雀云(Alaudo)的Docker倉庫,可以通過以下命令下載和運行:
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
版權聲明
轉載時請注明作者KiwenLau以及本文URL地址:
http://kiwenlau.com/2015/09/18/150918-single-mesos-docker/