Te rokiroki raraunga mo te wa roa i Elasticsearch

Te rokiroki raraunga mo te wa roa i Elasticsearch

Ko Igor Sidorenko toku ingoa, he kaiarahi hangarau ahau i roto i te roopu o nga kaiwhakahaere e pupuri ana i nga hanganga katoa o Domclick.

Kei te pirangi au ki te whakapuaki i aku wheako ki te whakarite i te rokiroki raraunga tohatoha ki Elasticsearch. Ka tirohia e tatou he aha nga tautuhinga kei runga i nga node te kawenga mo te tohatoha o nga kongakonga, me pehea te mahi me te mahi a ILM.

Ko te hunga e mahi ana me nga rakau, tetahi huarahi, tetahi atu ranei, ka pa ki te raru o te rokiroki mo te wa roa mo te tātaritanga a muri ake nei. I roto i te Elasticsearch, he tino pono tenei, na te mea he pouri nga mea katoa mo te mahi a te kaitiaki. Ko te Putanga 6.6 i whakaurua te mahi ILM. E 4 nga waahanga kei roto:

  • Wera - Kei te kaha te whakahou me te patai i te taurangi.
  • Mahana - Kare e whakahōuhia te taupū, engari kei te uiuia tonutia.
  • Matao - Kua kore e whakahōuhia te taupū, ā, he uaua te uiui. Me rapu tonu nga korero, engari he puhoi pea nga patai.
  • Mukua - Kare e hiahiatia ana te taurangi ka taea te whakakore haumaru.

Ka hoatu

  • Raraunga Elasticsearch Hot: 24 nga tukatuka, 128 GB te mahara, 1,8 TB SSD RAID 10 (8 nodes).
  • Mahana Raraunga Elasticsearch: 24 tukatuka, 64 GB mahara, 8 TB NetApp SSD Kaupapahere (4 nodes).
  • Elasticsearch Raraunga Matao: 8 tukatuka, 32 GB mahara, 128 TB HDD RAID 10 (4 nodes).

Whāinga

He takitahi enei tautuhinga, ka whakawhirinaki katoa ki te waahi kei runga i nga node, te maha o nga tohu, nga raarangi, me era atu. Kei a matou 2-3 TB o nga raraunga ia ra.

  • 5 ra - Wāhanga wera (8 matua / 1 tauira).
  • 20 ra - Wāhanga mahana (whakaheke-taupū 4 matua / 1 tauira).
  • 90 ra - Wāhanga makariri (whakatio-taupū 4 matua / 1 tauira).
  • 120 ra - Mukua te wahanga.

Te whakatu i te Elasticsearch

Hei tohatoha i te mahanga puta noa i nga kohanga, me kotahi noa te tawhā:

  • Hot-nodes:
    ~]# cat /etc/elasticsearch/elasticsearch.yml | grep attr
    # Add custom attributes to the node:
    node.attr.box_type: hot
  • Warm-nodes:
    ~]# cat /etc/elasticsearch/elasticsearch.yml | grep attr
    # Add custom attributes to the node:
    node.attr.box_type: warm
  • makariri-nodes:
    ~]# cat /etc/elasticsearch/elasticsearch.yml | grep attr
    # Add custom attributes to the node:
    node.attr.box_type: cold

Te whakatu Logstash

He pehea te mahi katoa me pehea te whakatinana i tenei waahanga? Me timata ma te whakauru i nga raarangi ki Elasticsearch. E rua nga huarahi:

  1. Ka tikina e Logstash nga rakau mai i Kafka. Ka taea te tiki ma, te huri ranei i to taha.
  2. Ka tuhi tetahi mea ki a Elasticsearch, hei tauira, he tūmau APM.

Whakaarohia he tauira mo te whakahaere taurangi ma te Logstash. Ka hangaia he taurangi ka pa ana ki a ia tauira taupū me te rite ILM.

k8s-ingress.conf

input {
    kafka {
        bootstrap_servers => "node01, node02, node03"
        topics => ["ingress-k8s"]
        decorate_events => false
        codec => "json"
    }
}

