Docker 安装ElasticSearch

官方网站:https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

1.拉取镜像并运行

#查看image
> docker search elasticsearch

#拉取image
#在该网站查看镜像版本 https://www.elastic.co/cn/downloads/past-releases#elasticsearch >docker pull elasticsearch:8.3.2
# 安装容器
#-e ES_JAVA_OPTS="-Xmx512m -Xms512m" 内存大小
#-e "discovery.type=single-node". 非集群模式
> docker run -d --name esearch -e ES_JAVA_OPTS="-Xmx512m -Xms512m" -e "discovery.type=single-node" 
-v /usr/local/esearch/plugins:/usr/share/elasticsearch/plugins 
-v /usr/local/esearch/data:/usr/share/elasticsearch/data 
-v /usr/local/esearch/logs:/usr/share/elasticsearch/logs 
-p 9200:9200 -p 9300:9300 --privileged=true elasticsearch:8.3.2


2.验证esearch是否安装成功

>curl localhost:9200
curl: (52) Empty reply from server

服务器无响应,修改配置文件

#以root用户进入容器
[root@localhost ~]# docker exec -it -u root esearch /bin/bash
elasticsearch@c26146caf35d:~$ ls  
LICENSE.txt  NOTICE.txt  README.asciidoc  bin  config  data  jdk  lib  logs  modules  plugins
elasticsearch@c26146caf35d:~$ ls config/
certs                              elasticsearch.keystore  jvm.options    log4j2.file.properties  role_mapping.yml  users
elasticsearch-plugins.example.yml  elasticsearch.yml       jvm.options.d  log4j2.properties       roles.yml         users_roles
elasticsearch@c26146caf35d:~$ vi config/elasticsearch.yml 

 

#docker 安装vim 使用如下命令安装:

apt-get update
apt-get install vim

3.修改配置文件

# Enable security features
xpack.security.enabled: false

4.退出容器,重启容器配置生效

#重启容器
[root@localhost ~]# docker restart esearch
esearch

#测试
[root@localhost ~]# curl localhost:9200
{
  "name" : "c26146caf35d",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "11U4QRDsRHatLSS7v68X0Q",
  "version" : {
    "number" : "8.0.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "1b6a7ece17463df5ff54a3e1302d825889aa1161",
    "build_date" : "2022-02-03T16:47:57.507843096Z",
    "build_snapshot" : false,
    "lucene_version" : "9.0.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

 5.配置分词器

#https://github.com/medcl/elasticsearch-analysis-ik
#版本要对应

  5.1.download or compile

  • optional 1 - download pre-build package from here: https://github.com/medcl/elasticsearch-analysis-ik/releases, download .zip file

    create plugin folder cd your-es-root/plugins/ && mkdir ik

    unzip plugin to folder your-es-root/plugins/ik

  • optional 2 - use elasticsearch-plugin to install ( supported from version v5.5.1 ):

    ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.3.0/elasticsearch-analysis-ik-6.3.0.zip
    
     

    NOTE: replace 6.3.0 to your own elasticsearch version

  5.2.restart elasticsearch

 

 

posted @ 2022-07-13 15:31  RyderWang  阅读(124)  评论(0编辑  收藏  举报