How to use Docker-compose to build an ELK cluster

How to use Docker-compose to build an ELK cluster

All the orchestration files and configuration files can be accessed on my Github. You can quickly build a 3-instance ES cluster and a Kibana instance by simply modifying the path in the configuration file.

planning

It is planned to create three ES instances to form a cluster, and create a Kibana instance to connect to the cluster. Each ES instance uses a local configuration file to facilitate the storage and version management of the configuration file. Kibana's configuration file is also placed locally and mounted into the container through file mapping.

The overall directory structure is as follows:

$tree
.
├── docker-compose.yml
├── kibana.yml
├── node1
│ └── es1.yml
├── node2
│ └── es2.yml
└── node3
 └── es3.yml

3 directories, 5 files

Arrangement File

The main orchestration file is docker-compose.yml

version: "2.1"
services:
 es-node1:
 image: docker.elastic.co/elasticsearch/elasticsearch:6.7.0
 hostname: es-node1
 expose: #Do not expose the port to applications outside the container - "9001"
 ports: #Expose ports to the host - "9200:9200"
 - "9300:9300"
 volumes:
 - ~/Projects/sh-valley/docker-conf/elasticstack/cluster/node1/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml
 environment:
 - cluster.name=es-cluster
 - bootstrap.memory_lock=true
 - "ES_JAVA_OPTS=-Xms256m -Xmx256m"
 ulimits:
 memlock:
 soft: -1
 hard: -1
 networks:
 es-cluster-network:
 ipv4_address: 172.21.0.10
 es-node2:
 image: docker.elastic.co/elasticsearch/elasticsearch:6.7.0
 hostname: es-node2
 expose: #Do not expose the port to applications outside the container - "9002"
 ports: #Expose the port to the host - "9201:9201"
 - "9301:9301"
 volumes:
 - ~/Projects/sh-valley/docker-conf/elasticstack/cluster/node2/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml
 environment:
 - cluster.name=es-cluster
 - bootstrap.memory_lock=true
 - "ES_JAVA_OPTS=-Xms256m -Xmx256m"
 ulimits:
 memlock:
 soft: -1
 hard: -1
 networks:
 es-cluster-network:
 ipv4_address: 172.21.0.11
 es-node3:
 image: docker.elastic.co/elasticsearch/elasticsearch:6.7.0
 hostname: es-node3
 expose: #Do not expose the port to applications outside the container - "9003"
 ports: #Expose the port to the host - "9202:9202"
 - "9302:9302"
 volumes:
 - ~/Projects/sh-valley/docker-conf/elasticstack/cluster/node3/es3.yml:/usr/share/elasticsearch/config/elasticsearch.yml
 environment:
 - cluster.name=es-cluster
 - bootstrap.memory_lock=true
 - "ES_JAVA_OPTS=-Xms256m -Xmx256m"
 ulimits:
 memlock:
 soft: -1
 hard: -1
 networks:
 es-cluster-network:
 ipv4_address: 172.21.0.12
 kibana:
 image: docker.elastic.co/kibana/kibana:6.7.0
 ports:
 - "5601:5601"
 volumes:
 - ~/Projects/sh-valley/docker-conf/elasticstack/cluster/kibana.yml:/usr/share/kibana/config/kibana.yml
 environment:
 -ELASTICSEARCH_URL=http://es-node1:9200
 networks:
 - es-cluster-network
networks:
 es-cluster-network:
 driver: bridge
 ipam:
 driver: default
 config:
 - subnet: 172.21.0.0/16
 gateway: 172.21.0.1

The ES configuration file only selects one example as follows:

cluster.name: elasticsearch-cluster
node.name: es-node1
network.bind_host: 0.0.0.0
network.publish_host: 172.21.0.10
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true 
node.data: true 
discovery.zen.ping.unicast.hosts: ["172.21.0.10:9300","172.21.0.11:9301","172.21.0.12:9302"]
discovery.zen.minimum_master_nodes: 2

Kibana's configuration file is as follows

server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://es-node1:9200", "http://es-node2:9201", "http://es-node3:9202" ]
xpack.monitoring.ui.container.elasticsearch.enabled: false

Startup Command

After the configuration file is prepared, you can start the cluster

$ docker-compose up -d

The startup process may be slow. You can see the cluster nodes through the command line.

$ curl http://localhost:9200/_cat/nodes
172.21.0.12 51 96 29 6.53 6.43 3.72 md - es-node3
172.21.0.11 47 96 30 6.53 6.43 3.72 mdi - es-node2
172.21.0.10 49 96 30 6.53 6.43 3.72 mdi * es-node1

In the subsequent use process, you can start and stop the service through the docker-compose command. If you do not want to keep the related instances, you can use docker-compose down to shut down and delete the container.

References

elasticsearch document
Docker-compose custom network, fixed container IP address
Difference between docker-compose ports and expose

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:
  • Docker Compose one-click ELK deployment method implementation
  • Sample code for deploying ELK using Docker-compose
  • How to build an elk system using docker compose
  • Use Docker Compose to quickly deploy ELK (tested and effective)

<<:  js implements axios limit request queue

>>:  Graphical introduction to the difference between := and = in MySQL

Recommend

WeChat applet development practical skills: data transmission and storage

Combining the various problems I encountered in m...

Vue's Render function

Table of contents 1. Nodes, trees, and virtual DO...

Example of using setInterval function in React

This article is based on the Windows 10 system en...

MySQL database Shell import_table data import

Table of contents MySQL Shell import_table data i...

MySQL master-slave replication delay causes and solutions

Table of contents A brief overview of the replica...

CSS HACK for IE6/IE7/IE8/IE9/FF (summary)

Since I installed the official version of IE8.0, ...

Solution to the welcome to emergency mode message when booting CentOS7.4

Today I used a virtual machine to do an experimen...

How to optimize the slow Like fuzzy query in MySQL

Table of contents 1. Introduction: 2. The first i...

MySQL 5.7.17 Compressed Version Installation Notes

This article shares the installation steps of MyS...

What is a MySQL tablespace?

The topic I want to share with you today is: &quo...

Steps for restoring a single MySQL table

When I was taking a break, a phone call completel...

Detailed explanation of the installation and use of Vue-Router

Table of contents Install Basic configuration of ...

Detailed explanation of MySQL transaction processing usage and example code

MySQL transaction support is not bound to the MyS...