Docker容器搭建Elasticsearch(7.6.2)集群

这篇文章主要介绍了如何在Docker容器搭建Elasticsearch(7.6.2)集群,亲测有效,需要的朋友可以参考一下。

1、基础配置

  • es需要修改linux的一些参数:
sudo vi /etc/sysctl.conf
vm.max_map_count=262144
  • 不重启, 直接生效当前的命令
sysctl -w vm.max_map_count=262144
  • es三个实例的数据和日志目录创建:
    本文采用是在/es目录下新增三个es实例目录,分别是es01,es02,es03.
mkdir -p es01/data
mkdir -p es01/logs
mkdir -p es02/data
mkdir -p es02/logs
mkdir -p es03/data
mkdir -p es03/logs
## 授权
sudo chmod 777 es* -R

2、elasticsearch镜像

  • elasticsearch镜像获取命令:
docker pull elasticsearch:7.6.2
  • elasticsearch镜像查看命令
docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
elasticsearch            7.6.2               f29a1ee41030        6 weeks ago         791MB

3、docker-compose的安装

  • 通过命令查看是否安装docker-compose
docker-compose --version
  • 若没有出现以下信息
docker-compose version 1.25.1, build a82fef07
  • 需要安装docker-compose的命令:
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  • 添加可执行权限
sudo chmod +x /usr/local/bin/docker-compose

4、docker-compose.yml

docker-compose.yml文件如下:

version: '3'
services:
  es01:
    image: elasticsearch:7.6.2
    container_name: es01
    environment:
      - node.name=es01
      - cluster.name=docker-my-cluster
      - 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:
      - ./es01/data:/usr/share/elasticsearch/data
      - ./es01/logs:/usr/share/elasticsearch/logs
      - ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
    ports:
      - 9200:9200
    networks:
      - elastic

  es02:
    image: elasticsearch:7.6.2
    container_name: es02
    environment:
      - node.name=es02
      - cluster.name=docker-my-cluster
      - 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:
      - ./es02/data:/usr/share/elasticsearch/data
      - ./es02/logs:/usr/share/elasticsearch/logs
      - ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
    ports:
      - 9201:9200
    networks:
      - elastic

  es03:
    image: elasticsearch:7.6.2
    container_name: es03
    environment:
      - node.name=es03
      - cluster.name=docker-my-cluster
      - 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:
      - ./es03/data:/usr/share/elasticsearch/data
      - ./es03/logs:/usr/share/elasticsearch/logs
      - ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
    ports:
      - 9202:9200
    networks:
      - elastic

networks:
  elastic:
    driver: bridge

5、elasticsearch.yml

elasticsearch.yml配置文件如下:

network.host: 0.0.0.0

6、启动elasticsearch集群

  • 启动elasticsearch集群命令
cd /es
docker-compose  up -d 

7、浏览器验证elasticsearch集群

  • es01实例访问9200端口
{
  "name" : "es01",
  "cluster_name" : "docker-my-cluster",
  "cluster_uuid" : "_z4zo0YSRP61sKtcsmhGbA",
  "version" : {
    "number" : "7.6.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
    "build_date" : "2020-03-26T06:34:37.794943Z",
    "build_snapshot" : false,
    "lucene_version" : "8.4.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
  • es02实例访问9201端口
{
  "name" : "es02",
  "cluster_name" : "docker-my-cluster",
  "cluster_uuid" : "_z4zo0YSRP61sKtcsmhGbA",
  "version" : {
    "number" : "7.6.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
    "build_date" : "2020-03-26T06:34:37.794943Z",
    "build_snapshot" : false,
    "lucene_version" : "8.4.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
  • es03实例访问9202端口
{
  "name" : "es03",
  "cluster_name" : "docker-my-cluster",
  "cluster_uuid" : "_z4zo0YSRP61sKtcsmhGbA",
  "version" : {
    "number" : "7.6.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
    "build_date" : "2020-03-26T06:34:37.794943Z",
    "build_snapshot" : false,
    "lucene_version" : "8.4.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

通过以上步骤,恭喜你完成了docker容器搭建Elasticsearch(7.6.2)集群,是不是很简单。

如果您觉得有帮助,欢迎收藏点赞哦 ~ ~ 多谢~

你可能感兴趣的:(ELK,docker)