Docker安装ElasticSearch

Posted killbill

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker安装ElasticSearch相关的知识,希望对你有一定的参考价值。

1、从dockerHub拉取官方ElasticSearch镜像

官方仓库 :https://hub.docker.com/

docker pull elasticsearch:7.10.1
2、创建容器挂载目录并授权,持久化容器数据和配置

创建三个目录分别挂载配置config、数据data、插件plugins

mkdir -p /elasticsearch/data 
mkdir -p /elasticsearch/config 
mkdir -p /elasticsearch/plugins 

授予读写执行权限

chmod -R 777 /elasticsearch
3、创建docker-compose.yml文件,使用docker-compose启动容器

环境变量中可以指定ES内存占用

version: \'2\'
services:
  elasticsearch:
    container_name: elasticsearch
    image: elasticsearch:7.10.1
    ports:
      - "9200:9200"
    volumes:
      - /elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /elasticsearch/data:/usr/share/elasticsearch/data
      - /elasticsearch/plugins:/usr/share/elasticsearch/plugins
    environment:
      - "ES_JAVA_OPTS=-Xms64m -Xmx512m"
      - "discovery.type=single-node"
      - "COMPOSE_PROJECT_NAME=elasticsearch-server"
    restart: always
4、使用docker-compose在docker-compose.yml所在目录启动容器
docker-compose up -d

查看容器是否成功启动

docker ps -a | grep elasticsearch 

测试访问
curl http://192.168.0.50:9200/
返回

{
  "name" : "37da3258e541",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "pxYI8abQQA-F7wKqP6cG3w",
  "version" : {
    "number" : "7.10.1",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "1c34507e66d7db1211f66f3513706fdf548736aa",
    "build_date" : "2020-12-05T01:00:33.671820Z",
    "build_snapshot" : false,
    "lucene_version" : "8.7.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

成功啦~~~

以上是关于Docker安装ElasticSearch的主要内容,如果未能解决你的问题,请参考以下文章

docker安装kibana

docker安装elasticsearch

Docker安装ElasticSearch

Docker安装ElasticSearch和Kibana

Docker安装ElasticSearch和Kibana

Docker安装ElasticSearch和Kibana