How to quickly build ELK based on Docker

How to quickly build ELK based on Docker

[Abstract] This article quickly builds a complete ELK system based on the self-built Docker platform. The relevant images are directly obtained from the Docker Hub, which can quickly realize log collection, analysis and retrieval.

Preparing the image

  • Get the ES image: docker pull elasticsearch:latest
  • Get the kibana image: docker pull kibana:latest
  • Get the logstash image: docker pull logstash:latest

Start Elasticsearch

The ES configuration file in the official image is saved in /usr/share/elasticsearch/config. If necessary, this directory can be mapped to the host machine; the data file directory is /usr/share/elasticsearch/data. Here we map the data directory out; the container provides port 9200 by default for API interaction.

docker run --name elasticsearch \
-v "$PWD/esdata":/usr/share/elasticsearch/data \
-p 9200:9200 \
-d elasticsearch

After the container is started, you can call it to verify:

Start Kibana

Kibana, as the UI for ES operations, needs to communicate with the ES container, so here we need to link the ES container and provide port 5601 for page interaction.

docker run --name kibana \
--link elasticsearch:elasticsearch \
-p 5601:5601 \
-d kibana

After the container is started, use a browser to access port 5601 to see the kibana page. When you access it for the first time, you may be prompted that no default index has been created. Here you need to create a default index on the management page. The default index is usually called logstash-*. Create a default index as shown in the following figure.

Start Logstash

The main function of Logstash is to collect logs. This component has many plug-ins and can support most log integration methods, such as TCP, UDP, JDBC, files, queues, etc. Its configuration is very simple and its startup method is also very simple. Here, taking the access log of nginx as an example, we configure logstash to read the access.log of nginx and then forward the log to Elasticsearch.

First compile a logstash configuration file logstash.conf, the content is as follows:

input{
 
   file{
 
      path=>"/tmp/nginx/logs/access.log"
 
   }
 
}output{
 
   stdout{ } #log output to console #output to es
 
   elasticsearch
 
      hosts=>"100.100.x.231"
 
   }
 
}

Start the container. Here we put the nginx log in /tmp/nginx/logs/access.log. In order for the container to read this log, you need to map the log directory to the container.

docker run –it –rm -v /tmp/nginx/logs/access.log:/tmp/nginx/logs/access.log -f /config-dir/logstash.conf

Next, we can test the entire process of log collection and display. First, create some access logs in nginx, for example, directly use curl to call the nginx service port, or directly write data to access.log. At this time, we can see the following log output in the logstash container:

Later, open the Kibana page to see the log data written in real time:

Summarize

Docker containers make it very convenient to build ELK. Through ELK, you can quickly analyze and retrieve logs and find problems. Several core contributors of ELK founded a company called Elastic, which currently has some cooperation with our company. Based on open source, the company has also released some commercial products called X-Pack, which provides many enhancements in machine learning, graph algorithms, and security technologies. Interested students can learn about it for themselves.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Sample code for deploying ELK using Docker-compose
  • A brief summary of the practice of connecting Node framework to ELK
  • Example of using Docker to build an ELK log system
  • In-depth analysis of the ELK principle and introduction

<<:  MySQL 5.7.21 Installer Installation Graphic Tutorial under Windows 10

>>:  Correct use of Vue function anti-shake and throttling

Recommend

Windows Server 2016 Standard Key activation key serial number

I would like to share the Windows Server 2016 act...

Implementation steps for installing Redis container in Docker

Table of contents Install Redis on Docker 1. Find...

Implementation of mysql split function separated by commas

1: Define a stored procedure to separate strings ...

SQL to implement time series dislocation restoration case

Table of contents 1. Requirements description 2. ...

Detailed explanation of how to use the Vue license plate input component

A simple license plate input component (vue) for ...

How to find and delete duplicate rows in MySQL

Table of contents 1. How to find duplicate rows 2...

JavaScript Basics: Immediate Execution Function

Table of contents Immediately execute function fo...

How to make JavaScript sleep or wait

Table of contents Overview Checking setTimeout() ...

Solution to VMware virtual machine no network

Table of contents 1. Problem Description 2. Probl...

A brief understanding of the three uses of standard SQL update statements

1. Environment: MySQL-5.0.41-win32 Windows XP Pro...

Detailed example of IOS database upgrade data migration

Detailed example of IOS database upgrade data mig...

Solution to high CPU usage of Tomcat process

Table of contents Case Context switching overhead...

Several magical uses of JS ES6 spread operator

Table of contents 1. Add attributes 2. Merge mult...

How to understand semantic HTML structure

I believe everyone knows HTML and CSS, knows the ...

Let's talk about the performance of MySQL's COUNT(*)

Preface Basically, programmers in the workplace u...