ÔõÑùÔÚLinuxÉÏÉèÖÃÈÝÆ÷ÈÕÖ¾ÖÎÀí
ÔõÑùÔÚlinuxÉÏÉèÖÃÈÝÆ÷ÈÕÖ¾ÖÎÀí
¼ò½é£º
Ëæ×ÅÈÝÆ÷ÊÖÒÕµÄÒ»Ö±Éú³¤£¬Ô½À´Ô½¶àµÄÓ¦ÓóÌÐò±»°²ÅÅÔÚÈÝÆ÷ÖС£ÈÝÆ÷µÄÒ»´óÌصã¾ÍÊÇÇáÁ¿¼¶£¬µ«ÕâÒ²´øÀ´ÁËÈÝÆ÷ÈÕÖ¾ÖÎÀíµÄÌôÕ½¡£±¾ÎĽ«ÏÈÈÝÔÚLinuxÉÏÔõÑùÉèÖÃÈÝÆ÷ÈÕÖ¾ÖÎÀí£¬ÒÔʵÏÖÈÕÖ¾µÄÍøÂç¡¢´æ´¢ºÍÆÊÎö¡£
Ò»¡¢×°ÖÃDocker
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚLinuxÉÏ×°ÖÃDocker¡£DockerÊÇÒ»ÖÖÊ¢ÐеÄÈÝÆ÷»¯Æ½Ì¨£¬¿ÉÒÔ×ÊÖúÎÒÃÇ¿ìËÙ¹¹½¨¡¢´ò°üºÍ°²ÅÅÓ¦ÓóÌÐò¡£
×°ÖÃDocker
ÔÚÖÕ¶ËÖÐÖ´ÐÐÒÔÏÂÏÂÁîÒÔ×°ÖÃDocker£º
$ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io
µÇ¼ºó¸´ÖÆ
Æô¶¯Docker
×°ÖÃÍê³Éºó£¬Ê¹ÓÃÒÔÏÂÏÂÁîÆô¶¯DockerЧÀÍ£º
$ sudo systemctl start docker
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÏÖÔÚ£¬ÎÒÃÇÒѾװÖúÃÁËDocker£¬¿ÉÒÔ×îÏÈÉèÖÃÈÝÆ÷ÈÕÖ¾ÖÎÀí¡£
¶þ¡¢ÉèÖÃÈÝÆ÷ÈÕÖ¾Çý¶¯
ĬÈÏÇéÐÎÏ£¬DockerʹÓÃjson-file×÷ΪĬÈϵÄÈÕÖ¾Çý¶¯¡£µ«¹ØÓÚÉú²úÇéÐÎÀ´Ëµ£¬ÎÒÃÇ¿ÉÄÜÐèÒª¸üÇ¿Ê¢µÄÈÕÖ¾ÖÎÀí¹¤¾ß£¬ºÃ±ÈElasticsearch¡¢FluentdµÈ¡£
×èÖ¹DockerЧÀÍ
ÔÚ¸üËûÈÕÖ¾Çý¶¯Ö®Ç°£¬ÎÒÃÇÐèÒªÏÈ×èÖ¹DockerЧÀÍ£º
$ sudo systemctl stop docker
µÇ¼ºó¸´ÖÆ
ÉèÖÃÈÕÖ¾Çý¶¯
±à¼DockerÉèÖÃÎļþ£¬Ð޸ġ°/etc/docker/daemon.json¡±Îļþ£¬Ìí¼ÓÈçÏÂÄÚÈÝ£º
{ "log-driver": "fluentd", "log-opts": { "fluentd-address": "192.168.1.100:24224" } }
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬fluentd-addressÊÇFluentdЧÀÍÆ÷µÄIPµØµãºÍ¶Ë¿Ú¡£
ÖØÐÂÆô¶¯Docker
¸üÐÂÉèÖúó£¬ÖØÐÂÆô¶¯DockerЧÀÍÒÔʹ¸ü¸ÄÉúЧ£º
$ sudo systemctl start docker
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÏÖÔÚ£¬ÈÝÆ÷µÄÈÕÖ¾½«»áͨ¹ýFluentd¾ÙÐÐÍøÂ磬ÎÒÃÇ¿ÉÒÔ½«Æä·¢Ë͵½ElasticsearchµÈ¹¤¾ß¾ÙÐд洢ºÍÆÊÎö¡£
Èý¡¢ÉèÖÃFluentd
ΪÁ˽«ÈÝÆ÷µÄÈÕÖ¾·¢Ë͵½Fluentd£¬ÎÒÃÇÐèÒªÔÚFluentdЧÀÍÆ÷ÉϾÙÐÐÏìÓ¦µÄÉèÖá£
×°ÖÃFluentd
ÔÚFluentdЧÀÍÆ÷ÉÏÖ´ÐÐÒÔÏÂÏÂÁîÒÔ×°ÖÃFluentd£º
$ curl -L https://toolbelt.treasuredata.com/sh/install-ubuntu-xenial-td-agent3.sh | sh
µÇ¼ºó¸´ÖÆ
ÉèÖÃFluentd
±à¼FluentdÉèÖÃÎļþ£¬Ð޸ġ°/etc/td-agent/td-agent.conf¡±Îļþ£¬Ìí¼ÓÈçÏÂÄÚÈÝ£º
<source> @type forward port 24224 bind 0.0.0.0 </source> <match docker.**> @type elasticsearch host 192.168.1.200 port 9200 index_name fluentd type_name docker </match>
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬hostºÍportÊÇElasticsearchЧÀÍÆ÷µÄIPµØµãºÍ¶Ë¿Ú¡£
ÖØÆôFluentd
¸üÐÂÉèÖúó£¬ÖØÐÂÆô¶¯FluentdЧÀÍÒÔʹ¸ü¸ÄÉúЧ£º
$ sudo systemctl restart td-agent
µÇ¼ºó¸´ÖÆ
ÏÖÔÚ£¬FluentdÒѾ׼±¸ºÃÎüÊÕÀ´×ÔÈÝÆ÷µÄÈÕÖ¾ÁË¡£
ËÄ¡¢²âÊÔÈÕÖ¾ÍøÂç
ΪÁ˲âÊÔÎÒÃǵÄÉèÖÃÊÇ·ñÉúЧ£¬ÎÒÃǽ¨ÉèÒ»¸ö¼òÆÓµÄHello WorldÓ¦Ó㬲¢½«Æä´ò°ü³ÉDocker¾µÏñ¡£
½¨ÉèÓ¦ÓÃ
ÔÚÖÕ¶ËÖÐÖ´ÐÐÒÔÏÂÏÂÁîÒÔ½¨ÉèÒ»¸öÃûΪ¡°app.py¡±µÄPythonÓ¦Óãº
$ echo 'print("Hello World!")' > app.py
µÇ¼ºó¸´ÖÆ
½¨ÉèDockerfile
ÔÚͳһĿ¼Ï½¨ÉèÒ»¸öÃûΪ¡°Dockerfile¡±µÄÎļþ£¬ÄÚÈÝÈçÏ£º
FROM python:3 COPY app.py . CMD [ "python", "./app.py" ]
µÇ¼ºó¸´ÖÆ
¹¹½¨¾µÏñ
ÔÚÖÕ¶ËÖÐÖ´ÐÐÒÔÏÂÏÂÁîÒÔ¹¹½¨Docker¾µÏñ£º
$ docker build -t myapp .
µÇ¼ºó¸´ÖÆ
ÔËÐÐÈÝÆ÷
ÔËÐÐÒÔÏÂÏÂÁîÒÔÆô¶¯ÈÝÆ÷£¬²¢Éó²éFluentdЧÀÍÖÐÊÇ·ñÊÕµ½ÁËÀ´×ÔÈÝÆ÷µÄÈÕÖ¾£º
$ docker run myapp
µÇ¼ºó¸´ÖÆ
ÈôÊÇÒ»ÇÐÉèÖÃ׼ȷ£¬Ä㽫ÔÚFluentdЧÀÍÆ÷ÉÏ¿´µ½ÀàËÆÓÚ¡°Hello World!¡±µÄÈÕÖ¾ÐÅÏ¢¡£
×ܽ᣺
ͨ¹ýÒÔÉÏ°ì·¨£¬ÎÒÃÇÀֳɵØÉèÖÃÁËLinuxÉϵÄÈÝÆ÷ÈÕÖ¾ÖÎÀí¡£Ê¹ÓÃFluentdºÍElasticsearchµÈ¹¤¾ß£¬ÎÒÃÇ¿ÉÒÔÇáËɵØÍøÂç¡¢´æ´¢ºÍÆÊÎöÈÝÆ÷µÄÈÕÖ¾£¬ÒÔ±ã¸üºÃµØ¼à¿ØºÍά»¤ÎÒÃǵÄÓ¦ÓóÌÐò¡£Ï£Íû±¾ÎĶÔÄãÔÚLinuxÉÏÉèÖÃÈÝÆ÷ÈÕÖ¾ÖÎÀíÓÐËù×ÊÖú¡£
²Î¿¼Á´½Ó£º
Docker¹Ù·½Îĵµ£ºhttps://docs.docker.com/
Fluentd¹Ù·½Îĵµ£ºhttps://www.fluentd.org/
Elasticsearch¹Ù·½Îĵµ£ºhttps://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖÃÈÝÆ÷ÈÕÖ¾ÖÎÀíµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