filter {
    ruby {
        path => "/etc/logstash/conf.d/k8s-normalize.rb"
    }
    if [log] =~ "[warn]" or [log] =~ "[error]" or [log] =~ "[notice]" or [log] =~ "[alert]" {
        grok {
            match => { "log" => "%{DATA:[nginx][error][time]} [%{DATA:[nginx][error][level]}] %{NUMBER:[nginx][error][pid]}#%{NUMBER:[nginx][error][tid]}: *%{NUMBER:[nginx][error][connection_id]} %{DATA:[nginx][error][message]}, client: %{IPORHOST:[nginx][error][remote_ip]}, server: %{DATA:[nginx][error][server]}, request: "%{WORD:[nginx][error][method]} %{DATA:[nginx][error][url]} HTTP/%{NUMBER:[nginx][error][http_version]}", (?:upstream: "%{DATA:[nginx][error][upstream][proto]}://%{DATA:[nginx][error][upstream][host]}:%{DATA:[nginx][error][upstream][port]}/%{DATA:[nginx][error][upstream][url]}", )?host: "%{DATA:[nginx][error][host]}"(?:, referrer: "%{DATA:[nginx][error][referrer]}")?" }
            remove_field => "log"
        }
    }
    else {
        grok {
            match => { "log" => "%{IPORHOST:[nginx][access][host]} - [%{IPORHOST:[nginx][access][remote_ip]}] - %{DATA:[nginx][access][remote_user]} [%{HTTPDATE:[nginx][access][time]}] "%{WORD:[nginx][access][method]} %{DATA:[nginx][access][url]} HTTP/%{NUMBER:[nginx][access][http_version]}" %{NUMBER:[nginx][access][response_code]} %{NUMBER:[nginx][access][bytes_sent]} "%{DATA:[nginx][access][referrer]}" "%{DATA:[nginx][access][agent]}" %{NUMBER:[nginx][access][request_lenght]} %{NUMBER:[nginx][access][request_time]} [%{DATA:[nginx][access][upstream][name]}] (?:-|%{IPORHOST:[nginx][access][upstream][addr]}:%{NUMBER:[nginx][access][upstream][port]}) (?:-|%{NUMBER:[nginx][access][upstream][response_lenght]}) %{DATA:[nginx][access][upstream][response_time]} %{DATA:[nginx][access][upstream][status]} %{DATA:[nginx][access][request_id]}" }
            remove_field => "log"
        }
    }
}
output {
    elasticsearch {
        id => "k8s-ingress"
        hosts => ["node01", "node02", "node03", "node04", "node05", "node06", "node07", "node08"]
        manage_template => true # включаем управление шаблонами
        template_name => "k8s-ingress" # имя применяемого шаблона
        ilm_enabled => true # включаем управление ILM
        ilm_rollover_alias => "k8s-ingress" # alias для записи в индексы, должен быть уникальным
        ilm_pattern => "{now/d}-000001" # шаблон для создания индексов, может быть как "{now/d}-000001" так и "000001"
        ilm_policy => "k8s-ingress" # политика прикрепляемая к индексу
        index => "k8s-ingress-%{+YYYY.MM.dd}" # название создаваемого индекса, может содержать %{+YYYY.MM.dd}, зависит от ilm_pattern
    }
}

Tatūnga Kibana

He tauira turanga e pa ana ki nga taurangi hou katoa. Ka whakatakotohia te tohatoha o nga tohu wera, te maha o nga kongakonga, nga tauira, me era atu. Ko te taumaha o te tauira ka whakatauhia e te whiringa order. Ko nga tauira he nui ake te taumaha ka whakakore i nga tawhā tauira o mua, ka taapirihia ranei nga mea hou.

Te rokiroki raraunga mo te wa roa i Elasticsearch
Te rokiroki raraunga mo te wa roa i Elasticsearch

TIKI _tauira/taunoa

{
  "default" : {
    "order" : -1, # вес шаблона
    "version" : 1,
    "index_patterns" : [
      "*" # применяем ко всем индексам
    ],
    "settings" : {
      "index" : {
        "codec" : "best_compression", # уровень сжатия
        "routing" : {
          "allocation" : {
            "require" : {
              "box_type" : "hot" # распределяем только по горячим нодам
            },
            "total_shards_per_node" : "8" # максимальное количество шардов на ноду от одного индекса
          }
        },
        "refresh_interval" : "5s", # интервал обновления индекса
        "number_of_shards" : "8", # количество шардов
        "auto_expand_replicas" : "0-1", # количество реплик на ноду от одного индекса
        "number_of_replicas" : "1" # количество реплик
      }
    },
    "mappings" : {
      "_meta" : { },
      "_source" : { },
      "properties" : { }
    },
    "aliases" : { }
  }
}

Na ka tono i te mapi ki nga tohu k8s-ingress-* te whakamahi i te tauira me te taumaha teitei ake.

Te rokiroki raraunga mo te wa roa i Elasticsearch
Te rokiroki raraunga mo te wa roa i Elasticsearch

TIKI _tauira/k8s-whakauru

{
  "k8s-ingress" : {
    "order" : 100,
    "index_patterns" : [
      "k8s-ingress-*"
    ],
    "settings" : {
      "index" : {
        "lifecycle" : {
          "name" : "k8s-ingress",
          "rollover_alias" : "k8s-ingress"
        },
        "codec" : "best_compression",
        "routing" : {
          "allocation" : {
            "require" : {
              "box_type" : "hot"
            }
          }
        },
        "number_of_shards" : "8",
        "number_of_replicas" : "1"
      }
    },
    "mappings" : {
      "numeric_detection" : false,
      "_meta" : { },
      "_source" : { },
      "dynamic_templates" : [
        {
          "all_fields" : {
            "mapping" : {
              "index" : false,
              "type" : "text"
            },
            "match" : "*"
          }
        }
      ],
      "date_detection" : false,
      "properties" : {
        "kubernetes" : {
          "type" : "object",
          "properties" : {
            "container_name" : {
              "type" : "keyword"
            },
            "container_hash" : {
              "index" : false,
              "type" : "keyword"
            },
            "host" : {
              "type" : "keyword"
            },
            "annotations" : {
              "type" : "object",
              "properties" : {
                "value" : {
                  "index" : false,
                  "type" : "text"
                },
                "key" : {
                  "index" : false,
                  "type" : "keyword"
                }
              }
            },
            "docker_id" : {
              "index" : false,
              "type" : "keyword"
            },
            "pod_id" : {
              "type" : "keyword"
            },
            "labels" : {
              "type" : "object",
              "properties" : {
                "value" : {
                  "type" : "keyword"
                },
                "key" : {
                  "type" : "keyword"
                }
              }
            },
            "namespace_name" : {
              "type" : "keyword"
            },
            "pod_name" : {
              "type" : "keyword"
            }
          }
        },
        "@timestamp" : {
          "type" : "date"
        },
        "nginx" : {
          "type" : "object",
          "properties" : {
            "access" : {
              "type" : "object",
              "properties" : {
                "agent" : {
                  "type" : "text"
                },
                "response_code" : {
                  "type" : "integer"
                },
                "upstream" : {
                  "type" : "object",
                  "properties" : {
                    "port" : {
                      "type" : "keyword"
                    },
                    "name" : {
                      "type" : "keyword"
                    },
                    "response_lenght" : {
                      "type" : "integer"
                    },
                    "response_time" : {
                      "index" : false,
                      "type" : "text"
                    },
                    "addr" : {
                      "type" : "keyword"
                    },
                    "status" : {
                      "index" : false,
                      "type" : "text"
                    }
                  }
                },
                "method" : {
                  "type" : "keyword"
                },
                "http_version" : {
                  "type" : "keyword"
                },
                "bytes_sent" : {
                  "type" : "integer"
                },
                "request_lenght" : {
                  "type" : "integer"
                },
                "url" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword"
                    }
                  }
                },
                "remote_user" : {
                  "type" : "text"
                },
                "referrer" : {
                  "type" : "text"
                },
                "remote_ip" : {
                  "type" : "ip"
                },
                "request_time" : {
                  "format" : "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis||dd/MMM/YYYY:H:m:s Z",
                  "type" : "date"
                },
                "host" : {
                  "type" : "keyword"
                },
                "time" : {
                  "format" : "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis||dd/MMM/YYYY:H:m:s Z",
                  "type" : "date"
                }
              }
            },
            "error" : {
              "type" : "object",
              "properties" : {
                "server" : {
                  "type" : "keyword"
                },
                "upstream" : {
                  "type" : "object",
                  "properties" : {
                    "port" : {
                      "type" : "keyword"
                    },
                    "proto" : {
                      "type" : "keyword"
                    },
                    "host" : {
                      "type" : "keyword"
                    },
                    "url" : {
                      "type" : "text",
                      "fields" : {
                        "keyword" : {
                          "type" : "keyword"
                        }
                      }
                    }
                  }
                },
                "method" : {
                  "type" : "keyword"
                },
                "level" : {
                  "type" : "keyword"
                },
                "http_version" : {
                  "type" : "keyword"
                },
                "pid" : {
                  "index" : false,
                  "type" : "integer"
                },
                "message" : {
                  "type" : "text"
                },
                "tid" : {
                  "index" : false,
                  "type" : "keyword"
                },
                "url" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword"
                    }
                  }
                },
                "referrer" : {
                  "type" : "text"
                },
                "remote_ip" : {
                  "type" : "ip"
                },
                "connection_id" : {
                  "index" : false,
                  "type" : "keyword"
                },
                "host" : {
                  "type" : "keyword"
                },
                "time" : {
                  "format" : "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis||dd/MMM/YYYY:H:m:s Z",
                  "type" : "date"
                }
              }
            }
          }
        },
        "log" : {
          "type" : "text"
        },
        "@version" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "ignore_above" : 256,
              "type" : "keyword"
            }
          }
        },
        "eventtime" : {
          "type" : "float"
        }
      }
    },
    "aliases" : { }
  }
}

