尊龙凯时人生就是搏

ÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄÈÕÖ¾ÆÊÎöºÍÒì³£ÅŲé

Ëæ×ÅÈÝÆ÷ÊÖÒÕµÄÆÕ¼°ºÍÓ¦Óà £¬DockerÒѾ­³ÉΪÐí¶àÆóÒµÖв»¿É»òȱµÄÒ»²¿·Ö ¡£ÔÚʹÓÃDocker¾ÙÐпª·¢ºÍ°²ÅÅÖÐ £¬ÈÝÆ÷µÄÈÕÖ¾ÆÊÎöºÍÒì³£ÅŲéÊǺÜÊÇÖ÷ÒªµÄÒ»»· ¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄÈÕÖ¾ÆÊÎöºÍÒì³£ÅŲé £¬ÒÔ¼°ÏêϸµÄ´úÂëʾÀý ¡£

Ò»¡¢DockerÈÕÖ¾¼ò½é

DockerÈÕÖ¾Ö¸µÄÊÇÈÝÆ÷µÄÊä³ö £¬°üÀ¨ÈÝÆ÷µÄ±ê×¼Êä³öºÍ¹ýʧÊä³ö £¬ÔÚÈÝÆ÷ÄÚ²¿ £¬¿ÉÒÔͨ¹ýstdoutºÍstderr½«Êä³öдÈëµ½¿ØÖÆ̨ ¡£Docker½«ÕâЩÊä³ö²¶»ñ £¬ÉúÑĵ½ËÞÖ÷»úÉϵÄÒ»¸öÎļþÖÐ ¡£

ÔÚDockerÖÐ £¬Ã¿¸öÈÝÆ÷¶¼ÓÐ×Ô¼ºµÄÈÕÖ¾ £¬¿ÉÒÔʹÓÃDockerÏÂÁîÉó²éÈÝÆ÷µÄÈÕÖ¾£º

docker logs [CONTAINER ID]

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÆäÖÐCONTAINER IDÖ¸µÄÊÇÈÝÆ÷µÄID ¡£

¶þ¡¢Ê¹ÓÃDocker¾ÙÐÐÈÝÆ÷ÈÕÖ¾ÆÊÎö

ʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄÈÕÖ¾ÆÊÎö £¬¿ÉÒÔ×ÊÖúÎÒÃÇÏàʶÈÝÆ÷µÄÔËÐÐÇéÐÎ £¬ÕÒµ½±£´æµÄÎÊÌâ²¢¾ÙÐÐÐÞ¸´ ¡£ÏÂÃæÊÇʹÓÃDocker¾ÙÐÐÈÝÆ÷ÈÕÖ¾ÆÊÎöµÄÏêϸ°ì·¨£º

1. Éó²éÈÝÆ÷ÈÕÖ¾

Ê×ÏÈ £¬ÎÒÃÇÐèÒªÉó²éÈÝÆ÷µÄÈÕÖ¾ £¬ÅжÏÈÝÆ÷ÊÇ·ñ±£´æÒì³£ ¡£Ê¹ÓÃDockerÏÂÁîÉó²éÈÝÆ÷µÄÈÕÖ¾£º

docker logs [CONTAINER ID]

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÈôÊÇÏëÉó²éÈÝÆ÷×î½üµÄ10ÌõÈÕÖ¾ £¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ

docker logs --tail 10 [CONTAINER ID]

µÇ¼ºó¸´ÖÆ

2. ƾ֤Ҫº¦×Ö¹ýÂËÈÕÖ¾

ÔÚÉó²éÈÝÆ÷ÈÕ־ʱ £¬ÎÒÃÇ¿ÉÒÔƾ֤Ҫº¦×ÖÀ´¹ýÂËÈÕÖ¾ £¬ÒÔ±ãÔ½·¢×¼È·µØÏàʶÈÝÆ÷µÄÔËÐÐÇéÐÎ ¡£Ê¹ÓÃÈçÏÂÏÂÁî £¬¿ÉÒÔƾ֤Ҫº¦×Öɸѡ³öÈÕÖ¾£º

docker logs [CONTAINER ID] | grep [KEYWORD]

µÇ¼ºó¸´ÖÆ

ÀýÈç £¬²éÕÒ°üÀ¨¡°error¡±µÄÈÕÖ¾£º

docker logs [CONTAINER ID] | grep error

µÇ¼ºó¸´ÖÆ

3. Êä³öÈÝÆ÷ÈÕÖ¾µ½Îļþ

Docker»á½«ÈÝÆ÷µÄÈÕÖ¾ÉúÑĵ½ËÞÖ÷»úÉϵÄÒ»¸öÎļþÖÐ ¡£ÎÒÃÇ¿ÉÒÔ½«ÈÝÆ÷µÄÈÕÖ¾Êä³öµ½ÎļþÖÐ £¬ÒÔ±ãºóÐøÆÊÎö ¡£Ê¹ÓÃÈçÏÂÏÂÁî £¬¿ÉÒÔ½«ÈÝÆ÷µÄÈÕÖ¾Êä³öµ½Ò»¸öÎļþÖУº

