docker学习笔记(八):资源限制、监控与编排

2274人浏览 / 47人评论

这次的内容有点多,涉及到了容器的资源限制、容器运行状况监控和容器编排。

同时也是本阶段学习Docker的尾声,接下来将继续学习kubernetes相关知识,相关学习笔记也会同步更新上来。

容器资源限制

Docker在默认情况下可以使用物理机所有资源,很多时候不做限制将会导致容器无休止的占用物理机资源。比如一些运算密集型的容器,持续占用CPU资源;再比如Redis等内存数据库容器将占用更多的内存资源。这样由于个别容器的设计不合理等问题,很有可能导致整个物理机中的容器都无法正常运行。

Docker实现容器资源限制的方式主要是依靠系统内核中的**Cgroups**,cgroups,其名称源自控制组群(control groups)的简写,是Linux内核的一个功能,用来限制、控制与分离一个进程组的资源(如CPU、内存、磁盘输入输出等)。这也是最早的容器,当时叫做进程容器,其实现在Docker也就可以理解成就是一个进程。

对内存进行限制

对内存进行限制,主要是在创建容器是进行指定,具体方如下:

docker run -it -m 200M --rm centos:v1 /bin/bash

以上命令就将容器的最大可使用内存设置为200M了,当容器内部应用使用内存超过200M时将会因为OOM被强行关闭。

对CPU进行限制

谈及CPU限制,主要是使用CPU的亲和性来进行指定容器运行的CPU。相关指令:

docker run -it --cpuset-cpus=1 --rm centos:v1 /bin/bash

这条指令将会绑定该容器到cpu1上,容器中的所运行的程序都将在这颗CPU上执行。

CPU的亲和性

CPU Affinity 可以将进程或线程绑定到一个CPU核或一组CPU核上,这样进程或线程只能在指定的CPU核上执行。可以看做是对操作系统中的调度算法的进行了修改。

意义:线程在一个CPU上运行后,CPU的缓存中可能保存了一些信息,调度该线程在同一CPU上执行减少了缓存未命中,提高了性能,例如用于进行图形渲染的程序

参见:Java CPU亲和性

下面列举一些指令:

# 查看系统CPU信息
[root@localhost ~]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
......

# 创建4个死循环
[root@localhost ~]# cat /dev/zero > /dev/null &
[1] 39829
[root@localhost ~]# cat /dev/zero > /dev/null &
[2] 39830
[root@localhost ~]# cat /dev/zero > /dev/null &
[3] 39831
[root@localhost ~]# cat /dev/zero > /dev/null &
[4] 39832

# 查看4个程序所在CPU信息, 其中psr就是所在CPU编号,当前系统环境只有一个CPU,所以都是0
[root@localhost ~]# ps mo pid,comm,psr `pgrep cat`
   PID COMMAND         PSR
 39829 cat               -
     - -                 0
 39830 cat               -
     - -                 0
 39831 cat               -
     - -                 0
 39832 cat               -
     - -                 0

# 安装 killall
[root@localhost ~]# yum whatprovides */killall
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
......

# 关闭所有cat进程
[root@localhost ~]#  killall -9 cat

# 指定cat 进行使用cpu
taskset -c 0 cat /dev/zero > /dev/null &

更多资源限制参看:使用 docker 对容器资源进行限制

容器监控

这里主要使用到了google提供的cadvisor工具。

docker pull hub.c.163.com/xbingo/cadvisor:latest

docker run \
> -v /var/run:/var/run \
> -v /sys:/sys:ro \
> -v /var/lib/docker:/var/lib/docker:ro \
> -d -p 8080:8080 --name=mon \
> hub.c.163.com/xbingo/cadvisor;latest

容器编排

这里主要讲的是docker-compose这个工具。 相关命令:

# 安装和卸载docker-compose
[root@localhost ~]#  yum install python2-pip -y
[root@localhost ~]#  pip install docker-compose
[root@localhost ~]#  pip uninstall docker-compose
[root@localhost ~]#  docker-compose -v

# docker-compose相关命令
[root@localhost ~]#  docker-compose start
[root@localhost ~]#  docker-compose stop
[root@localhost ~]#  docker-compose rm
[root@localhost ~]#  docker-compose start -d

更多内容可以参看:【Docker入门】第三部分 服务

还有一些其他的编排工具:

  • swarm
  • mesos
  • openshift
  • kubernets

后面将持续更新kubernets的相关学习笔记。

全部评论

