SpringBoot and Elasticsearch are perfectly integrated, and WebFlux responsive programming is implemented

【Part 1】Install the new version of Elasticsearch(8.8.0)andKibana(8.8.0)

The original text was published in: Practical combat: Perfect integration of Spring Boot and Elasticsearch, WebFlux responsive programming implementation [1], welcome to use RSS subscription [2] to get the latest updates.

1. Preface

The article contains the following content:

  • Install new versions ofElasticsearch(8.8.0)andKibana(8.8.0)

  • SpringBoot integrates Elasticsearch CRUD and WebFlux to achieve fully responsive programming
    • Java17

    • spring-boot 3.1.2

    • SSL connectionElasticsearch

  • Filebeat(8.8.0)Installation and uploadingThe logs generated by the SpringBoot project can be queried on Kibana

Build environment:

  • GNU/linux host with Docker installed

I’m very excited about reactive programming recently, and I want to use it to write everything. It’s like seeing everything with a hammer as a nail. I happened to want to use ES (Elasticsearch) for some of my own projects, so I just learned how to do fully responsive programming and CRUD for ES, but I still encountered a lot of problems,because There is a lot of content, so I will explain each part in several sections.

2. Install the new version of Elasticsearch (8.8.0) and Kibana (8.8.0)

I don’t need to introduce what Elasticsearch is. It can query billions of data in milliseconds.

The official installation documentation is here: run-elasticsearch-locally[3]

If it’s too long, just read the simple version below:

2.1 Create directories for ES data storage, plug-ins, and logs

mkdir /dockerData/elasticsearch/data
mkdir /dockerData/elasticsearch/plugins
mkdir /dockerData/elasticsearch/logs

2.2 Running ES container

Create a network to interact with kibana
docker network create elastic
Pull the specified version image
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.8.0

docker run -d \
    --name elasticsearch \
    -e "ES_JAVA_OPTS=-Xms4096m -Xmx4096m" \
    -e "discovery.type=single-node" \
   -v /dockerData/elasticsearch/data:/usr/share/elasticsearch/data \
   -v /dockerData/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
    -v /dockerData/elasticsearch/logs:/usr/share/elasticsearch/logs \
    --privileged \
    --network elastic \
    -p 9200:9200 \
    -p 9300:9300 \
docker.elastic.co/elasticsearch/elasticsearch:8.8.0

  • -d: Indicates running the container in “background mode” (detached mode). Even if the terminal is closed or the SSH session is exited, the container will still remain running.

  • -name elasticsearch: Specify the name of the container as “elasticsearch” so that you can use the name to manage and access the container in the future.

  • -e "ES_JAVA_OPTS=-Xms4096m -Xmx4096m": Set the Java virtual machine options of Elasticsearch. Here set the initial heap memory (Xms) and maximum heap memory (Xmx) is 4GB, which is 4096MB. This can be adjusted according to your machine.

  • -e "discovery.type=single-node": Set the node discovery type of Elasticsearch to single-node, which means that Elasticsearch will run as a separate node rather than as a cluster part of.

  • -v /dockerData/elasticsearch/data:/usr/share/elasticsearch/data: Mount the /dockerData/elasticsearch/data directory on the host to the container The /usr/share/elasticsearch/data directory is used to persistently store Elasticsearch data.

  • -v /dockerData/elasticsearch/plugins:/usr/share/elasticsearch/plugins: Mount the /dockerData/elasticsearch/plugins directory on the host to the container /usr/share/elasticsearch/plugins directory, used to store Elasticsearch plug-ins.

  • -v /dockerData/elasticsearch/logs:/usr/share/elasticsearch/logs: Mount the /dockerData/elasticsearch/logs directory on the host to the container The /usr/share/elasticsearch/logs directory is used to store Elasticsearch log files.

  • -privileged: Provides the container to run in privileged mode, which may be necessary for some special needs.

  • -network elastic: Connect the container to the Docker network named “elastic”. This network is usually used to connect Elasticsearch, Kibana and other Elastic Stack components.

  • -p 9200:9200: Maps the 9200 port of the host to the 9200 port in the container, which is used to access the Elasticsearch HTTP API.

  • -p 9300:9300: Maps port 9300 of the host to port 9300 in the container, which is used for inter-node communication (cluster communication) of Elasticsearch.

  • docker.elastic.co/elasticsearch/elasticsearch:8.8.0: Specify the Elasticsearch Docker image and its version to be used. The 8.8.0 version is used here.

Some students who have installed ES may ask, here I directly use “background mode” (detached mode), so how do I see the token generated for the first time? Don’t worry, there is a new method now, which will be mentioned when installing kibana.

2.3 Running Kibana container

Regarding the following two lines, it should be noted that I am not running this Kibana in background mode, so it is convenient to wait and see the generated verification code.

docker pull docker.elastic.co/kibana/kibana:8.8.0
docker run --name kibana --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:8.8.0

After the Kibana container is running, use a browser to open the server’s ip:5601. If you are using a cloud service, don’t forget to configure the cloud service configuration security group rules. Then you will see that we need to enter ES. token.

We reopen a terminal to connect to the server, and then enter the following command to enter the container’s terminal

docker exec -it elasticsearch /bin/bash

Then regenerate a token through the following command

bin/elasticsearch-create-enrollment-token --scope kibana

At this point you will see that the terminal will generate a token. You need to copy this token to the browser kibana page and write it down in a scratch pad first.

You also need to generate a password through the following command, write it down, and you will use it to log in to kibana.

bin/elasticsearch-reset-password -u elastic

As shown in the picture:

Fill in token

After the input is completed, click Configure Elastic and you will see that we need to output a verification code

This verification code can be found in the terminal where Kibana was just opened, as shown below:

After the input is completed, you will need the password we just generated to log in to Kibana.

At this point, the installation of ES and Kibana is completed. You can explore what fun things there are in the new version of ES.

Next chapter: [2] Practical combat: perfect integration of SpringBoot and Elasticsearch, WebFlux responsive programming implementation [4]

Reference materials

[1]

https://runnable.run/archives/-yi–chao-ji-feng-he-guai-zhi-shou-ba-shou-da-jian-ni-de-xiang-ying-shi-sou-suo- yin-qing-hou-duan-kuang-jia: https://link.juejin.cn/?target=https://runnable.run/archives/-yi–chao-ji-feng-he- guai-zhi-shou-ba-shou-da-jian-ni-de-xiang-ying-shi-sou-suo-yin-qing-hou-duan-kuang-jia

[2]

https://runnable.run/feed: https://link.juejin.cn/?target=https://runnable.run/feed

[3]

https://www.elastic.co/guide/en/elasticsearch/reference/current/run-elasticsearch-locally.html#run-elasticsearch-locally: https://link.juejin.cn/?target= https://www.elastic.co/guide/en/elasticsearch/reference/current/run-elasticsearch-locally.html#run-elasticsearch-locally

[4]

https://juejin.cn/post/7261269922734784567: https://juejin.cn/post/7261269922734784567

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. Cloud native entry-level skills treeHomepageOverview 16,757 people are learning the system