docker logs [CONTAINER ID] > [LOG FILE]

µÇ¼ºó¸´ÖÆ

ÀýÈç £¬½«ÈÝÆ÷µÄÈÕÖ¾Êä³öµ½Îļþ¡°container.log¡±£º

docker logs [CONTAINER ID] > container.log

µÇ¼ºó¸´ÖÆ

4. ʹÓõÚÈý·½¹¤¾ß¾ÙÐÐÈÕÖ¾ÆÊÎö

ÈôÊÇÏëÔ½·¢ÉîÈëµØ¾ÙÐÐÈÝÆ÷ÈÕÖ¾ÆÊÎö £¬¿ÉÒÔʹÓÃһЩµÚÈý·½¹¤¾ß ¡£ÀýÈç £¬Ê¹ÓÃELK£¨Elasticsearch + Logstash + Kibana£©¾ÙÐÐÈÕÖ¾ÆÊÎö ¡£ÏÂÃæ¼òÆÓÏÈÈÝÒ»ÏÂÔõÑùʹÓÃELK¾ÙÐÐÈÝÆ÷ÈÕÖ¾ÆÊÎö ¡£

4.1 ×°ÖÃELK

ÎÒÃÇ¿ÉÒÔʹÓÃDockerÀ´×°ÖÃELK £¬Ïêϸ°ì·¨ÈçÏ£º

docker pull sebp/elk
docker run -p 5601:5601 -p 9200:9200 -p 5044:5044 -it --name elk sebp/elk

µÇ¼ºó¸´ÖÆ

ÉÏÊöÏÂÁîÖÐ £¬À­È¡ÁËsebp/elk¾µÏñ £¬²¢Æô¶¯ÁËÒ»¸öÃûΪ¡°elk¡±µÄÈÝÆ÷ ¡£ÎÒÃÇ¿ÉÒÔͨ¹ýµØµãhttp://localhost:5601/À´»á¼ûKibanaÃæ°å ¡£

4.2 ÉèÖÃLogstash

ÔÚLogstashÖÐ £¬ÐèÒªÉèÖÃÊäÈë¡¢¹ýÂËÆ÷ºÍÊä³ö ¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄLogstashÉèÖÃÎļþ £¬ÓÃÓÚ½«ÈÝÆ÷µÄÈÕÖ¾ÊäÈëµ½ElasticsearchÖУº

input {
  file {
    type => "docker"
    path => "/var/lib/docker/containers/*/*.log"
    exclude => "*.gz"
  }
}

filter {
  if [type] == "docker" {
    grok {
      match => { "message" => "[%{TIMESTAMP_ISO8601:timestamp}] %{LOGLEVEL:loglevel} %{GREEDYDATA:message}" }
      overwrite => [ "message" ]
    }
    date {
      match => [ "timestamp", "ISO8601" ]
      timezone => "UTC"
    }
  }
}

output {
  stdout { codec => rubydebug }
  elasticsearch {
    hosts => ["localhost:9200"]
    index => "docker-%{+YYYY.MM.dd}"
    document_type => "docker"
  }
}

µÇ¼ºó¸´ÖÆ

ÉÏÊöÉèÖÃÎļþÖÐ £¬½ç˵ÁËÒ»¸öÃûΪ¡°docker¡±µÄÊäÈë £¬ÊäÈë·¾¶Îª/var/lib/docker/containers/ÏÂËùÓеÄ.logÎļþ ¡£ÔÚ¹ýÂËÆ÷ÖÐ £¬Ê¹ÓÃgrokģʽƥÅäÈÕÖ¾ £¬²¢½«Ê±¼ä´Áת»»ÎªISO8601ʱ¼äÃûÌà ¡£ÔÚÊä³öÖÐ £¬½«ÈÕÖ¾Êä³öµ½ElasticsearchÖÐ ¡£

4.3 Éó²éÈÝÆ÷ÈÕÖ¾

ÔÚÍê³ÉÒÔÉÏÉèÖúó £¬ÎÒÃÇ¿ÉÒÔÉó²éÈÝÆ÷µÄÈÕÖ¾²¢¾ÙÐÐÆÊÎö ¡£ÔÚKibanaÃæ°åÖÐ £¬Ñ¡Ôñ¡°Discover¡±Ò³Ãæ £¬¿ÉÒÔ¿´µ½ËùÓеÄÈÕÖ¾ÐÅÏ¢ ¡£

Èý¡¢Ê¹ÓÃDocker¾ÙÐÐÈÝÆ÷Òì³£ÅŲé