Whai muri i te tono i nga tauira katoa, ka whakamahia e matou te kaupapa here ILM ka tiimata ki te aro turuki i te oranga o nga tohu.

Te rokiroki raraunga mo te wa roa i Elasticsearch

Te rokiroki raraunga mo te wa roa i Elasticsearch

Te rokiroki raraunga mo te wa roa i Elasticsearch

TIKI _ilm/policy/k8s-ingress

{
  "k8s-ingress" : {
    "version" : 14,
    "modified_date" : "2020-06-11T10:27:01.448Z",
    "policy" : {
      "phases" : {
        "warm" : { # теплая фаза
          "min_age" : "5d", # срок жизни индекса после ротации до наступления теплой фазы
          "actions" : {
            "allocate" : {
              "include" : { },
              "exclude" : { },
              "require" : {
                "box_type" : "warm" # куда перемещаем индекс
              }
            },
            "shrink" : {
              "number_of_shards" : 4 # обрезание индексов, т.к. у нас 4 ноды
            }
          }
        },
        "cold" : { # холодная фаза
          "min_age" : "25d", # срок жизни индекса после ротации до наступления холодной фазы
          "actions" : {
            "allocate" : {
              "include" : { },
              "exclude" : { },
              "require" : {
                "box_type" : "cold" # куда перемещаем индекс
              }
            },
            "freeze" : { } # замораживаем для оптимизации
          }
        },
        "hot" : { # горячая фаза
          "min_age" : "0ms",
          "actions" : {
            "rollover" : {
              "max_size" : "50gb", # максимальный размер индекса до ротации (будет х2, т.к. есть 1 реплика)
              "max_age" : "1d" # максимальный срок жизни индекса до ротации
            },
            "set_priority" : {
              "priority" : 100
            }
          }
        },
        "delete" : { # фаза удаления
          "min_age" : "120d", # максимальный срок жизни после ротации перед удалением
          "actions" : {
            "delete" : { }
          }
        }
      }
    }
  }
}

