Docker install elasticsearch
- 1. Install Docker
- 2. Docker command
- 3. Docker install elasticsearch
- 4. Elasticsearch installs ik Chinese word breaker
- 5. Install ElasticSearch-head
- Six, ElasticSearch configuration to open the account password
- 7. ElasticSearch-head requires account password login
1. Install Docker
1. Uninstall the old version of docker
yum remove docker docker-common docker-selinux docker-engine
2. Install the software package
yum install -y yum-utils device-mapper-persistent-data lvm2
3. Set up Ali warehouse
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4. View the docker version
yum list docker-ce --showduplicates | sort -r
5. Install docker
yum -y install docker-ce-18.03.1.ce
6. Start docker
systemctl start docker
2. Docker command
basic command
1. Start
systemctl stop docker
2. close
systemctl stop docker
3. Restart
systemctl restart docker
4. View information such as images and containers
docker info
5. View version information
docker version
6. View the running status of docker
systemctl status docker
mirror command
1. Query the docker image list
docker images
2. Query by image name
docker search 镜像名称
3. Delete the mirror image
docker rmi IMAGE ID
container command
1. Query containers (only display running containers)
docker ps
2. Query containers (display all containers, including those that are not running)
docker ps -a
3. Close the container
docker container stop CONTAINER ID
4. Start the container
docker container start CONTAINER ID
5. Restart the container
docker container restart CONTAINER ID
6. Delete the container (one image can have multiple containers)
docker rm CONTAINER ID
log command
1. Query the container running log
docker logs -f 容器名称
docker logs -f elasticsearch
3. Docker install elasticsearch
1. Create a host data mount directory and configure permissions
Don't store data in containers, which is
one of the official Docker tips for using containers. Containers can be stopped or deleted at any time. When the container is rmed, the data in the container will be lost. In order to avoid data loss, users can use data volume mount to store data.
That's why the following directory of files is created
[root@localhost ~]# cd /home/
[root@localhost home]# mkdir es7/config -p
[root@localhost home]# mkdir es7/data -p
[root@localhost home]# mkdir es7/plugins -p
[root@localhost home]# cd es7/
[root@localhost es7]# chmod -R 777 /home/es7/
2. Add configuration file
[root@localhost home]# cd /es7/config
[root@localhost config]# touch elasticsearch.yml
[root@localhost config]# vim elasticsearch.yml
Then add in elasticsearch.yml:
network.host: 0.0.0.0
# 可访问IP
http.port: 9200
transport.port: 9300
# 跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
3. Pull the image
docker pull elasticsearch:7.6.2
#docker pull elasticsearch:$version
#When pulling the image, you can specify the version, if not specified, the latest is used by default
4. Create a container
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "ES_JAVA_OPS=-Xms2g -Xmx2g" -v /home/es7/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /home/es7/data:/usr/share/elasticsearch/data -v /home/es7/plugins:/usr/share/elasticsearch/plugins --restart=always -d elasticsearch:7.6.2
5. The browser checks whether elasticsearch starts successfully
http://ip:9200/
4. Elasticsearch installs ik Chinese word breaker
ps: The word breaker version should be consistent with your es version, otherwise the installation will fail
1. Download the tokenizer
https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v7.6.2
2. Install ik
/home/es7/plugins/i
[root@localhost plugins]# mkdir ik -p
[root@localhost plugins]# cd ik
[root@localhost ik]# unzip elasticsearch-analysis-ik-7.6.2.zip
The latter is to restart elasticsearch
3. Test ik
5. Install ElasticSearch-head
1. Install nodejs
download
wget https://nodejs.org/dist/v14.17.4/node-v14.17.4-linux-x64.tar.xz
decompress
tar xf node-v14.17.4-linux-x64.tar.xz
Add environment variables
vim /etc/profile
Add at the end of the file
export NODEJS_HOME=/nodejs安装目录
export PATH=$NODEJS_HOME/bin:$PATH
refresh configuration
source /etc/profile
Confirm whether the installation is successful, check the version number
node -v
npm -v
2. Install elasticsearch-head
download package
https://codeload.github.com/mobz/elasticsearch-head/zip/refs/heads/master
unzip files
unzip elasticsearch-head-master.zip
Go into the elasticsearch-head-maste directory and install node_module
npm install
Background process
nohup npm run start &
Execute exit at last, otherwise it cannot run in the background
exit
The elasticsearch-head port is 9100
Six, ElasticSearch configuration to open the account password
1. Modify elasticsearch.yml
network.host: 0.0.0.0
# 可访问IP
http.port: 9200
transport.port: 9300
# # 跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
# 开启账户密码验证
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
2. Restart elasticsearch
docker container restart CONTAINER ID
3. Go inside the container
#docker exec -it container name bash
docker exec -it elasticsearch bash
4. Set the passwords of elastic, apm_system, kibana, kibana_system, logstash_system, beats_system, remote_monitoring_user users
bin/elasticsearch-setup-passwords interactive
7. ElasticSearch-head requires account password login
127.0.0.1:9200?auth_user=elastic&auth_password=elastic