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

Implementation of pushing Docker images to Docker Hub

After the image is built successfully, it can be ...

How to change the root user's password in MySQL

Method 1: Use the SET PASSWORD command mysql> ...

How to use JavaScript to get the most repeated characters in a string

Table of contents topic analyze Objects of use So...

How to change the encoding to utf-8 in mysql version 5.7 under windows

Preface I just started learning MySQL and downloa...

MySQL 8.0.19 installation and configuration tutorial under Windows 10

I will be learning MySQL next semester. I didn...

Use of SerialPort module in Node.js

Table of contents Purpose Module Installation Bas...

How to get the current time using time(NULL) function and localtime() in Linux

time(); function Function prototype: time_t time(...

Tomcat common exceptions and solution code examples

The company project was developed in Java and the...

Vue recursively implements three-level menu

This article example shares the specific code of ...

CSS 3.0 text hover jump special effects code

Here is a text hovering and jumping effect implem...

SQL interview question: Find the sum of time differences (ignore duplicates)

When I was interviewing for a BI position at a ce...

Detailed explanation of CSS style sheets and format layout

Style Sheets CSS (Cascading Style Sheets) is used...

A brief discussion on the font settings in web pages

Setting the font for the entire site has always b...