Nga raruraru

He raruraru i te tatūnga me te waahi patuiro.

Wāhanga wera

Mo te hurihanga tika o nga tohu, he mea nui te noho ki te mutunga index_name-date-000026 hōputu tau 000001. He rarangi kei roto i te waehere e tirotiro ana i nga taurangi ma te whakamahi i nga korero mo te noho o nga tau i te mutunga. Ki te kore, ka puta he hapa, kaore he kaupapa here e whakamahia ki te taurangi, ka noho tonu ki te waahi wera.

Wāhanga mahana

Huri (tapahi) — te whakaiti i te maha o nga maramara, na te mea e 4 nga pona kei roto i nga wahanga mahana me te makariri. Kei roto i nga tuhinga nga rarangi e whai ake nei:

  • Me panui-anake te taurangi.
  • Me noho he kape o ia kongakonga o te taupū ki runga i te node kotahi.
  • Me kakariki te mana hauora tautau.

Hei tapahi i te taupū, ka nekehia e Elasticsearch nga mahanga tuatahi katoa ki te kohanga kotahi, ka taraihia te tohu kua tapahia me nga tawhā e tika ana, katahi ka mukua te mea tawhito. Tawhā total_shards_per_node me rite, nui ake ranei i te maha o nga maru matua kia uru ki runga i te pona kotahi. Ki te kore, ka puta he whakamohiotanga, ka kore nga maramara e neke ki nga pona tika.

