Развертывание кластера на одной ВМ

Предварительные действия перед развертыванием:

echo "vm.max_map_count=262144" >> /etc/sysctl.conf
sysctl -w vm.max_map_count=262144

Создание файла docker-compose.yaml:

version: '2.2'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.4.3
    container_name: elasticsearch
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - esnet
  elasticsearch2:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.4.3
    container_name: elasticsearch2
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "discovery.zen.ping.unicast.hosts=elasticsearch"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata2:/usr/share/elasticsearch/data
    networks:
      - esnet

volumes:
  esdata1:
    driver: local
  esdata2:
    driver: local

networks:
  esnet:

Запуск сервиса:

docker compose up -d

Развертывание кластера на разных ВМ

Действия на первой ноде

Предварительные действия перед развертыванием:

echo "vm.max_map_count=262144" >> /etc/sysctl.conf
sysctl -w vm.max_map_count=262144

Создание папки для данных:

mkdir esdata
touch elastic_config_01.yml
chown 1000:1000 esdata elastic_config_01.yml
chmod 0775 esdata elastic_config_01.yml

Создание конфигурационного файла для первой ноды elastic_config_01.yml:

cluster.name: elastic-cluster
node.name: node01
path.data: /usr/share/elasticsearch/data
network.host: 0.0.0.0
# This is the setting you need to be careful with, set it as the cname, a record or IP of the server which hosts docker.
network.publish_host: 192.168.10.10
transport.tcp.port: 9300
transport.publish_port: 9300
http.port: 9200
# This setting should include all ES nodes as the examples, you can use the same info as on the publish_host above. Put the current node, as first in the list.
discovery.zen.ping.unicast.hosts: ["192.168.10.10:9300", "192.168.10.11:9300"]
discovery.zen.minimum_master_nodes: 2
xpack.license.self_generated.type: basic
xpack.security.enabled: false
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers: X-Requested-With, X-Auth-Token, Content-Type, Content-Length

Создание файла docker-compose.yaml для первой ноды:

version: '2.2'
services:
  elasticsearch:
	image: docker.elastic.co/elasticsearch/elasticsearch:6.4.3
	container_name: elasticsearch
	environment:
	  - bootstrap.memory_lock=true
	  - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
	ulimits:
	  memlock:
	    soft: -1
		hard: -1
	volumes:
	  - /opt/data/esdata:/usr/share/elasticsearch/data
	  - /opt/data/elastic_config_01.yml:/usr/share/elasticsearch/config/elasticsearch.yml
	ports:
	  - 9200:9200
	  - 9300:9300

Запуск сервиса:

docker compose up -d

Действия на второй ноде

Предварительные действия перед развертыванием:

echo "vm.max_map_count=262144" >> /etc/sysctl.conf
sysctl -w vm.max_map_count=262144

Создание папки для данных:

mkdir esdata
chown 1000:1000 esdata
chmod 0775 esdata

Создание конфигурационного файла для второй ноды elastic_config_02.yml:

cluster.name: elastic-cluster
node.name: node02
path.data: /usr/share/elasticsearch/data
network.host: 0.0.0.0
# This is the setting you need to be careful with, set it as the cname, a record or IP of the server which hosts docker.
network.publish_host: 192.168.10.11
transport.tcp.port: 9300
transport.publish_port: 9300
http.port: 9200
# This setting should include all ES nodes as the examples, you can use the same info as on the publish_host above. Put the current node, as first in the list.
discovery.zen.ping.unicast.hosts: ["192.168.10.10:9300", "192.168.10.11:9300"]
discovery.zen.minimum_master_nodes: 2
xpack.license.self_generated.type: basic
xpack.security.enabled: false
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers: X-Requested-With, X-Auth-Token, Content-Type, Content-Length

Создание файла docker-compose.yaml для второй ноды:

version: '2.2'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.4.3
	container_name: elasticsearch
	environment:
		  - bootstrap.memory_lock=true
		  - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
	ulimits:
	  memlock:
		soft: -1
		hard: -1
	volumes:
	  - /opt/data/esdata:/usr/share/elasticsearch/data
	  - /opt/data/elastic_config_02.yml:/usr/share/elasticsearch/config/elasticsearch.yml
	ports:
	  - 9200:9200
	  - 9300:9300

Запуск сервиса:

docker compose up -d