First praise after look, form a habit 🌹

Welcome to wechat attention: The way of Java programming progress a little bit every day, precipitation technology to share knowledge.

Docker builds ElasticSearch cluster

Considering that many online ES cluster building methods are very complicated and the ES version is relatively low, a set of ES cluster building process based on Docker test environment is sorted out. It is not necessarily the best method to build Docker cluster, but Docker cluster building must be the fastest method. Go ahead and try it yourself.

Docker-compose is composed for docker container cluster. Docker-compose is composed for docker container cluster. Docker-compose is composed for Docker container cluster Cut the crap and get to the dry stuff!

The prefix

Create the file mount path of each ES node. This article configures the path to keep the same as the above. Docker build ES+Head+Kibana, if you have other needs, please kill yourself!

[root@localhost home]# ll total amount of docker-compose 4-rw-r --r--. 1 root root 2557 9月 8 20:22 docker-compose. Yml DRWX ------. 12 xianglei Xianglei 202 August 30 17:18 xianglei drwXR-XR-x. 5 Xianglei root 45 September 7 21:49 xianglei1 DRWX ------. 12 Xianglei root 202 September 3 20:15 xianglei2 DRWX ------. 12 Xianglei Root 202 September 3 20:14 xianglei3 [root@localhost home]#Copy the code

Grant permissions to non-root users for mounting paths of ES nodes

Chown -r xianglei/Folder pathCopy the code

To avoid unnecessary problems, modify vm.max_map_count

#Direct execution
sysctl -w vm.max_map_count=262144 
#Add a line at the end of /etc/sysctl.conf to make it permanent
vm.max_map_count=262144
Copy the code

Brainless CV operation

You can copy my docker-comemage. yml file directly. I believe you can use the screening method to compare the meaning of the above configuration information.

Version: '3.3' Services: ESmaster: image: ElasticSearch :7.6.2 container_name: ESmaster environment: - node.name=ESmaster - cluster.name=EScluster - discovery.seed_hosts=my_elastcsearch2,my_elastcsearch3 - cluster.initial_master_nodes=ESmaster,my_elastcsearch2,my_elastcsearch3 - bootstrap.memory_lock=true - http.port=9201 - node.master=true - node.data=true - http.cors.allow-origin=* - http.cors.enabled=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m"  ulimits: memlock: soft: -1 hard: -1 volumes: - /home/xianglei1/data/data:/usr/share/elasticsearch/data - /home/xianglei1/logs:/usr/share/elasticsearch/logs - /home/xianglei1/plugins:/usr/share/elasticsearch/plugins ports: - 9201:9201 networks: - mynet my_elastcsearch2: image: Elasticsearch: 7.6.2 container_name: my_elastcsearch2 environment: - node.name=my_elastcsearch2 - cluster.name=EScluster - discovery.seed_hosts=ESmaster,my_elastcsearch3 - cluster.initial_master_nodes=ESmaster,my_elastcsearch2,my_elastcsearch3 - bootstrap.memory_lock=true - http.port=9202 - node.master=true - node.data=true - http.cors.allow-origin=* - http.cors.enabled=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m"  ulimits: memlock: soft: -1 hard: -1 volumes: - /home/xianglei2/data/data:/usr/share/elasticsearch/data - /home/xianglei2/logs:/usr/share/elasticsearch/logs - /home/xianglei2/plugins:/usr/share/elasticsearch/plugins ports: - 9202:9202 networks: - mynet my_elastcsearch3: image: Elasticsearch: 7.6.2 container_name: my_elastcsearch3 environment: - node.name=my_elastcsearch3 - cluster.name=EScluster - discovery.seed_hosts=ESmaster,my_elastcsearch2 - cluster.initial_master_nodes=ESmaster,my_elastcsearch2,my_elastcsearch3 - bootstrap.memory_lock=true - http.port=9203 - node.master=true - node.data=true - http.cors.allow-origin=* - http.cors.enabled=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m"  ulimits: memlock: soft: -1 hard: -1 volumes: - /home/xianglei3/data/data:/usr/share/elasticsearch/data - /home/xianglei3/logs:/usr/share/elasticsearch/logs - /home/xianglei3/plugins:/usr/share/elasticsearch/plugins ports: - 9203:9203 networks: - mynet networks: mynet: driver: bridgeCopy the code

For Kibana and head containers, we can refer to the previous configuration can Docker build ES+ head +Kibana

One thing to note:

  • My cluster uses a new network, the details can be found, the current network is calledhome_mynetSo you need to change the ES node address in the configuration information when you start Kibana, and change — NET to –net home_mynet when you start Kibana
[root@localhost home]# docker network list
NETWORK ID          NAME                DRIVER              SCOPE
58436ed85c2d        bridge              bridge              local
2398670cf8e3        home_mynet          bridge              local
d1bd2ce47aa8        host                host                local
692d4bd9fbfd        mynetwork           bridge              local
478f5a96a153        none                null                local
[root@localhost home]# 
Copy the code

Perform docker – compose. Yml

#Execute in your custom docker-comemage. yml path (this will print a log message)
docker-compose up
#Background Startup
docker-compose up -d
Copy the code

Check whether the cluster container is started

[root@localhost home]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9C8255a53173 Kibana :7.6.2 "/ usr/local/bin/dumb..." 22 minutes ago Up 22 minutes 0.0.0.0:5601->5601/ TCP Kibana 783C863324F8 elasticSearch :7.6.2 "/usr/local/bin/dock..." 34 minutes ago Up 34 minutes 9200/tcp, 9300/tcp, /usr/local/bin/ElastcSearch2 ab54AC7515F3 elasticSearch :7.6.2 "/usr/local/bin/ElastcSearch2 AB54AC7515F3 ElasticSearch :7.6.2" 34 minutes ago Up 34 minutes 9200/tcp, 9300/tcp, 0.0.0.0:9201->9201/ TCP ESmaster 180536eda65B elasticSearch :7.6.2 "/usr/local/bin/dock..." 34 minutes ago Up 34 minutes 9200/tcp, 9300/tcp, My_elastcsearch3 3D18A3B987E1 / ELASticSearch-head :5 "/bin/sh -c 'grunt S..." 9 days ago Up 33 minutes 0.0.0.0:9100->9100/ TCP ElasticSearch -head [root@localhost home]#Copy the code

Let’s see what it looks like

Head

At this point, the ES cluster is completed!

But I also want to emphasize that the current environment is only suitable for learning in a test environment. It is not strictly a cluster, and the ES configuration information in the production environment will be more complex.

But the first step is the hardest! The experience of building a cluster should not have wasted a lot of learning time, for a developer how to use a high-performance ES cluster to achieve business is the ultimate goal.


Next period: ELK environment construction