elasticsearch docker的安装步骤

原创:elasticsearch2019/12/17发布pv:1uv:1ip:1twitter #elasticsearch

原文地址:https://www.douyacun.com/article/7d6abdb583f8dcea7e3ec37e1faa32cd

elasticsearch 安装

下载和安装步骤

官方文档给出的安装步骤是比较详细的

  1. 下载压缩文件
  2. Linux运行 bin/elasticsearch Windows运行bin\elasticsearch.bat
  3. curl http://localhost:9200/

文件描述符限制

/etc/security/limits.conf

*               soft    nofile          65536
*               hard    nofile          65536
*               soft    nproc           4096
*               hard    nproc           4096

启动内存不足

Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /data/elasticsearch-5.2.2/hs_err_pid26945.log

vim config/jvm.options

-Xms/-Xmx 设置成同等大小

-Xmx 不要超过内存的50%,不要超过30G

不能以root启动

这个就新增一个用户

useradd www
sudo su www
./elasticsearch/bin/elasticsearch

插件安装

安装一个中文智能分词插件 Smart Chinese Analysis plugin

➜  elasticsearch-7.5.0 bin/elasticsearch-plugin install analysis-smartcn
-> Downloading analysis-smartcn from elastic
[=================================================] 100%
-> Installed analysis-smartcn
➜  elasticsearch-7.5.0 bin/elasticsearch-plugin list
analysis-smartcn

多实例运行

bin/elasticsearch -E node.name=n1 -E cluster.name=douyacun -E path.data=n1_data -d
bin/elasticsearch -E node.name=n2 -E cluster.name=douyacun -E path.data=n2_data -d
bin/elasticsearch -E node.name=n3 -E cluster.name=douyacun -E path.data=n3_data -d

查看当前运行实例的情况

➜  elasticsearch-7.5.0 curl -X GET http://127.0.0.1:9200/_cat/nodes
127.0.0.1 13 91 7 2.61   dilm - n2
127.0.0.1 16 91 7 2.61   dilm - n3
127.0.0.1 28 91 7 2.61   dilm * n1

关闭已经运行的实例

ps|grep elastic|awk '{print  $1}'|xargs kill

docker 运行elastic search/kibana

$ docker pull elasticsearch:7.5.0
$ vim docker-compose.yml

version: '2.2'
services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.5.0
    container_name: es01
    environment:
      - node.name=es01
      - cluster.name=douyacun
      - discovery.seed_hosts=es02,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - elastic
  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.5.0
    container_name: es02
    environment:
      - node.name=es02
      - cluster.name=douyacun
      - discovery.seed_hosts=es01,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data02:/usr/share/elasticsearch/data
    networks:
      - elastic
  es03:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.5.0
    container_name: es03
    environment:
      - node.name=es03
      - cluster.name=douyacun
      - discovery.seed_hosts=es01,es02
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data03:/usr/share/elasticsearch/data
    networks:
      - elastic
  kibana:
    image: docker.elastic.co/kibana/kibana:7.5.0
    container_name: kibana75
    environment:
      - I18N_LOCALE=zh-CN
      - XPACK_GRAPH_ENABLED=true
      - TIMELION_ENABLED=true
      - XPACK_MONITORING_COLLECTION_ENABLED="true"
      - ELASTICSEARCH_HOSTS=http://es01:9200
    ports:
      - "5601:5601"
    networks:
      - elastic
  cerebro:
    image: lmenezes/cerebro:latest
    container_name: cerebro
    ports:
      - 9000:9000
    command:
      - -Dhosts.0.host=http://es01:9200
    networks:
      - elastic 
volumes:
  data01:
    driver: local
  data02:
    driver: local
  data03:
    driver: local

networks:
  elastic:
    driver: bridge

    
$ docker-compose up
  • volumes: 容器删除以后数据不会影响,具体原理看一下docker官方的解释
  • es01、es02、es03、kibana、cerebro必须在同一个网络下边,不多解释
  • cerebro 设置elasticsearch网络: -Dhosts.0.host=http://es01:9200, 注意域名使用container_name
  • kibana 设置网络方式:``ELASTICSEARCH_HOSTS=http://es01:9200`,注意域名使用container_name
  • 最重要的来了,这里有3个es节点,要保证docker服务可以内存分配4G以上

推荐阅读

安全性 x-pack

相关推荐

  • es使用template自动初始化mapping
  • es集群,证书命令
  • 认识logstash