• 安装docker版elasticsearch和kibana


    本文将介绍用docker的方式安装elasticsearch和kibana,并用浏览器访问elasticsearch。这里的elasticsearch主要给测试环境使用,因此不会设置https和密码。kibana是elasticsearch的前端,可以用来访问elasticsearch,展示数据图表、搜索数据等等。下文以Ubuntu22.04为例。

    一、编写如下docker-compose.yml文件

    在root目录下,用root执行(下同):vim docker-compose.yml,内容如下

    services:
      elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch:8.1.1
        container_name: elastic811
        ulimits:
          memlock:
            soft: -1
            hard: -1
          nofile:
            soft: 65535
            hard: 65535
        ports:
          - "9200:9200"
          - "9300:9300"
        volumes:
          - /data/docker/es811_data/data:/usr/share/elasticsearch/data  # 映射数据文件
        networks:
          - elastic
        environment:
          # 设置适当的内存占用
          - "ES_JAVA_OPTS=-Xms512m -Xmx4096m"
        restart: always
    
      kibana:
        image: docker.elastic.co/kibana/kibana:8.1.1
        container_name: kibana811
        ports:
          - "5601:5601"
        networks:
          - elastic
        depends_on:
          - elasticsearch
        restart: always
    
    networks:
      elastic:
        driver: bridge
    
    • 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
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    创建数据目录:mkdir -pv /data/docker/es811_data/data

    启动docker容器:docker-compose up -d (如果遇到问题,可能是系统open files不够,把宿主机的nofile soft和hard设置为至少65535,自行百度)

    二、编写elasticsearch.yml配置文件

    在root目录下,执行命令 vim elasticsearch.yml,内容如下

    cluster.name: "docker-cluster"
    network.host: 0.0.0.0
    
    # 新增这一行,设为单点模式
    discovery.type: "single-node"
    
    #----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
    #
    # The following settings, TLS certificates, and keys have been automatically
    # generated to configure Elasticsearch security features on 18-05-2024 02:47:05
    #
    # --------------------------------------------------------------------------------
    
    # Enable security features
    # 关闭安全验证
    xpack.security.enabled: false
    
    # 关闭enrollment安全验证
    xpack.security.enrollment.enabled: false
    
    # Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
    xpack.security.http.ssl:
      enabled: false  # 关闭
      keystore.path: certs/http.p12
    
    # Enable encryption and mutual authentication between cluster nodes
    xpack.security.transport.ssl:
      enabled: false  # 关闭
      verification_mode: none  # 设为none
      keystore.path: certs/transport.p12
      truststore.path: certs/transport.p12
    # Create a new cluster with the current node only
    # Additional nodes can still join the cluster later
    #cluster.initial_master_nodes: ["237fa9594e49"]
    
    #----------------------- END SECURITY AUTO CONFIGURATION -------------------------
    
    • 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
    • 32
    • 33
    • 34
    • 35
    • 36

    三、配置elasticsearch并重启

    执行如下命令:

    # 先停止容器
    docker-compose stop
    
    # 拷贝配置文件
    docker cp elasticsearch.yml elastic811:/usr/share/elasticsearch/config/elasticsearch.yml
    
    # 启动容器
    docker-compose start
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    四、从浏览器访问elasticsearch

    http://172.16.2.233:5601/
    172.16.2.233 是宿主机的ip地址。

  • 相关阅读:
    zxing详细使用说明 java生成二维码、条形码
    js异步与同步
    码蹄集需要频繁登录?如何做到“一劳永逸”——码蹄集只登录一次久久不掉线的教程
    【从入门到起飞】JavaSE—IO流(2)字符输入流&&字符输出流
    Java之三大特性
    Presto 之 explain and explain analyze的实现
    java高级用法之:在JNA中将本地方法映射到JAVA代码中
    计数排序与基数排序
    深度学习与总结JVM专辑(四):类文件结构(图文+代码)
    Linux使用rpm包安装mysql5.7
  • 原文地址:https://blog.csdn.net/damiaomiao666/article/details/139025266