Для телеком-оператора с терабайтами логов управление жизненным циклом индексов — критически важная задача. Без ILM диски заполнились бы за считанные дни.
# Создание ILM-политики для логов телеком-оператора
curl -k -u elastic:password -X PUT \
"https://localhost:9200/_ilm/policy/logs-lifecycle" \
-H 'Content-Type: application/json' -d '{
"policy": {
"phases": {
"hot": {
"min_age": "0ms",
"actions": {
"rollover": {
"max_primary_shard_size": "50gb",
"max_age": "1d"
},
"set_priority": { "priority": 100 }
}
},
"warm": {
"min_age": "7d",
"actions": {
"shrink": { "number_of_shards": 1 },
"forcemerge": { "max_num_segments": 1 },
"set_priority": { "priority": 50 },
"allocate": { "require": { "data": "warm" } }
}
},
"cold": {
"min_age": "30d",
"actions": {
"set_priority": { "priority": 0 },
"freeze": {},
"allocate": { "require": { "data": "cold" } }
}
},
"delete": {
"min_age": "90d",
"actions": { "delete": {} }
}
}
}
}'
Наша политика реализует типовой жизненный цикл:
- Hot (0-7 дней): активная запись и поиск на SSD. Rollover при 50 ГБ или через 1 день
- Warm (7-30 дней): только чтение. Индексы сжимаются, переносятся на HDD
- Cold (30-90 дней): редкий доступ. Замораживание для экономии памяти
- Delete (90+ дней): автоматическое удаление
Для высоконагруженной инсталляции телеком-оператора мы применили оптимизации:
# Шаблон индекса с оптимальными настройками
curl -k -u elastic:password -X PUT \
"https://localhost:9200/_index_template/logs-template" \
-H 'Content-Type: application/json' -d '{
"index_patterns": ["filebeat-*"],
"template": {
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1,
"index.refresh_interval": "30s",
"index.translog.durability": "async",
"index.translog.sync_interval": "30s",
"index.codec": "best_compression"
}
}
}'
Команды мониторинга, которые мы передали инженерам NOC:
# Здоровье кластера
curl -k -u elastic:password 'https://localhost:9200/_cluster/health?pretty'
# Статистика узлов
curl -k -u elastic:password 'https://localhost:9200/_nodes/stats?pretty&filter_path=nodes.*.os,nodes.*.jvm.mem,nodes.*.fs'
# Статистика индексов
curl -k -u elastic:password 'https://localhost:9200/_cat/indices?v&s=store.size:desc&h=index,docs.count,store.size,pri.store.size'
# Pending tasks
curl -k -u elastic:password 'https://localhost:9200/_cluster/pending_tasks?pretty'
# Thread pool queues
curl -k -u elastic:password 'https://localhost:9200/_cat/thread_pool?v&h=node_name,name,active,rejected,queue'