docker入门:单机elasticsearch安装记录,保证无坑

这是我参与 8 月更文挑战的第 10 天,活动详情查看: 8月更文挑战node

用过传统方式安装elasticsearch的小伙伴都知道,有很是多的坑须要填。常常抛出莫名的异常,因此本篇楼主将本身安装单机elasticsearch过程记录下来,帮助小伙伴闭坑。git

 注意:kibana,es,es插件版本要相同github

1.拉取镜像

docker pull elasticsearch:7.10.1
复制代码

2.新建文件夹

同上文所述相同,须要在宿主机上挂载配置文件与数据文件。web

mkdir -p /usr/local/elasticsearch/config
mkdir -p /usr/local/elasticsearch/data
复制代码

3.修改配置文件

在中间价的安装中不少个性化设置须要自行修改。这里进入上文新建好的文件夹中。新增elasticsearch.yml文件。spring

cd /usr/local/elasticsearch/config/
vi elasticsearch.yml
复制代码

elasticsearch.yml配置以下docker

network.host: 0.0.0.0   
network.bind_host: 0.0.0.0  #外网可访问

http.cors.enabled: true
http.cors.allow-origin: "*"
xpack.security.enabled: true # 这条配置表示开启xpack认证机制 spring boot链接使用
xpack.security.transport.ssl.enabled: true
复制代码

xpack.security配置后,elasticsearch须要帐号密码使用,建议安排上。若是使用springboot查询,那必定要设置,否者会报错!springboot

4.启动

docker run -p 9200:9200 --name elasticsearch \
-e  "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms1g -Xmx2g" \
-v /usr/local/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /usr/local/elasticsearch/data:/usr/share/elasticsearch/data \
-v /usr/local/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.10.1
复制代码

参数解释:bash

  • -p 9200:9200 :指定端口号
  • --name elasticsearch \ :指定容器名称
  • -e "discovery.type=single-node" \ :单机模式
  • -e ES_JAVA_OPTS="-Xms1g -Xmx2g" \ :指定内存
  • -v /usr/local/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \ :指定config在宿主机位置
  • -v /usr/local/elasticsearch/data:/usr/share/elasticsearch/data \ :指定数据在宿主机位置
  • -v /usr/local/elasticsearch/plugins:/usr/share/elasticsearch/plugins \ :指定插件在宿主机位置
  • -d elasticsearch:7.10.1 :指定镜像

5.初始化密码

此项仅在上文xpack配置的状况下才须要执行,首先进入容器命令行,而后直行初始化命令:markdown

执行cors

docker exec -it 容器id /bin/bash
bin/elasticsearch-setup-passwords interactive
复制代码

而后依次输入密码(须要输入不少不少次,别挣扎了,输入吧!)

image.png

6.验证

访问ip:9200,若是上文开启了xpack.security,须要输入帐号密码。
帐号/密码:elastic/上文设置的密码

若是出现如下页面,则表明成功。 image.png

7.安装插件

1.安装

下载地址:github.com/medcl/elast… 主要须要选择与es相同版本

放于上文配置plugins路径,而后新建ik文件夹,将解压后的文件所有放于ik文件夹中。

image.png

重启docker容器

docker restart 556b198b7616
复制代码

2.验证

重启后,请经过查询验证分词器是否生效。

GET _analyze?pretty
  {
    "analyzer": "ik_max_word",
    "text": "我吃西红柿"
  }
复制代码

若是出现如下结果,则证实安装生效。

image.png

相关文章
相关标签/搜索