admin管理员组

文章数量:1624786

目录

  • 前言
  • 安装ElasticSearch/ES
    • 安装步骤1:准备
      • 1. 安装docker
      • 2. 搜索可以使用的镜像。
      • 3. 也可从docker hub上搜索镜像。
      • 4. 选择合适的redis镜像。
    • 安装步骤2:拉取ElasticSearch镜像
      • 1 拉取镜像
      • 2 查看已拉取的镜像
    • 安装步骤3:创建容器
      • 创建容器方式1:快速创建容器
    • 安装步骤4:运行容器
    • 安装步骤5:检查是否安装成功
  • ElasticSearch配置
    • 工作目录/WorkingDir
    • 设置跨域请求
    • 重置密码
    • 启用用户名密码访问
    • 设置 JVM 内存参数
  • 容器设置
    • 容器随 docker 自动启动
    • 容器设置IP
  • 安装elasticsearch-head
  • 安装Kibana
  • 其它
    • 查看 elasticsearch 的版本
    • 把容器中的 ElasticSearch 文件复制出来
  • 参考

前言

  • TencentOS Server 3.1
  • Docker version 19.03.14, build 5eb3275d40
  • elasticsearch: 8.9.0

安装ElasticSearch/ES

安装步骤1:准备

1. 安装docker

安装 docker 参考:【Centos 8】【Centos 7】安装 docker

2. 搜索可以使用的镜像。

shell> docker search elasticsearch
NAME                                     DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
elasticsearch                            Elasticsearch is a powerful open source sear…   6115      [OK]       
kibana                                   Kibana gives shape to any kind of data — str…   2622      [OK]       
        

3. 也可从docker hub上搜索镜像。

docker hub,docker hub-stage。

4. 选择合适的redis镜像。

查找镜像。

版本拉取命令
最新版本docker pull elasticsearch:latest
7.4.0docker pull elasticsearch:7.4.0
7.12.0docker pull elasticsearch:7.12.0
8.0.0docker pull elasticsearch:8.0.0
8.9.0docker pull docker.elastic.co/elasticsearch/elasticsearch:8.9.0

安装步骤2:拉取ElasticSearch镜像

1 拉取镜像

shell> docker pull docker.elastic.co/elasticsearch/elasticsearch:8.9.0
8.9.0: Pulling from elasticsearch/elasticsearch
7a0437f04f83: Pull complete 
2b674c951ca3: Pull complete 
06baeb69f25f: Pull complete 
eeff01d19ce5: Pull complete 
a994306398ca: Pull complete 
2c002d76c1f6: Pull complete 
6286f2196f9b: Pull complete 
Digest: sha256:33d0cb2bb128ddcfbce810e2afd5a30d110ee21778e8805940c4d37f5ab80601
Status: Downloaded newer image for docker.elastic.co/elasticsearch/elasticsearch:8.9.0
docker.elastic.co/elasticsearch/elasticsearch:8.9.0

2 查看已拉取的镜像

shell> docker images
REPOSITORY                                      TAG       IMAGE ID       CREATED         SIZE
docker.elastic.co/elasticsearch/elasticsearch   8.9.0     281908e9f34e   2 weeks ago     1.34GB
hello-world                                     latest    9c7a54a9a43c   3 months ago    13.3kB
nacos/nacos-server                              v2.2.1    faff56ad2ef5   4 months ago    1.17GB
redis                                           6.2.1     de974760ddb2   2 years ago     105MB
elasticsearch                                   7.12.0    9337ed510a0c   2 years ago     830MB
mysql                                           5.7.31    42cdba9f1b08   2 years ago     448MB
mobz/elasticsearch-head                         5         b19a5c98e43b   6 years ago     824MB

安装步骤3:创建容器

创建容器方式1:快速创建容器

shell> docker create -e "discovery.type=single-node" \
--name elasticsearch1 -p 9200:9200  -p 9300:9300 \
docker.elastic.co/elasticsearch/elasticsearch:8.9.0

安装步骤4:运行容器

shell> docker start elasticsearch1

安装步骤5:检查是否安装成功

浏览器访问http://localhost:9200, 如果出现以下界面就是安装成功:

ElasticSearch配置

工作目录/WorkingDir

"WorkingDir": "/usr/share/elasticsearch" 

设置跨域请求

shell> docker exec -it elasticsearch1 /bin/bash
shell> vi /usr/share/elasticsearch/config/elasticsearch.yml

增加如下配置:

xpack.security.enabled: false
xpack.security.http.ssl.enabled: false
http.cors:
  enabled: true
  allow-origin: "*"

重置密码

shell> docker exec -it elasticsearch1 /bin/bash
shell> /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
WARNING: Owner of file [/usr/share/elasticsearch/config/users] used to be [root], but now is [elasticsearch]
WARNING: Owner of file [/usr/share/elasticsearch/config/users_roles] used to be [root], but now is [elasticsearch]
This tool will reset the password of the [elastic] user to an autogenerated value.
The password will be printed in the console.
Please confirm that you would like to continue [y/N]y


Password for the [elastic] user successfully reset.
New value: bAdUgEN9******

启用用户名密码访问

shell> docker exec -it elasticsearch1 bash
shell> vi /usr/share/elasticsearch/config/elasticsearch.yml

修改配置:

xpack.security.enabled: true
xpack.security.http.ssl.enabled: false
http.cors:
  enabled: true
  allow-origin: "*"
  allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

设置 JVM 内存参数

shell> docker exec -it elasticsearch1 /bin/bash
shell> vi /usr/share/elasticsearch/config/jvm.options

修改如下配置:

################################################################
## IMPORTANT: JVM heap size
################################################################
##
## The heap size is automatically configured by Elasticsearch
## based on the available memory in your system and the roles
## each node is configured to fulfill. If specifying heap is
## required, it should be done through a file in jvm.options.d,
## which should be named with .options suffix, and the min and
## max should be set to the same value. For example, to set the
## heap to 4 GB, create a new file in the jvm.options.d
## directory containing these lines:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/8.9/heap-size.html
## for more information
##
################################################################
-Xms1g
-Xmx1g

容器设置

容器随 docker 自动启动

设置容器的重启策略

shell> docker update --restart=always elasticsearch1
  • 每次docker启动时,容器也会自动启动

容器设置IP

向网络中添加容器

shell> docker network connect --ip 172.19.0.2  mynetwork elasticsearch1 
  • docket ip : 172.19.0.2

安装elasticsearch-head

Docker安装 elasticsearch-head

安装Kibana

其它

查看 elasticsearch 的版本

查看容器的版本:

shell> docker ps | grep elasticsearch1 
8c23805f805c   docker.elastic.co/elasticsearch/elasticsearch:8.9.0   "/bin/tini -- /usr/l…"   9 days ago       Up 11 hours     0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp   elasticsearch1

登录容器查看版本:

shell> docker exec -it elasticsearch1 bin/elasticsearch -V
Version: 8.9.0, Build: docker/8aa461beb06aa0417a231c345a1b8c38fb498a0d/2023-07-19T14:43:58.555259655Z, JVM: 20.0.2

把容器中的 ElasticSearch 文件复制出来

shell> docker cp -a elasticsearch1:/usr/share/elasticsearch /data/elasticsearch1/eg

参考

https://blog.csdn/qq_40942490/article/details/111594267
https://wwwblogs/jianxuanbing/p/9410800.html
https://blog.csdn/teyue87/article/details/122626499
https://blog.csdn/qq_44732146/article/details/120744829
https://gitee/mirrors/elasticsearch
https://github/mobz/elasticsearch-head

本文标签: ElasticsearchDockeres