Te rokiroki raraunga mo te wa roa i Elasticsearch
Te rokiroki raraunga mo te wa roa i Elasticsearch

TIKI /tiki-k8s-ingress-2020.06.06-000025/_settings

{
  "shrink-k8s-ingress-2020.06.06-000025" : {
    "settings" : {
      "index" : {
        "refresh_interval" : "5s",
        "auto_expand_replicas" : "0-1",
        "blocks" : {
          "write" : "true"
        },
        "provided_name" : "shrink-k8s-ingress-2020.06.06-000025",
        "creation_date" : "1592225525569",
        "priority" : "100",
        "number_of_replicas" : "1",
        "uuid" : "psF4MiFGQRmi8EstYUQS4w",
        "version" : {
          "created" : "7060299",
          "upgraded" : "7060299"
        },
        "lifecycle" : {
          "name" : "k8s-ingress",
          "rollover_alias" : "k8s-ingress",
          "indexing_complete" : "true"
        },
        "codec" : "best_compression",
        "routing" : {
          "allocation" : {
            "initial_recovery" : {
              "_id" : "_Le0Ww96RZ-o76bEPAWWag"
            },
            "require" : {
              "_id" : null,
              "box_type" : "cold"
            },
            "total_shards_per_node" : "8"
          }
        },
        "number_of_shards" : "4",
        "routing_partition_size" : "1",
        "resize" : {
          "source" : {
            "name" : "k8s-ingress-2020.06.06-000025",
            "uuid" : "gNhYixO6Skqi54lBjg5bpQ"
          }
        }
      }
    }
  }
}

Wāhanga makariri

whakatio (whakatio) - Ka whakatio matou i te taurangi hei arotau i nga patai mo nga raraunga o mua.

Ko nga rapunga e mahia ana i runga i nga taurangi tio ka whakamahi i te miro iti, whakatapua, rapu_throttled hei whakahaere i te maha o nga rapunga katahi ka pa ki nga maramara tio ki ia pona. Ka whakawhāiti tēnei i te nui o te pūmahara anō e hiahiatia ana mō ngā hanganga raraunga rangitahi e hāngai ana ki ngā maru tio, e tiaki ana i ngā kōpuku mai i te nui o te kai mahara.
Ko nga tohu tio he panui-anake: kaore e taea e koe te tohu ki roto.
Ko nga rapunga i runga i nga tohu tio e tika ana kia tere te mahi. Ko nga tohu tio kaore i te whakaaro mo te kawenga rapu nui. Ka roa pea he hēkona, he meneti ranei te mutunga o te rapunga o te taupū tio, ahakoa he rite nga rapunga i roto i nga manomano hēkona i te mea kaore i whakatotoka nga tohu.

Ngā putanga

I ako matou me pehea te whakareri i nga pona mo te mahi me te ILM, te whakarite tauira mo te tohatoha maramara ki waenga i nga pona wera, me te whakarite ILM mo te taupū me nga wahanga katoa o te oranga.

hononga whaihua

Source: will.com