zoukankan      html  css  js  c++  java
  • ES集群

    为什么是Docker?

    Docker是一个高速创新的企业级容器平台,优点很多,比如:

    • 可以在任何地方安全地构建、共享和运行任何应用程序
    • 节省资源、降低成本
    • 部署非常灵活方便

    让我们开始吧

    这个例子会使用Docker来搭建一个主节点两个数据节点的Elasticsearch集群,首先要已经安装好docker,可以使用docker --version命令来看确认一下。

    1、下面是目录结构,接下来会基于这个目录结构来操作

    .
    ├── docker-compose.yml
    ├── config
    │   ├── es01
    │   │   └── elasticsearch.yml
    │   ├── es02
    │   │   └── elasticsearch.yml
    │   └── es03
    │       └── elasticsearch.yml
    ├── data
    │   ├── es01
    │   ├── es02
    │   └── es03
    └── logs
        ├── es01
        ├── es02
        └── es03

    2、编写docker-compose.yml文件

    version: '2'
    services:
      es01:
        image: docker.elastic.co/elasticsearch/elasticsearch:6.2.0
        container_name: es01
        restart: always
        environment:
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - ./data/es01:/usr/share/elasticsearch/data
          - ./config/es01/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
          - ./logs/es01:/usr/share/elasticsearch/logs
        ports:
          - 9200:9200
          - 9300:9300
        networks:
          - esnet
      es02:
        image: docker.elastic.co/elasticsearch/elasticsearch:6.2.0
        container_name: es02
        restart: always
        environment:
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - ./data/es02:/usr/share/elasticsearch/data
          - ./config/es02/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
          - ./logs/es02:/usr/share/elasticsearch/logs
        depends_on:
          - es01
        networks:
          - esnet
      es03:
        image: docker.elastic.co/elasticsearch/elasticsearch:6.2.0
        container_name: es03
        restart: always
        environment:
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - ./data/es03:/usr/share/elasticsearch/data
          - ./config/es03/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
          - ./logs/es03:/usr/share/elasticsearch/logs
        depends_on:
          - es01
        networks:
          - esnet
    
    networks:
      esnet:

    Elasticsearch集群启动的时候,需要主节点启动成功后,其他节点才能启动并join到集群里,因此在配置文件里要保证这一点,官网Control startup and shutdown order in Compose这篇文章介绍了如何控制启动和关闭顺序的问题,我这里是通过配置restart: alwaysdepends_on来控制顺序的,这个办法比较简单。
    另外,我这里使用的是6.2.0版本的elasticsearch,官方目前只提供了6.8.1和7.2.0版本的docker镜像,所以需要先自己做个6.2.0的镜像,下面简单说下如何制作镜像。

    • 新建一个目录并进入这个目录
    • 新建Dockerfile文件,文件内容为FROM docker.elastic.co/elasticsearch/elasticsearch:6.2.0,保存
    • 打开终端进入当前目录执行docker build .

    3、分别编写每个节点的elasticsearch.yml配置

    cluster.name: es-cluster
    node.name: es01
    node.master: true
    node.data: false
    path.data: /usr/share/elasticsearch/data
    path.logs: /usr/share/elasticsearch/logs
    bootstrap.memory_lock: true
    network.host: 0.0.0.0
    http.port: 9200
    transport.tcp.port: 9300
    discovery.zen.ping.unicast.hosts: ["es01", "es02", "es03"]
    # discovery.seed_hosts: ["es02", "es03"]
    # cluster.initial_master_nodes: ["es01", "es02", "es03"]
    
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    
    xpack.security.enabled: false
    xpack.security.transport.ssl.enabled: false

    每个节点的配置基本一样,这里只写一个节点的配置,其他节点主要改下node.namenode.masternode.data配置即可。

    4、执行命令docker-compose up部署集群,可以在命令后面加上-d参数使后台执行。

    5、验证
    浏览器打开http://127.0.0.1:9200,输出如下则表示成功了。

    {
      "name" : "es01",
      "cluster_name" : "es-cluster",
      "cluster_uuid" : "-zUZlE_lTJ2LX7JMq4R40g",
      "version" : {
        "number" : "6.2.0",
        "build_hash" : "37cdac1",
        "build_date" : "2018-02-01T17:31:12.527918Z",
        "build_snapshot" : false,
        "lucene_version" : "7.2.1",
        "minimum_wire_compatibility_version" : "5.6.0",
        "minimum_index_compatibility_version" : "5.0.0"
      },
      "tagline" : "You Know, for Search"
    }

    接下来再使用Elasticsearch提供的API来检查一下集群和节点的健康状况。
    使用/_cluster/health/_cat/health?v查看集群健康状况,结果分别如下图:

    使用/_cat/nodes?v查看节点,结果如下图:

    至此,就已经完成了使用Docker搭建的Elasticsearch集群。

  • 相关阅读:
    Oracle常用命令大全(很有用,做笔记)
    表格驱动编程在代码中的应用
    mac 利用svn下载远程代码出现Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
    FAILURE: Build failed with an exception.
    There is an internal error in the React performance measurement code.Did not expect componentDidMount timer to start while render timer is still in progress for another instance
    react native TypeError network request failed
    Android向系统相册中插入图片,相册中会出现两张 一样的图片(只是图片大小不一致)
    react-native Unrecognized font family ‘Lonicons’;
    react-native SyntaxError xxxxx/xx.js:Unexpected token (23:24)
    Application MyTest has not been registered. This is either due to a require() error during initialization or failure to call AppRegistry.registerComponent.
  • 原文地址:https://www.cnblogs.com/1124li/p/11690636.html
Copyright © 2011-2022 走看看