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

Solution to MySQL remote connection failure

I have encountered the problem that MySQL can con...

How to start multiple MySQL instances in CentOS 7.0 (mysql-5.7.21)

Configuration Instructions Linux system: CentOS-7...

JS+CSS to realize dynamic clock

This article example shares the specific code of ...

Detailed explanation of important cascading concepts in CSS

Recently, I encountered a problem in the process ...

The complete implementation process of Sudoku using JavaScript

Table of contents Preface How to solve Sudoku Fil...

CentOS 7 installation and configuration method graphic tutorial

This article records the detailed installation tu...

What you need to know about MySQL auto-increment ID

Introduction: When using MySQL to create a table,...

The concept of MySQL tablespace fragmentation and solutions to related problems

Table of contents background What is tablespace f...

js canvas realizes rounded corners picture

This article shares the specific code of js canva...

Vue implements carousel animation

This article example shares the specific code of ...

JavaScript realizes the generation and verification of random codes

The generation and verification of random codes i...