Nodes Stats
All Nodes
# Check All Nodes Info
# pretty 可以方便肉眼觀察 JSON 數據結構,當然也可以用 www.bejson.com 這個在線 JSON 格式轉換工具來看。
curl -XGET http://ES_URL:9200/_nodes?pretty
# Check mlockall Params
curl -XGET http://ES_URL:9200/_nodes?filter_path=**.mlockall\&pretty
上面那個是我在百度 mlockall 參數的時候,找到的一個帶過濾的 URL,於是在這個基礎上就可以衍生出很多檢索 node 信息的方式。
Single Node
# Check Specific Node Info
# vpYO4QSHRRWmFwleCalL3Q 是 ES Cluster 內部識別 Node 的標記
curl -XGET http://ES_URL:9200/_nodes?filter_path=**.vpYO4QSHRRWmFwleCalL3Q\&pretty
# 或者填入 node name 這樣查詢也可以
curl -XGET http://ES_URL:9200/_nodes/NODE_NAME/stats?pretty
Specific Info
# Check OS
curl -XGET http://ES_URL:9200/_nodes?filter_path=**.os\&pretty
# Check thread_pool
# 在實際運維中有指導價值,可以看 bulk/create/delete/... 操作時隊列中 reject 數量。長期將此作爲 ES 的性能指標,也可以進一步瞭解集羣是否需要擴容,查詢是否需要優化等。
curl -XGET http://ES_URL:9200/_nodes?filter_path=**.thread_pool\&pretty
Specific Info for Single Node
curl -XGET http://ES_URL:9200/_nodes/NODE_NAME/stats?filter_path=**.thread_pool\&pretty
Indices Settings
Create
# 第一種
curl -XPUT http://ES_URL:9200/ES_INDEX -d '{
"settings" : {
"number_of_shards" : 2
},
"mappings" : {
"ES_TYPE" : {
...
}
}
}'
# 第二種
curl -XPUT http://ES_URL:9200/ES_INDEX -d '{
"settings" : {
"number_of_shards" : 2
}
}'
curl -XPUT http://ES_URL:9200/ES_INDEX/_mapping/ES_TYPE -d '
{
"properties" : {
"param_a": {
"type": "long"
},
"param_b": {
"type": "float"
},
"param_c": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}'
Mappings
# Enlarge Index Field Limit
curl -XPUT http://ES_URL:9200/ES_INDEX/_settings -d '{"index": {"mapping": {"total_fields": {"limit": "20000"}}}}'
# Disable _all of fields
curl -XPUT http://ES_URL:9200/ES_INDEX/ -d '{
"mappings": {
"ES_TYPE": {
"_all": {
"enabled": false
}
}
}
}'
Shards
# Reallocate Shards by Node Attributes
curl -XPUT http://ES_URL:9200/ES_INDEX/_settings -d '{"index": {"routing": {"allocation": {"include": {"box_type": "warm"}}}}}'
# Set total_shards_per_node for Indices ES_INDEX
curl -XPUT http://ES_URL:9200/ES_INDEX/_settings -d '{"index.routing.allocation.total_shards_per_node": "20"}'
Cluster Settings
Routing
# Routing none
curl -XPUT http://ES_URL:9200/_cluster/settings -d '
{
"transient": {
"cluster.routing.allocation.enable": "none"
}
}'
# Routing all
curl -XPUT http://ES_URL:9200/_cluster/settings -d'
{
"transient" : {
"cluster.routing.allocation.enable" : "all"
}
}'
Thread Pool
# Index Queue Size
# 在 5.x 版本及以上這條命令已經不生效了,需要在每個節點的 elasticsearch.yml 中設置並 restart ES 節點才能修改 thread_pool 信息
curl -XPUT http://ES_URL:9200/_cluster/settings -d '{"thread_pool": {"index": {"queue_size": "20000"}}}'
Shard Allocation
# Shard Rellocation
ES_HOST=xxx;ES_PORT=9200;TO_NODE=xxx;curl http://$ES_HOST:$ES_PORT/_cat/shards | grep 'p UNAS' | awk '{print $1, $2}' | while read var_index var_shard; do
curl -XPOST http://$ES_HOST:$ES_PORT/_cluster/reroute -d "
{
\"commands\" : [
{
\"allocate_empty_primary\" :
{
\"index\": \"$var_index\",
\"shard\": $var_shard,
\"node\": \"$TO_NODE\",
\"accept_data_loss\": true
}
}
]
}" ;
sleep 5;
done
# Move Shard
curl -XPOST "http://ES_URL:9200/_cluster/reroute' -d '{
"commands" : [{
"move" : {
"index" : "ES_INDEX",
"shard" : 0,
"from_node" : "FROM_NODE",
"to_node" : "TO_NODE"
}
}]
}'
Others: _cat
# Health
curl -XGET http://ES_URL:9200/_cat/health?v
# Indices
curl -XGET http://ES_URL:9200/_cat/indices?v
# Nodes
curl -XGET http://ES_URL:9200/_cat/nodes?v
# Shards
curl -XGET http://ES_URL:9200/_cat/shards|grep monitor| grep 2018.04.02
curl -XGET 'http://ES_URL:9200/_cat/shards' | grep UNASSIGNED
Snapshot
# 創建倉庫
curl -XPUT http://ES_URL:9200/_snapshot/my_backup
{
"type": "fs",
"settings": {
"location": "/mnt/backup",
"compress": true
}
}
# 針對具體的index創建快照備份
curl -XPUT http://ES_URL:9200/_snapshot/my_backup/snapshot_test
{
"indices": "index_1, index_2"
}
# 查看備份狀態
curl -XGET http://ES_URL:9200/_snapshot/my_backup/snapshot_test/_status