Use MongoDB to store Docker logs __ Storage

Source: Internet
Author: User
Tags mongodb docker run fluentd

Log is a very important part of the system, through the log can be found in time the problems in the system, but also to provide clues to repair problems. Docker provides a variety of plug-in ways to manage logs, and this article records the process of using MongoDB to store Docker logs.Data FlowCreated with Raphaël 2.1.2 Start Docker container fluentd MongoDB End

The date produced by the Docker is sent to the FLUENTD, and then FLUENTD is transferred to MongoDB. Configure Fluentd

Prerequisite: Operating system is CentOS7, installed MongoDB3.4 1. Install Fluentd

The CentOS 7 software library does not contain FLUENTD installation packages, so you need to install them manually. The software td-agent used in CentOS.

# curl-l Https://toolbelt.treasuredata.com/sh/install-redhat-td-agent3.sh | Sh

The above command creates a Td-agent installation library Td.repo in the/etct/yum.repo.d/directory, and then automatically installs Td-agent. Set to start automatically when the installation is complete.

# Systemctl start td-agent
# Systemctl Enable Td-agent

If a problem occurs during startup, you can view the log file located under/var/log/td-agent/td-agent.log 2. Configure to dump Docker logs to MongoDB

Plug-in support is required for the dump to MongoDB, but Td-agent is not installed by default and needs to be installed.

# yum-y Install td-agent-gemt
# Td-agent-gem Install Fluent-plugin-mongo

Edit/etc/td-agent/td-agent.conf, add

# # Match tag=docker.* and dump to MongoDB
# # When the Docker starts the container, the tag of the log should conform to the docker.* form
<match docker.*>
  @ Type MONGO
  # database address
  host 127.0.0.1
  # database ports Port
  22017
  # Store log database and dataset name db
  Docker
  Collection Log
</match>

Restart Td-agent. Start Container

The command to start the container is changed to:

$ docker Run--mount Type=bind,source=/home/demo/app,destination=/app--log-driver=fluentd--log-opt tag= "Docker.log" Python3:latest python3/app/test.py

After you have finished running, you can view the log in MongoDB.

Reference Documentation:
Https://docs.treasuredata.com/articles/td-agent
https://docs.docker.com/engine/admin/logging/fluentd/
Https://docs.fluentd.org/v1.0/articles/out_mongo

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.