First, you need to install docker
Furthermore, elasticsearch is installed on your other servers or this server (because you need to build a cluster)
Here I will demonstrate how to deploy the es in docker to the local es.
Look first, look at me
Native es:
docker:
I won’t talk about the issues of es installation and docker installation here. Let’s go straight to the topic.
First, we use docker to pull the elasticsearch image (because the version installed on my local machine is es:8.1.2, so the elasticsearch version I use docker to pull is preferably 8.1.2), and then we can execute the docker command
This download may take some time because elasticsearch is very large. Need to wait patiently.
docker pull elasticsearch:8.1.2
After the download is complete, we can execute the following naming to see the image we downloaded (as you can see from here, this image is indeed very large)
docker images
Okay, after the image is pulled, we now operate the local es and then cluster it.
The following is to enter the native es operation. Please pay attention to the fact that it is the native es. Don’t be confused.
Then modify the configuration of the local es (you only need to modify the cluster name here, because if you modify the configuration file in docker by mounting the file, my computer will report an error: device or resource busy )
So I directly changed the local es cluster name to docker-cluster to make it consistent with the es cluster name in docker.
Then start the local es (execute the local es, do not use the root user, I use the xiaomaomi user here)
Go to the bin directory of es and execute ./elasticsearch
./elasticsearch
After the startup is completed, you can change the password (mainly because I forgot the password)
./elasticsearch-reset-password -u elastic -i
Then we use the curl command to test whether the modification and startup are successful.
curl --insecure -u elastic:123456 -XGET "https://192.168.111.138:9200/"
Then we can take a look at the current cluster nodes
curl --insecure -u elastic:123456 -XGET "https://192.168.111.138:9200/_cat/nodes"
We found that there is only one
Then, we generate a token. With this token, a new node can automatically join the cluster (the token validity here is only 30 minutes, so try not to ink it)
./elasticsearch-create-enrollment-token -s node
Okay, that’s it for the local es operation.
Notice! Notice! Notice! Next, it is to operate es in docker
Start es in docker (detailed explanation of each parameter:)
-e: Specify internal environment variables
ENROLLMENT_TOKEN: Use the token generated above to start and automatically join the cluster node of the local es ( note that this token is the token you generated above, do not fill in mine )
-p: indicates the mapped port. Because the local ES has already occupied 9200 and 9300, other ports are given here.
-d: background execution
docker run --name elasticsearch -e ENROLLMENT_TOKEN="eyJ2ZXIiOiI4LjEuMiIsImFkciI6WyIxOTIuMTY4LjExMS4xMzg6OTIwMCJdLCJmZ3IiOiI2OGE4YWIzY2Y1NDIwZDJlY2Q4NzMzMzNlMTA0NDJjNWFhM2VlZWY4ODdhOWZlNmY3ZmE4MTZmY2Y4NDMyMzE2Iiwia2V5IjoiMUFoSE5vSUIzVnNzcVR4V09SVUU6bTFQQlYwYXlRVy1vNmJzcm5xdWVZdyJ9" \
-p 9222:9200 \
-p 9333:9300 \
-d elasticsearch:8.1.2
We can execute the view docker process command to see if it runs successfully.
docker ps
If yours is empty, it proves that there is an error in es in your docker.
(If it is not empty, just look below and change the password of es in docker to start reading)
Then we can check the logs to see what the problem is
docker logs elasticsearch
If a problem does occur (search on Baidu, translate and translate to see what the problem is), after knowing how to solve it, we can close and delete it and run it again
View all processes, because you need to use CONTAINER ID to stop and delete them.
docker ps -a
Then you can execute the stop and delete commands (note that def0135b3e00 here fills in your own id)
docker stop def0135b3e00
docker rm def0135b3e00
Then find the problem, correct the problem, and then go back to starting es in docker and restart that part.
----------------------------------------Separating line (come here directly if there is no error) ----------------------------------
To change the password of es in docker, we need to enter the docker image first.
docker exec -it elasticsearch /bin/bash
cd bin
Then we can execute the command to change the password inside
./elasticsearch-reset-password -u elastic -i
After the modification is successful, we can exit and use the curl command to check whether it is successful. (Note that the port is 9222. We used the local 9222 port earlier and mapped it to the 9200 port in docker)
exit
curl --insecure -u elastic:123456 -XGET "https://192.168.111.138:9222/"
At this point we can check the log of the local es ( note that it is the log of the local es )
We find that we have joined successfully and can then execute the view node.
curl --insecure -u elastic:123456 -XGET "https://192.168.111.138:9200/_cat/nodes"