Cluster Elasticsearch v7

Правим vim /etc/elasticsearch/elasticsearch.yml

Node1

cluster.name: my-cluster
node.name: "es-node-1"
node.master: true
discovery.zen.ping.unicast.hosts: ["172.16.215.46", "172.16.215.14","172.16.215.57"]
network.host: 172.16.215.46

Node2

cluster.name: my-cluster
node.name: "es-node-2"
node.data: true
discovery.zen.ping.unicast.hosts: ["172.16.215.46", "172.16.215.14","172.16.215.57"]
network.host: 172.16.215.57

Node3

cluster.name: my-cluster
node.name: "es-node-3"
node.data: true
discovery.zen.ping.unicast.hosts: ["172.16.215.46", "172.16.215.14","172.16.215.57"]
network.host: 172.16.215.14

Проверяем

curl -X GET "http://172.16.215.46:9200/_cluster/health?pretty"
{
  "cluster_name" : "my-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 2,
  "number_of_data_nodes" : 2,
  "active_primary_shards" : 6,
  "active_shards" : 12,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}

Смотрим мастера

curl -X GET "http://172.16.215.46:9200/_cat/master?pretty"
H3-hM0EhQEaPy3FQRhtWgw 172.16.215.57 172.16.215.57 es-node-2

Список Нод

curl -X GET "http://172.16.215.46:9200/_cat/nodes"
172.16.215.57 28 65 2 0.25 0.21 0.11 dm * es-node-2
172.16.215.46 10 87 2 0.17 0.20 0.12 dm - es-node-1

А вообще там можно все ))

Попробуем погонять  elsticsearch c помощью python

write.py

from datetime import datetime
from elasticsearch import Elasticsearch
from os import urandom
from base64 import b64encode
es = Elasticsearch(‘http://172.16.215.14:9200’)

i = 0
while i < 10000000:
    result = urandom(1000000)
    token = b64encode(result).decode(‘utf-8’)
    doc = {
    ‘author’: ‘author_name’,
    ‘text’: token,
    ‘timestamp’: datetime.now(),
    ‘id’: i
    }
    resp = es.index(index=»test-index1″, id=i, document=doc)
    print(i)
    i = i+1

resp = es.get(index=»test-index», id=1)
print(resp[‘_source’])

[свернуть]
read.py

from datetime import datetime
from elasticsearch import Elasticsearch
from os import urandom
from base64 import b64encode
es = Elasticsearch(‘http://172.16.215.46:9200’)

i = 0
while i < 10000000:
    resp = es.get(index=»test-index1″, id=i)
    print(resp[‘_source’])
    i = i+1

[свернуть]

 


Добавить комментарий 0