Sample code for installing ElasticSearch and Kibana under Docker

Sample code for installing ElasticSearch and Kibana under Docker

1. Introduction

Elasticsearch is very popular now, and many companies are using it, so if you don’t know about es, you may be looked down upon. So here I decided to learn es. I prefer docker, so I used docker to install es. Here I will introduce the installation details and the things that need attention in detail. I will not explain the installation of docker here, you can install it by yourself, it is very simple, I promise you may really fall in love with it. The computer I use here is a MacBook Pro. If it is Linux, it is basically the same. If it is Windows, it may be different. I have not actually operated it here. If you are interested, you can try it yourself.

2.ElasticSearch installation

2.1 Install es in docker

To use es, you must install it. Since I am used to docker, I also want to try it on docker, mainly because many of my software have chosen docker. Docker installation is actually very simple, and only requires one line of command. Here I choose es 7.2.0 version mirror image installation, the specific installation command is as follows:

docker pull elasticsearch:7.2.0

After typing the command, press Enter and wait for the image download to complete.

2.2 Start es

After the installation is complete, of course you need to start our es. It is also very convenient to start here, just one line of command is enough. as follows:

docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -d elasticsearch:7.2.0

This way es is started. We can check whether es is installed successfully by entering the command:

curl http://localhost:9200

Or open the URL http://localhost:9200 in the browser. If you can see the following information, it means that our es has been installed.

{
 "name" : "530dd7820315",
 "cluster_name" : "docker-cluster",
 "cluster_uuid" : "7O0fjpBJTkmn_axwmZX0RQ",
 "version" : {
  "number" : "7.2.0",
  "build_flavor" : "default",
  "build_type" : "docker",
  "build_hash" : "508c38a",
  "build_date" : "2019-06-20T15:54:18.811730Z",
  "build_snapshot" : false,
  "lucene_version" : "8.0.0",
  "minimum_wire_compatibility_version" : "6.8.0",
  "minimum_index_compatibility_version" : "6.0.0-beta1"
 },
 "tagline" : "You Know, for Search"
}

If you install it on a server, you must open port 9200 of your server for external access, and then replace localhost with the IP address of your server.

2.3 Modify the configuration to solve the cross-domain access problem

First enter the container, then enter the specified directory to modify the elasticsearch.yml file.

docker exec -it elasticsearch /bin/bash
cd /usr/share/elasticsearch/config/
vi elasticsearch.yml

Add to the end of the elasticsearch.yml file:

http.cors.enabled: true
http.cors.allow-origin: "*"

After modifying the configuration, restart the container.

docker restart elasticsearch

2.4 Install ik word segmenter

The word segmenter that comes with es is not very friendly to Chinese word segmentation, so we download the open source IK word segmenter to solve this problem. First, go to the plugins directory to download the word segmenter, unzip it after downloading, and then restart es. The specific steps are as follows:

Note: The version of elasticsearch and the version of ik tokenizer need to be consistent, otherwise it will fail when restarted. You can view all versions here, select the version that suits you, right-click and copy the link address. Click here

cd /usr/share/elasticsearch/plugins/
elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.2.0/elasticsearch-analysis-ik-7.2.0.zip
exit
docker restart elasticsearch 

Then you can verify whether the installation is successful in the dev tools of the kibana interface;

POST test/_analyze
{
 "analyzer": "ik_max_word",
 "text": "Hello, I am Dongxie Jiafly"
}

Without adding "analyzer": "ik_max_word", each word is segmented. You can try it after installing kibana below.

3. Kibana installation

3.1 Install kibana in docker

The same command for installing kibana with docker is as follows:

docker pull kibana:7.2.0

Wait for all images to be downloaded.

3.2 Start Kibana

After the installation is complete, you need to start the kibana container and use --link to connect to the elasticsearch container. The command is as follows:

docker run --name kibana --link=elasticsearch:test -p 5601:5601 -d kibana:7.2.0
docker start kibana

After starting, you can open the browser and enter http://localhost:5601 to open the kibana interface.

4. Conclusion

After the above steps, es and kibana are installed. Isn’t it simple? This is one of the benefits of Docker, and one of the reasons why I prefer Docker. Of course, Docker has far more functions than these. We will write more about them later. In short, they can definitely be used. Ha ha

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:
  • How to install elasticsearch and kibana in docker
  • How to install ElasticSearch on Docker in one article
  • How to install kibana tokenizer inside docker container
  • Teach you how to install ElasticSearch and Kibana on Docker

<<:  JavaScript implements draggable progress bar

>>:  MySQL 8.0.12 decompression version installation tutorial personal test!

Recommend

Some functions of using tcpdump to capture packets in the Linux command line

tcpdump is a flexible and powerful packet capture...

How to redirect nginx directory path

If you want the path following the domain name to...

CSS to achieve horizontal lines on both sides of the middle text

1. The vertical-align property achieves the follo...

Tutorial on using prepare, execute and deallocate statements in MySQL

Preface MySQL officially refers to prepare, execu...

How to fix abnormal startup of mysql5.7.21

A colleague reported that a MySQL instance could ...

MySQL Quick Data Comparison Techniques

In MySQL operation and maintenance, a R&D col...

Initial summary of the beginner's website building tutorial

After writing these six articles, I started to fee...

Linux kernel device driver memory management notes

/********************** * Linux memory management...

js implements mouse in and out card switching content

This article shares the specific code of js to re...

Detailed explanation of the use of MySQL group links

Grouping and linking in MYSQL are the two most co...

JavaScript data flattening detailed explanation

Table of contents What is Flattening recursion to...

UCenter Home site adds statistics code

UCenter Home is an SNS website building system rel...

MySQL Series 11 Logging

Tutorial Series MySQL series: Basic concepts of M...

JavaScript implements asynchronous submission of form data

This article example shares the specific code of ...