###### tags: `netology` `devops` # Домашнее задание к занятию "6.5. Elasticsearch" ## Задача 1 ### Dockerfile: ```dockerfile= FROM centos:7 RUN yum install wget perl-Digest-SHA -y RUN groupadd -r elasticsearch && \ useradd -r -g elasticsearch elasticsearch USER elasticsearch WORKDIR /home/elasticsearch RUN wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-linux-x86_64.tar.gz && \ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-linux-x86_64.tar.gz.sha512 && \ shasum -a 512 -c elasticsearch-7.11.1-linux-x86_64.tar.gz.sha512 && \ tar -xzf elasticsearch-7.11.1-linux-x86_64.tar.gz COPY ./elasticsearch.yml ./elasticsearch-7.11.1/config EXPOSE 9200 ENTRYPOINT ./elasticsearch-7.11.1/bin/elasticsearch ``` ### Link: https://hub.docker.com/repository/docker/frolmr/6_5_elastic ### Response: ```bash= ➜ curl -X GET "localhost:9200/?pretty" { "name" : "netology_test", "cluster_name" : "elasticsearch", "cluster_uuid" : "hddU2vG_Quy4fGrjqOpMPg", "version" : { "number" : "7.11.1", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "ff17057114c2199c9c1bbecc727003a907c0db7a", "build_date" : "2021-02-15T13:44:09.394032Z", "build_snapshot" : false, "lucene_version" : "8.7.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } ``` ## Задача 2 ### Добавьте в elasticsearch 3 индекса: ```bash= ➜ curl -X PUT "localhost:9200/ind-1?pretty" -H 'Content-Type: application/json' -d' { "settings": { "number_of_shards": 1, "number_of_replicas": 0 } } ' ``` ```bash= ➜ curl -X PUT "localhost:9200/ind-2?pretty" -H 'Content-Type: application/json' -d' { "settings": { "number_of_shards": 2, "number_of_replicas": 1 } } ' ``` ```bash= ➜ curl -X PUT "localhost:9200/ind-3?pretty" -H 'Content-Type: application/json' -d' { "settings": { "number_of_shards": 4, "number_of_replicas": 2 } } ' ``` ### Получите список индексов и их статусов: ```bash= ➜ curl -X GET -u undefined:$ESPASS "localhost:9200/_cat/indices/ind-*?v=true&s=index&pretty" health status index uuid pri rep docs.count docs.deleted store.size pri.store.size green open ind-1 esoOQBzkSB62VBrWXJvE9w 1 0 0 0 208b 208b yellow open ind-2 tdsm3LIKRo2BWfz11sYrLg 2 1 0 0 416b 416b yellow open ind-3 HcKdUeeNRo-1oRchrmebGA 4 2 0 0 832b 832b ``` ### Получите состояние кластера elasticsearch ```bash= ➜ curl -X GET -u undefined:$ESPASS "localhost:9200/_cluster/health?pretty" { "cluster_name" : "elasticsearch", "status" : "yellow", "timed_out" : false, "number_of_nodes" : 1, "number_of_data_nodes" : 1, "active_primary_shards" : 7, "active_shards" : 7, "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 10, "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" : 41.17647058823529 } ``` ## Задача 3 ### Используя API зарегистрируйте данную директорию как snapshot repository c именем netology_backup ```bash= ➜ curl -X PUT -u undefined:$ESPASS "localhost:9200/_snapshot/netology_backup?pretty" -H 'Content-Type: application/json' -d' { "type": "fs", "settings": { "location": "snapshots" } } ' { "acknowledged" : true } ``` ### Создайте индекс test с 0 реплик и 1 шардом ```bash= ➜ curl -X GET -u undefined:$ESPASS "localhost:9200/_cat/indices/*?v=true&s=index&pretty" health status index uuid pri rep docs.count docs.deleted store.size pri.store.size green open test wtfdytcJROyQPoiK1ir89w 1 0 0 0 208b 208b ``` ### Создайте snapshot состояния кластера elasticsearch ```bash= ls -l elasticsearch-7.11.1/snapshots/ total 48 -rw-r--r-- 1 elasticsearch elasticsearch 434 Feb 18 20:31 index-0 -rw-r--r-- 1 elasticsearch elasticsearch 8 Feb 18 20:31 index.latest drwxr-xr-x 3 elasticsearch elasticsearch 4096 Feb 18 20:31 indices -rw-r--r-- 1 elasticsearch elasticsearch 30964 Feb 18 20:31 meta-pPb7QEQtSCGhv9-FIKQfUw.dat -rw-r--r-- 1 elasticsearch elasticsearch 266 Feb 18 20:31 snap-pPb7QEQtSCGhv9-FIKQfUw.dat ``` ### Удалите индекс test и создайте индекс test-2 ```bash= ➜ curl -X GET -u undefined:$ESPASS "localhost:9200/_cat/indices/*?v=true&s=index&pretty" health status index uuid pri rep docs.count docs.deleted store.size pri.store.size green open test-2 8swc76KiSiCK_OfgOP0h1w 1 0 0 0 208b 208b ``` ### Восстановите состояние кластера elasticsearch из snapshot, созданного ранее ```bash= curl -X POST -u undefined:$ESPASS "localhost:9200/_snapshot/netology_backup/snapshot_1/_restore?pretty" ``` ```bash= ➜ curl -X GET -u undefined:$ESPASS "localhost:9200/_cat/indices/*?v=true&s=index&pretty" health status index uuid pri rep docs.count docs.deleted store.size pri.store.size green open test kY6Fs7hOSL2mKoKiqOR3WA 1 0 0 0 208b 208b green open test-2 8swc76KiSiCK_OfgOP0h1w 1 0 0 0 208b 208b ```