2020-07-11 16:51:05.0
obuv ko啪enka hole historie m臎艡en铆 膷asu hodinky pro v拧echny <a href="http://www.cjr7.com/n谩拧ivku/kotn%c3%adkov%c3%a9-boty-podzimn%c3%ad-20217-1b">kotn铆kov茅 boty podzimn铆 20217 1b</a> fc barcelona 拧koln铆 set sada batoh <a href="http://www.mandesuryudunews.com/t艡ebovsko/aevor-bookpack-black-eclipse-%c4%8dern%c3%bd-batoh-z-pet-lahv%c3%ad">aevor bookpack black eclipse 膷ern媒 batoh z pet lahv铆</a> <a href="http://www.erlingsolem.com/rozd臎l臎n铆/karbonov%c3%a1-f%c3%b3lie-pro-iphone-4-4s">karbonov谩 f贸lie pro iphone 4 4s</a> d谩msk茅 leg铆ny d啪铆nov茅 damson riflov茅 leg铆ny i <a href="http://www.mandesuryudunews.com/anatomick谩/na%c5%a1e-prodejny-a-distribuce">na拧e prodejny a distribuce</a> helen fontaine svatebn铆 korzetov茅 拧aty s dlouh媒m ruk谩vem hfw1009 frauen m盲nner nike free run 2 537732 <a href="http://www.musicpyeongchang.com/verner/angelbird-ssd2go-pkt-xt-externe-ssd">angelbird ssd2go pkt xt externe ssd</a> <a href="http://www.newssawansahil.com/arbeiten/babybett-wei%c3%9f-g%c3%bcnstig-online-kaufen" >babybett wei脽 g眉nstig online kaufen</a> [url=http://www.newssawansahil.com/arbeiten/babybett-wei%c3%9f-g%c3%bcnstig-online-kaufen]babybett wei脽 g眉nstig online kaufen[/url]
2020-07-10 01:33:29.0
mia bag borsa a tracolla donna piccola plissettata nera vendita scontata fly flot ciabatta in camoscio oro con <a href="http://www.jendelakabar.com/romantici/abbigliamento-2016-nero-ricco-venerd%c3%ac-offerte-adidas">abbigliamento 2016 nero ricco venerd矛 offerte adidas</a> <a href="http://www.biplobibartabd.com/peterson_quail/prada-exclusive-to-feather-trimmed-cr%c3%aape-de">prada exclusive to feather trimmed cr锚pe de</a> retlux rtl 193 stolna lampa blaze and the monster machines auto morpher <a href="http://www.reutersbangla.com/najni啪u/lotto-tenisice-stone">lotto tenisice stone</a> brian dales sin aplicaciones boucl茅 chaquetas lam茅 negro navidad beb茅 ni帽a carnaval santa vestido para ni帽as veran <a href="http://www.wadifa-wadifa.com/asimetrica/vestidos-de-manga-larga">vestidos de manga larga</a> <a href="http://www.somosblink.com/vaporoso/zapatos-de-tac%c3%b3n-de-cuero-celestes-de-trotters">zapatos de tac贸n de cuero celestes de trotters</a> tory burch kira double strap medium shoulder bag jordan 13 retro black white gum <a href="http://www.protibedonbd.com/finzel_pineygreen/throw-over-one-shoulder">throw over one shoulder</a> <a href="http://www.wadifa-wadifa.com/n贸rdicas/vestidos-floreados-largos-veracruz-mujer-casuales-ropa" >vestidos floreados largos veracruz mujer casuales ropa</a> [url=http://www.wadifa-wadifa.com/n贸rdicas/vestidos-floreados-largos-veracruz-mujer-casuales-ropa]vestidos floreados largos veracruz mujer casuales ropa[/url]
2020-07-09 17:42:35.0
Solid Color Two Piece Shorts Set For Women Fashion Office Long Sleeve Suit Blazer With Button Fly Casual Shorts Ladies 2 Piece Solid V Neck Elegant Dress Ruffles Pleated Dress Women Fashion Butterfly Long Sleeve Chic A Line Dress Sundress Vestidos Mujer <a href="http://www.ipl-schedule.com/eurekamill/TWOTWINSTYLE-Patchwork-Mesh-Asymmetrical-Skirt-Female-High-Waist-Black-Skirts-Women-Fashion-Clothes-2020-Autumn-New-Plus-Sizes">TWOTWINSTYLE Patchwork Mesh Asymmetrical Skirt Female High Waist Black Skirts Women Fashion Clothes 2020 Autumn New Plus Sizes</a> peanuts camiseta charlie brown woodstock charles monroe anime personalizado cosplay ocasional camiseta de manga corta estampada <a href="http://www.huayuanart.com/comparador/gucci-guilty-absolute-pour-homme-50ml">gucci guilty absolute pour homme 50ml</a> authentic puma suede fat outlet authentic converse shoes puma basket white x trapstar collaboration publishing casual sneaker 361644 01 super deals <a href="http://www.medianasionalisme.com/maguayo_pocahontas/womens-designer-sandals-sliders-luxury-footwear-flannels">womens designer sandals sliders luxury footwear flannels</a> kotn铆kov茅 boty under armour <a href="http://www.turismo-medico-turquia.com/predlo啪ka/astroride-reebok">astroride reebok</a> 褋褍屑泻邪 卸械薪褋泻邪褟 polina supreme 薪邪褌褍褉邪谢褜薪邪褟 泻芯卸邪 <a href="http://www.apederana.com/tishomingo_lucien/%d0%ba%d1%80%d0%b5%d0%b4%d0%b8%d1%82-%d0%bd%d0%b0-%d1%8e%d0%b2%d0%b5%d0%bb%d0%b8%d1%80%d0%bd%d1%8b%d0%b5-%d0%b8%d0%b7%d0%b4%d0%b5%d0%bb%d0%b8%d1%8f">泻褉械写懈褌 薪邪 褞胁械谢懈褉薪褘械 懈蟹写械谢懈褟</a> <a href="http://www.parineeti-chopra.com/bagdad_maplebay/puma-rebnd-streed-sd">puma rebnd streed sd</a> <a href="http://www.freestocktipsonmobile.com/salmon_crosscity/puma-softsport-jacket-girls-black" >puma softsport jacket girls black</a> [url=http://www.freestocktipsonmobile.com/salmon_crosscity/puma-softsport-jacket-girls-black]puma softsport jacket girls black[/url]
2020-07-08 05:08:48.0
Provera Internet C.O.D. Store Saturday Delivery gugSkach https://acialisd.com/# - Cialis Parfreda Viagra Gel Edible <a href=https://acialisd.com/#>tadalafil cialis</a> waisab Meilleur Prix Cialis Generique
2020-07-08 00:48:04.0
<a href="http://www.zoozashita.com/callia/925-sterling-ez%c3%bcst-bokal%c3%a1nc">925 sterling ez眉st bokal谩nc</a> <a href="http://www.saadmahdi.com/facebookj谩t/kreat%c3%adv-j%c3%a1t%c3%a9k-rajzol%c3%a1s-vizzel-j%c3%a1t%c3%a9kbolt-%c3%a9s-online-j%c3%a1t%c3%a9k-we">kreat铆v j谩t茅k rajzol谩s vizzel j谩t茅kbolt 茅s online j谩t茅k we</a> <a href="http://www.scs-center.com/tomcsanyi/39-n%c5%91i-frizura-a-legmen%c5%91bb-r%c3%b6vid">39 n艖i frizura a legmen艖bb r枚vid</a> <a href="http://www.learn-emailmarketing.com/tegnet/k%c3%b8b-karmamia-mode-til-kvinder-online">k酶b karmamia mode til kvinder online</a> footjoy prodry crew herre str酶mper navy tilbeh酶r herre kylie jenner puma black 21t desktop wallpapers <a href="http://www.newsmillng.com/tidioute_kouts/wp-toddler-round-toe-leather-burgundy">wp toddler round toe leather burgundy</a> venta al por mayor precio de calzado en corea compre online los <a href="http://www.infopublimarkjm.com/elactante/zllndz-chaleco-de-plum%c3%b3n-sin-mangas-chaleco-chaqueta-chaleco">zllndz chaleco de plum贸n sin mangas chaleco chaqueta chaleco</a> compre blusa de rayas blancas negras bot贸n turn down tops camisas <a href="http://www.relliktheseries.com/hosszusz谩ru/b.toys-ugr%c3%a1l%c3%b3-m%c3%a9hecske">b.toys ugr谩l贸 m茅hecske</a> pl眉ss nyuszi 眉l艖 100 cm es heunec textil webshop f眉gg枚ny <a href="http://www.dakarcine.com/jjjn0972/daiwa-megaforce-bolognai-horg%c3%a1szbot-5m">daiwa megaforce bolognai horg谩szbot 5m</a> <a href="http://www.lepantofolkfestival.com/stearinlys/viola-short-love-lou" >viola short love lou</a> [url=http://www.lepantofolkfestival.com/stearinlys/viola-short-love-lou]viola short love lou[/url]
2020-07-01 07:52:20.0
<a href="http://www.jogosdediversao.com/republica/modelos-de-sandalias-para-mujer">modelos de sandalias para mujer</a> nike air 70 azul jeans uomo con polsino scarpa calcio ronaldo <a href="http://www.wasl-sy.com/generazione/camicioni-estivi-2015">camicioni estivi 2015</a> collo coreana camicia <a href="http://www.yenisanliurfa.com/prosperoso/borse-a-mano-2016">borse a mano 2016</a> zalando offerte uomo sacco domyos 30 kg <a href="http://www.yenisanliurfa.com/notifiche/little-gucci-vestito">little gucci vestito</a> [url=http://www.voyagericietmaintenant.com/pararse/vans-cuadros-old-skool]vans cuadros old skool[/url]
2020-06-17 05:14:11.0
Levitra Mejor Que Cialis https://agenericcialise.com/ - Cialis Viagra Tschechien Rezeptfrei <a href=https://agenericcialise.com/#>Cialis</a> Order 60 Mg Cialis Online