Alokacja shardów i równoważenie
Zrozumieją Państwo, jak Elasticsearch decyduje o rozmieszczeniu shardów, jak allocation awareness rozkłada repliki między zasobami sprzętowymi oraz jak kontrolować równoważenie podczas skalowania i konserwacji.
Alokacja shardów i równoważenie to bezpłatna lekcja Elasticsearch & Full Text Search Systems na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Elasticsearch & Full Text Search Systems, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Elasticsearch & Full Text Search Systems zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
Where Do Shards Go?
When you create an index or add a node, Elasticsearch must decide which node holds each shard. This process is shard allocation, and keeping it balanced is key to a healthy, performant cluster.
The Allocation Process
The master node runs allocation deciders for every unassigned shard. They check disk space, shard count, awareness rules, and filters before placing a shard. Failing any decider keeps the shard UNASSIGNED.
Primary vs Replica Placement
A replica is never allocated to the same node as its primary. This guarantees that losing one node cannot take out both copies of the same data. With one replica you survive any single-node failure.
Watching Allocation
Use the _cat/shards API to see where each shard sits and its state. STARTED means active; RELOCATING means it is moving.
GET _cat/shards?vExplaining a Stuck Shard
When a shard will not allocate, the _cluster/allocation/explain API tells you exactly which decider blocked it and why. This is the first stop for debugging a yellow or red cluster.
GET _cluster/allocation/explain
{
"index": "my_index",
"shard": 0,
"primary": false
}Allocation Awareness
Allocation awareness spreads copies across physical boundaries like racks or availability zones. You tag nodes with custom attributes and tell the cluster to be aware of them.
cluster.routing.allocation.awareness.attributes: zoneForced Awareness
Forced awareness goes further: it refuses to over-allocate replicas to surviving zones if a zone goes down, preventing one zone from holding all copies. This protects capacity planning during outages.
cluster.routing.allocation.awareness.force.zone.values: zone1,zone2Shard Filtering
You can pin or exclude an index from specific nodes using allocation filters. This is handy for hot/warm architectures where older indices migrate to cheaper hardware.
PUT my_index/_settings
{
"index.routing.allocation.require.box_type": "warm"
}Rebalancing
After nodes join or leave, the cluster rebalances to even out shard counts. This is automatic but generates network and disk I/O, so it should be controlled during sensitive operations.
Pausing Allocation
Before a rolling restart, disable allocation so the cluster does not waste effort relocating shards from a node you are about to bring back. Re-enable it afterward.
PUT _cluster/settings
{
"transient": {
"cluster.routing.allocation.enable": "primaries"
}
}Throttling
Limit concurrent recoveries with cluster.routing.allocation.node_concurrent_recoveries and bandwidth with indices.recovery.max_bytes_per_sec to keep rebalancing from starving live queries.
Quick Check
Test your understanding of shard allocation.
Recap
You learned how shards are placed and balanced:
- Allocation deciders choose shard locations; replicas avoid their primary's node.
- Debug stuck shards with
allocation/explain. - Allocation awareness and forced awareness spread copies across zones.
- Use allocation filters for hot/warm tiers and disable allocation during rolling restarts.
Często zadawane pytania
Czy lekcja „Alokacja shardów i równoważenie” jest bezpłatna?
Tak — pełny tekst „Alokacja shardów i równoważenie” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Elasticsearch & Full Text Search Systems, przejdź na CoddyKit PRO. Kurs Elasticsearch & Full Text Search Systems zawiera 4 lekcji w sumie.
Co nauczysz się w „Alokacja shardów i równoważenie”?
Zrozumieją Państwo, jak Elasticsearch decyduje o rozmieszczeniu shardów, jak allocation awareness rozkłada repliki między zasobami sprzętowymi oraz jak kontrolować równoważenie podczas skalowania i k… Ćwiczysz Elasticsearch & Full Text Search Systems z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Elasticsearch & Full Text Search Systems?
Nie wymagamy żadnego doświadczenia. Elasticsearch & Full Text Search Systems w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Alokacja shardów i równoważenie”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Elasticsearch & Full Text Search Systems?
Tak. Każda lekcja Elasticsearch & Full Text Search Systems zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Wyjaśnienie shardingu i replik
- Stan klastra i monitorowanie
- Role węzłów i architektura
- Alokacja shardów i równoważenie