目錄
1.修改某個索引的分片數(shù)
2.es 寫入超時
3.重索引
4.es常用命令
5.華為云es開啟安全模式,客戶端使用方法
6.運維的一些命令
7.新加Es節(jié)點操作
8.由tranlog引起的文件句柄過多問題解決
1.修改某個索引的分片數(shù)
#其中, index_patterns 表示要匹配的索引名
#"order": 1 ,這個值,在的會overwite小的值,eg: 默認(rèn)的es_tempate一般我們都配置為0,這個什為1,那個這值里面的所以參數(shù)都會overwirte 值為0的參數(shù)
#number_of_shards 表示分片數(shù)
#number_of_routing_shards 可擴(kuò)展的最大分片數(shù),要number_of_shards 倍數(shù),8倍比較合適
PUT _template/gakx_vehicle1_new
{
??"index_patterns": [
????"gakx.vehicle1_*"
??],
??"order": 1,
??"settings": {
????"index": {
??????"number_of_shards": 15,
??????"number_of_routing_shards": 120
????}
??}
}
2.es 寫入超時
es 寫入超時,多方面原因
#先查詢集群狀態(tài)
get _cluster/health
#再看五上bulk 或者 wirte 隊列情況
# es 6.1 6.3
GET _cat/thread_pool/bulk?v&h=ip,port,name,type,active,size,queue,queue_size,rejected,largest,completed
# es 6.7
GET _cat/thread_pool/write?v&h=ip,port,name,type,active,size,queue,queue_size,rejected,largest,completed
3.重索引
#_reindex 重索引
POST _reindex
{
??"source": {
????"index":?"fjst_gakx.bill1_20190808",
????"size": 5000
??},
??"dest": {
????"index":?"fjst_gakx.bill1_20190808new"
??}
}
#索引與別名是多對多的關(guān)系
#一個索引可以有多個別名,一個別名也可以對應(yīng)多個索引,
#設(shè)置別名
PUT /my_index_v1/_alias/my_index
#查看 別名為my_index所有 索引
GET /*/_alias/my_index
#查看這個索引有幾個別名
GET /my_index_v1/_alias/*
#設(shè)置副本數(shù)
PUT 4gyd.post_20191029/_settings
{
????"index": {
??????"number_of_replicas": 0
????}
}
4.es常用命令
#查看分詞情況
post idx_z06crjzjcs_j_qz_wg_my_1205/_analyze
{
"analyzer":"ik_max_word",
"text":"黃小明在臺灣abcdedf"
}
post _analyze
{
"analyzer":"ik_max_word",
"text":"黃小明在臺灣abcdedf"
}
#查看段的情況
get idx_z22czrk_gab_czrk_jbxx_new_zl_my_1218/_segments
#進(jìn)行段的合并
post idx_z22czrk_gab_czrk_jbxx_new_zl_my_1218/_forcemerge?only_expunge_deletes=false&max_num_segments=1&flush=true&pretty
5.華為云es開啟安全模式,客戶端使用方法
1.kibana使用方法.
kibana需要使用oss的版本,如: kibana-oss-xxx-linux-x86_64.tar.gz
#配置里面需要修改
elasticsearch.ssl.verificationMode: none
#bWVpeWE6QWRtaW5AMTIzNDU= 為? base64(用戶:密碼)
elasticsearch.customHeaders: {"custom-proxy-username":"bWVpeWE6QWRtaW5AMTIzNDU="}
2.程序直接訪問(有些功能沒有配置資源目錄,如姓名分析,可以使用這個方式).
1)把原來的http修改為https
2) request head 增加參數(shù)
#bWVpeWE6QWRtaW5AMTIzNDU= 為? base64(用戶:密碼)
"custom-proxy-username":"bWVpeWE6QWRtaW5AMTIzNDU="
6.運維的一些命令
#查看 硬盤分布情況
get _cat/allocation?v
#查看集群狀態(tài)
#curl -Xget "http://192.168.1.1:9200/_cluster/health?pretty"
get _cluster/health
{
??"cluster_name": "elasticsearch_cluster",
??"status": "yellow",
??"timed_out": false,
??"number_of_nodes": 311,
??"number_of_data_nodes": 231,
??"active_primary_shards": 20161,
??"active_shards": 38804,
??"relocating_shards": 0,
??"initializing_shards": 60,
??"unassigned_shards": 13,
??"delayed_unassigned_shards": 0,
??"number_of_pending_tasks": 6,
??"number_of_in_flight_fetch": 0,
??"task_max_waiting_in_queue_millis": 53955,
??"active_shards_percent_as_number": 99.81222830979758
}
#如果有沒分配的,要查看分配的分片
#查看分配情況 ,INITIALIZING 代表是在init初始化中,UNASSIGNED 代表還沒分配的
get _cat/shards?v
4gdx.post_20191126 0 ????r ?????UNASSIGNED ????
#如果還有沒有分配的,查看一下原因
#查看分配失敗的原因
get _cluster/allocation/explain
{
"index":"4gyd.post_20191126",
"shard":0,
"primary":false
}
#檢查是否gc達(dá)到100%
?/opt/shell/jstat.sh /usr/local/elk/es1
觀察O指標(biāo)
#查看原因,解決
#原因1. allocation_expalin temporarily thottled 超過最大限制
#解決方法:設(shè)置初始化參數(shù),加快初始化
put _cluster/settings
{
"transient":{
"cluster.routing.allocation.node_concurrent_recoveries":60
??}
}
#原因2.Too manny oppen file 文件句柄過多
#請查看 由tranlog引起的文件句柄過多問題解決
#原因3: ?"allocate_explanation": "cannot allocate because all found copies of the shard are either stale or corrupt",
#說明數(shù)據(jù)有問題,或者不同步,找到一下"in_sync": false,的節(jié)點.完成后再查看explain .如果還有問題把a(bǔ)llocate_stale_primary 設(shè)置成allocate_empty_primary .允許為空分片
POST _cluster/reroute
{
??"commands": [
????{"allocate_stale_primary": {
??????"index": "t_sys_log_sga_20200709",
??????"shard": 1,
??????"node": "LN82kzp",
??????"accept_data_loss":true
????}}
??]
}
#設(shè)置平衡參數(shù),加快平衡
put _cluster/settings
{
"transient":{
"cluster.routing.allocation.cluster_concurrent_rebalance":60,
"indices.recovery.max_bytes_per_sec":"1gb"
}
}
#查看集群的所有參數(shù)
GET _cluster/settings
{
??"persistent": {
????"indices": {
??????"breaker": {
????????"fielddata": {
??????????"limit": "20%"
????????},
????????"request": {
??????????"limit": "10%"
????????},
????????"total": {
??????????"limit": "70%"
????????}
??????}
????}
??},
??"transient": {
????"cluster": {
??????"routing": {
????????"rebalance": {
??????????"enable": "all"
????????},
????????"allocation": {
??????????"cluster_concurrent_rebalance": "2",
??????????"node_concurrent_recoveries": "60",
??????????"node_initial_primaries_recoveries": "4",
??????????"enable": "all"
????????}
??????}
????}
??}
}
#查看索引情況
get _cat/indices
#查看節(jié)點情況(掛了的就不在這里面)
GET _cat/nodes?v
#pending 任務(wù)
get _cat/pending_tasks?v
#重新分布分片?
post _cluster/reroute?retry_failed=true
#去掉只讀模型
put */_settings
{
"index.blocks.read_only_allow_delete":null
}
#減少不平衡現(xiàn)象,每個表分配的主分片個數(shù)
put */_settings
{
"index.routing.allocation.total_shards_per_node":2
}
#比較多臺,重啟一般要操作的步驟
#關(guān)閉自動分片
PUT _cluster/settings
{
??"persistent": {
????"cluster": {
??????"routing": {
????????"allocation.enable": "none"
??????}
????}
??}
}
#kill es 進(jìn)程
#啟動 es集群
#啟動自動分片
PUT _cluster/settings
{
??"persistent": {
????"cluster": {
??????"routing": {
????????"allocation.enable": "all"
??????}
????}
??}
}
7.新加Es節(jié)點操作
#分成兩種情況.
#一:新的節(jié)點上部署.
1.做互信,系統(tǒng)參數(shù)祝始化,建立es用戶,在/data盤,創(chuàng)建文件目錄,受權(quán)給es用戶.(可參考安裝文檔)
2.修改配置,增加新的ip地址,如:
vim /usr/local/elk/es1/config/elasticsearch.yml
discovery.zen.ping.unicast.hosts: ["xxxx","xxxx"]
3.分發(fā)軟件,scp 到新的機(jī)器上
4.ssh 新的節(jié)點,修改配置文件
vim /usr/local/elk/es1/config/elasticsearch.yml
network.host: xxx.xxx.xxx
5.重啟es集群
PUT _cluster/settings
{
??"persistent": {
????"cluster": {
??????"routing": {
????????"allocation.enable": "none"
??????}
????}
??}
}
#kill es 進(jìn)程
#啟動 es集群
#啟動自動分片
PUT _cluster/settings
{
??"persistent": {
????"cluster": {
??????"routing": {
????????"allocation.enable": "all"
??????}
????}
??}
}
#二:在老節(jié)點上,新增加實例.
1.copy 軟件,如
cp /usr/local/elk/es1 /usr/local/elk/es2
2.修改配置,增加新的ip地址,如:
#修改舊的地址配置,增加discovery.zen.ping.unicast.hosts 新的端口
vim /usr/local/elk/es1/config/elasticsearch.yml
??discovery.zen.ping.unicast.hosts:
["x.x.x.x:9300","x.x.x.x:9302",]
#修改新的地址配置,增加discovery.zen.ping.unicast.hosts 新的端口 和 http.port,transport.tcp.port 的端口
vim /usr/local/elk/es1/config/elasticsearch.yml
?http.port: 9202
?transport.tcp.port: 9302
?discovery.zen.ping.unicast.hosts:?
["x.x.x.x:9300","x.x.x.x:9302",]
3.分發(fā)軟件,scp 到新的機(jī)器上
4.重啟es集群
PUT _cluster/settings
{
??"persistent": {
????"cluster": {
??????"routing": {
????????"allocation.enable": "none"
??????}
????}
??}
}
#kill
es 進(jìn)程
#啟動 es集群
#啟動自動分片
PUT _cluster/settings
{
??"persistent": {
????"cluster": {
??????"routing": {
????????"allocation.enable": "all"
??????}
????}
??}
}
??????8.由tranlog引起的文件句柄過多問題解決
#查看機(jī)器文件占用的句柄
/opt/FusionInsight_SetupTool/preinstall/tools/cluster/clustercmd.sh "cat /proc/sys/fs/file-nr"
?"cat /proc/sys/fs/file-nr"
#如果有大于30W 應(yīng)該處理一下.
vi?/opt/check_fd.sh
ps -ef|grep java|grep org.elasticsearch.bootstrap.Elasticsearch|grep -v grep |awk '{print $2}'|while read line;do cd /proc/$line/fd;ls -l > /opt/fd_$line.txt;done;wc -l /opt/fd_*|grep -v 總用量|awk '{if($1>5000) print $2}'|while read line;do cat? $line|grep translog|awk -F'/' '{print $9}'|sort|uniq -c|awk '{if($1>1000)print $0}';done;
#分發(fā)到其它臺機(jī)器?
/opt/FusionInsight_SetupTool/preinstall/tools/cluster/clusterscp.sh put /opt/check_fd.sh /opt/check_fd.sh
#執(zhí)行檢查腳本 查看是哪個索引引起的
?/opt/FusionInsight_SetupTool/preinstall/tools/cluster/clustercmd.sh "sh? /opt/check_fd.sh"?
47845 d6AF_i8_SWa3cV5kBybpXg
87405 57icq0x4S7KFsxe4k7sWrg
#查看所有 index 和對于的id
#地址要修改成對應(yīng)的地址: eg:大集群:x.x.x.x:24148
curl -Xget "http://163.1.6.3:24148/_cat/indices?v" > /opt/all_index.txt
#這個ip就是對應(yīng)的kibanna.yml里面的elasticsearch.url,位置在總控/usr/local/elk/kibana-6.1.3-8601/config文章來源:http://www.zghlxwxcb.cn/news/detail-402492.html
[root@hosts01 ~]# cat /opt/all_index.txt |grep h-sdnAM5Q32AoD1fTLIq0Q
green open 4gyd.log_20211215 h-sdnAM5Q32AoD1fTLIq0Q 5 1 37255447
#設(shè)置有問題的index, 副本設(shè)置為0,文章來源地址http://www.zghlxwxcb.cn/news/detail-402492.html
PUT 4gdx.post_20211211/_settings
{
"number_of_replicas": 0
}
#副本設(shè)置為1
PUT 4gdx.post_20211211/_settings
{
"number_of_replicas": 1
}
到了這里,關(guān)于ES常見問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!