• docker compose安装elasticsearch


    docker compose安装 elasticsearch

    安装

    创建目录 es:

    mkdir es
    cd es
    
    • 1
    • 2

    创建挂载目录 data

    mkdir data
    
    • 1

    创建 docker-compose.yml文件:

    version: '3'
    services:
        # search engine
        elasticsearch:
            image: docker.elastic.co/elasticsearch/elasticsearch-oss:7.0.1
    #        image: elasticsearch:7.9.0
            container_name: elasticsearch
            environment:
                - discovery.type=single-node
                - http.port=9200
                - http.cors.enabled=true
    #            - http.cors.allow-origin=http://192.168.93.139:1358
                - http.cors.allow-origin=*
    #            - http.cors.allow-origin=http://localhost:1358,http://127.0.0.1:1358
                - http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
                - http.cors.allow-credentials=false
                - bootstrap.memory_lock=true
                - 'ES_JAVA_OPTS=-Xms512m -Xmx512m'
            volumes:
                - $PWD/data:/usr/share/elasticsearch/data
            ports:
                - '9200:9200'
                - '9300:9300'
        # elasticsearch browser
        dejavu:
            image: appbaseio/dejavu:3.2.3
            container_name: dejavu
            ports:
                - '1358:1358'
            links:
                - elasticsearch
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    其中 dejavu是es的可视化Web管理台

    启动

    docker-compose up -d
    
    • 1

    测试 es是否启动成功,访问: http://192.168.93.130:9200/?pretty:

    {
      "name": "5c7ade417dc7",
      "cluster_name": "docker-cluster",
      "cluster_uuid": "NrFq1k24RLaD5EhRf6kKuA",
      "version": {
        "number": "7.0.1",
        "build_flavor": "oss",
        "build_type": "docker",
        "build_hash": "e4efcb5",
        "build_date": "2019-04-29T12:56:03.145736Z",
        "build_snapshot": false,
        "lucene_version": "8.0.0",
        "minimum_wire_compatibility_version": "6.7.0",
        "minimum_index_compatibility_version": "6.0.0-beta1"
      },
      "tagline": "You Know, for Search"
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    说明启动成功

    创建索引

    PUT http://192.168.93.130:9200/test , 结果

    {
        "acknowledged": true,
        "shards_acknowledged": true,
        "index": "test"
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    获取索引

    GET http://192.168.93.130:9200/test, 结果:

    {
        "test": {
            "aliases": {},
            "mappings": {},
            "settings": {
                "index": {
                    "creation_date": "1598768222773",
                    "number_of_shards": "1",
                    "number_of_replicas": "1",
                    "uuid": "nA152EH8QXmdbWDRDwr1eA",
                    "version": {
                        "created": "7000199"
                    },
                    "provided_name": "test"
                }
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    es可视化管理 dejavu

    老是报403, 解决方案, 将http.cors.allow-origin设置为*

    http.cors.allow-origin=*
    
    • 1

    在这里插入图片描述

    问题

    当将es挂载宿主机目录时,会报错

    java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes

    解决方案

    原因是 自建的在宿主机上的 目录 data,没有足够的权限

    执行

    [root@startsky es]# chmod 777 data
    
    • 1
  • 相关阅读:
    格力售后官方电话 - (24小时全国客服中心)
    Elasticsearch 8.X 如何生成 TB 级的测试数据 ?
    Golang 自定义函数库(个人笔记)
    二、vmware配置集群分发,配置java环境
    组件传值
    【第十一篇】- Git Gitee
    数字视频测量应用技术(基础篇)
    【计算机网络笔记】网络地址转换(NAT)
    day02 springmvc
    算法与数据结构【30天】集训营——图的应用之最小生成树、最短路径、拓扑排序、关键路径(29)
  • 原文地址:https://blog.csdn.net/m0_67393039/article/details/126327095