DockerÖÐÈÝÆ÷µÄÒì³£ÅŲéÒ²ÊǺÜÊÇÖ÷ÒªµÄ ¡£ÈÝÆ÷µÄÒì³£¿ÉÄܵ¼ÖÂÓ¦ÓóÌÐòÎÞ·¨Õý³£ÔËÐÐ £¬ÉõÖÁ»áµ¼ÖÂÕû¸öϵͳµÄÍ߽⠡£ÏÂÃæÏÈÈÝÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄÒì³£ÅŲé ¡£

1. Éó²éÈÝÆ÷״̬

ÎÒÃÇ¿ÉÒÔʹÓÃÈçÏÂÏÂÁîÀ´Éó²éÈÝÆ÷µÄ״̬£º

docker ps -a

µÇ¼ºó¸´ÖÆ

´ËÏÂÁÁгöËùÓеÄÈÝÆ÷¼°Æä״̬ ¡£

2. ½øÈëÈÝÆ÷¾ÙÐе÷ÊÔ

ÔÚÉó²éÈÝÆ÷״̬ºó £¬ÎÒÃÇ¿ÉÒÔ½øÈëÈÝÆ÷ÖоÙÐе÷ÊÔ ¡£Ê¹ÓÃÈçÏÂÏÂÁî £¬¿ÉÒÔ½øÈëµ½ÈÝÆ÷ÖУº

docker exec -it [CONTAINER ID] /bin/bash

µÇ¼ºó¸´ÖÆ

ÆäÖÐ £¬CONTAINER IDÖ¸µÄÊÇÈÝÆ÷µÄID ¡£

3. Éó²éÈÕÖ¾²¢ÆÊÎö

ÔÚ½øÈëµ½ÈÝÆ÷Öкó £¬ÎÒÃÇ¿ÉÒÔÉó²éÈÝÆ÷µÄÈÕÖ¾ £¬²¢Æ¾Ö¤ÈÕÖ¾ÐÅÏ¢¾ÙÐе÷ÊÔÆÊÎö ¡£ÏêϸÏÂÁîÈçÏ£º

docker logs [CONTAINER ID]

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

4. ʹÓù¤¾ß¾ÙÐÐÆÊÎö

ÔÚ¾ÙÐÐÈÝÆ÷Òì³£ÅŲéʱ £¬ÎÒÃÇ¿ÉÒÔʹÓÃһЩ¹¤¾ß¾ÙÐÐ×ÊÖú ¡£ÀýÈç £¬ÔÚÈÝÆ÷ÖÐ×°ÖÃDebug¹¤¾ß £¬ÒÔÀû±ãÎÒÃǾÙÐе÷ÊÔ ¡£ÏÂÃæÊÇÒ»¸öÀý×Ó£º

docker run -d --name nginx-debug --entrypoint /usr/bin/sleep nginx 9d
docker pause nginx-debug
docker network connect [NETWORK] nginx-debug
docker attach --sig-proxy=false nginx-debug

µÇ¼ºó¸´ÖÆ

ÉÏÊöÏÂÁîÖÐ £¬Ê×ÏȽ¨ÉèÁËÒ»¸öÃûΪ¡°nginx-debug¡±µÄÈÝÆ÷ £¬²¢¾ÙÐÐÁËһЩÉèÖà ¡£ÎÒÃÇ¿ÉÒÔʹÓôËÈÝÆ÷À´¾ÙÐе÷ÊÔ ¡£

ËÄ¡¢×ܽá

ÔÚʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄÈÕÖ¾ÆÊÎöºÍÒì³£ÅŲéʱ £¬ÎÒÃÇ¿ÉÒÔʹÓÃDockerÏÂÁî¾ÙÐÐÉó²éºÍÆÊÎö £¬Ò²¿ÉÒÔʹÓõÚÈý·½¹¤¾ßÀ´×ÊÖúÎÒÃÇÔ½·¢ÉîÈëµØ¾ÙÐÐÈÝÆ÷ÈÕÖ¾µÄÆÊÎöºÍÒì³£ÅŲé ¡£Ï£ÍûÉÏÊöÄÚÈÝÄܹ»¶ÔÄúÔÚʹÓÃDocker¾ÙÐпª·¢ºÍ°²ÅÅʱÓÐËù×ÊÖú £¬Í¬Ê±±¾ÎÄÒ²ÌṩÁËÏêϸµÄ´úÂëʾÀý £¬¿ÉÒÔʹ¶ÁÕ߸üÒ×ÓÚÃ÷È·²¢Ñ§Ï°Ïà¹ØÊÖÒÕ ¡£

ÒÔÉϾÍÊÇÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄÈÕÖ¾ÆÊÎöºÍÒì³£ÅŲéµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼ ¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý ¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