MESOS 本地持久化存儲(chǔ)類型:
-
root,最基本的存儲(chǔ)資源拧粪,默認(rèn)是mesos agent工作路徑的存儲(chǔ)資源灶搜。
應(yīng)用共享式使用。
在創(chuàng)建應(yīng)用的同時(shí)瞎疼,會(huì)在/var/lib/mesos/slave/volumes目錄下創(chuàng)建應(yīng)用的存儲(chǔ)目錄科乎。
agent上報(bào)root類型存儲(chǔ)2G。
[ { "name" : "disk", "type" : "SCALAR", "scalar" : { "value" : 2048 } } ]
-
path,作為附加存儲(chǔ)資源丑慎,可以將整塊磁盤喜喂,通過(guò)目錄存儲(chǔ)的方式進(jìn)行劃分。用于日志存儲(chǔ)竿裂、備份玉吁,用于無(wú)性能要求的存儲(chǔ)。
應(yīng)用共享式使用腻异。
在創(chuàng)建應(yīng)用的同時(shí)进副,會(huì)在path目錄下創(chuàng)建應(yīng)用的存儲(chǔ)目錄。
如 mount /dev/sdb /mnt && mkdir /mnt/data, /dev/sdb 是10G悔常,agent上報(bào)目錄存儲(chǔ)資源/mnt/data影斑,使用2G大小。
[ { "name" : "disk", "type" : "SCALAR", "scalar" : { "value" : 2048 }, "disk" : { "source" : { "type" : "PATH", "path" : { "root" : "/mnt/data" } } } } ]
-
mount,作為附加存儲(chǔ)資源机打,只能整塊使用矫户,不能像path類存儲(chǔ)一樣分割使用。用于database残邀、write-ahead-log(WAL預(yù)寫式日志)皆辽,用于有性能要求的存儲(chǔ)。
應(yīng)用獨(dú)占式使用芥挣。
在創(chuàng)建應(yīng)用時(shí)驱闷,應(yīng)用使用整個(gè)磁盤資源,允許有預(yù)存在的數(shù)據(jù)文件/目錄空免,但是當(dāng)mesos銷毀應(yīng)用時(shí)空另,會(huì)刪除所有數(shù)據(jù)
如 mount /dev/sdb /mnt/data, agent上報(bào)存儲(chǔ)磁盤資源/mnt/data,使用大小2G。
[ { "name" : "disk", "type" : "SCALAR", "scalar" : { "value" : 2048 }, "disk" : { "source" : { "type" : "MOUNT", "mount" : { "root" : "/mnt/data" } } } } ]
Marathon docker應(yīng)用使用local persistent volume示例
Marathon對(duì)于這幾種Persistent Volume的使用區(qū)分蹋砚,主要是通過(guò)persistent.type來(lái)控制的扼菠。
操作流程:
1. marathon創(chuàng)建應(yīng)用
2. 查看應(yīng)用mount信息
3. 創(chuàng)建tmp.txt
4. 重啟應(yīng)用摄杂,查看tmp.txt
5. 查看應(yīng)用的本地存儲(chǔ)目錄
root
創(chuàng)建marathon 應(yīng)用
{
"id": "/cwc/test/test-root",
"instances": 1,
"portDefinitions": [],
"container": {
"type": "DOCKER",
"docker": {
"image": "busybox"
},
"volumes": [
{
"persistent": {
"size": 100
},
"mode": "RW",
"containerPath": "mydata"
},
{
"containerPath": "/mydata",
"hostPath": "mydata",
"mode": "RW"
}
]
},
"cpus": 0.1,
"mem": 128,
"requirePorts": false,
"cmd": "tail -f /dev/null",
"residency": {
"relaunchEscalationTimeoutSeconds": 10,
"taskLostBehavior": "WAIT_FOREVER"
}
}
這時(shí)候marathon隨機(jī)選取了一個(gè)主機(jī)去部署應(yīng)用,以后與這個(gè)應(yīng)用相關(guān)的所有操作都只在這個(gè)主機(jī)上運(yùn)行循榆。
可以看到
應(yīng)用容器內(nèi)存儲(chǔ)目錄 /mydata
主機(jī)存儲(chǔ)目錄/var/lib/mesos/slave/volumes/roles/slave_public/cwc_test_test-root#mydata#743b88a7-8e17-11e7-b490-b6a91729f427
重啟應(yīng)用數(shù)據(jù)不變
重啟agent匙姜,應(yīng)用自動(dòng)恢復(fù),數(shù)據(jù)不變
應(yīng)用銷毀冯痢,數(shù)據(jù)消失
path
marathon 應(yīng)用
{
"id": "/cwc/test/test-path",
"instances": 1,
"portDefinitions": [],
"container": {
"type": "DOCKER",
"docker": {
"image": "busybox",
"network": "HOST"
},
"volumes": [
{
"persistent": {
"size": 100,
"type": "path"
},
"mode": "RW",
"containerPath": "mydata"
},
{
"containerPath": "/mydata",
"hostPath": "mydata",
"mode": "RW"
}
]
},
"cpus": 0.1,
"mem": 128,
"requirePorts": false,
"cmd": "tail -f /dev/null",
"residency": {
"relaunchEscalationTimeoutSeconds": 10,
"taskLostBehavior": "WAIT_FOREVER"
}
}
這時(shí)候marathon隨機(jī)選取了一個(gè)主機(jī)去部署應(yīng)用,以后與這個(gè)應(yīng)用相關(guān)的所有操作都只在這個(gè)主機(jī)上運(yùn)行框杜。
可以看到
應(yīng)用容器內(nèi)存儲(chǔ)目錄 /mydata
主機(jī)存儲(chǔ)目錄/mnt/data/volumes/roles/slave_public/cwc_test_test-path#mydata#8f2d2ba9-8e1c-11e7-b490-b6a91729f427/
重啟應(yīng)用數(shù)據(jù)不變
agent重啟浦楣,數(shù)據(jù)不變
應(yīng)用銷毀,數(shù)據(jù)消失
agent 重新resize path resource咪辱,應(yīng)用啟動(dòng)失敗
mount
marathon 應(yīng)用
{
"id": "/cwc/test/test-mount",
"instances": 1,
"portDefinitions": [],
"container": {
"type": "DOCKER",
"docker": {
"image": "busybox"
},
"volumes": [
{
"persistent": {
"size": 100,
"type": "mount"
},
"mode": "RW",
"containerPath": "mydata"
},
{
"containerPath": "/mydata",
"hostPath": "mydata",
"mode": "RW"
}
]
},
"cpus": 0.1,
"mem": 128,
"requirePorts": false,
"cmd": "tail -f /dev/null",
"constraints": [
[
"hostname",
"LIKE",
"192.168.131.4"
]
],
"residency": {
"relaunchEscalationTimeoutSeconds": 10,
"taskLostBehavior": "WAIT_FOREVER"
}
}
應(yīng)用容器內(nèi)存儲(chǔ)目錄 /mydata
主機(jī)存儲(chǔ)目錄/dcos/volume0/
重啟應(yīng)用數(shù)據(jù)存在
agent重啟振劳,數(shù)據(jù)存在
應(yīng)用銷毀,數(shù)據(jù)消失
agent 重新resize mount resource油狂,應(yīng)用啟動(dòng)失敗
Marathon 使用Host Volume
{
"type": "DOCKER",
"volumes": [
{
"mode": "RO",
"container_path": "/etc/localtime",
"host_path": "/etc/localtime"
},
{
"mode": "RW",
"container_path": "/tmp",
"host_path": "/tmp"
}
],
"docker": {
"image": "busybox",
"network": "HOST",
"privileged": false,
"parameters": [
{
"key": "label",
"value": "MESOS_TASK_ID=cwc_test-local-path.75db9606-97d6-11e7-aaa2-36ce7409b167"
}
],
"force_pull_image": false
}
}