Elasticsearch 簡稱es.是一個開源的分佈式 RESTful 搜索和分析引擎
實際應用場景:存儲日誌
官網地址:https://www.elastic.co/cn/
注:Elasticsearch啓動不能通過root用戶,只能通過普通用戶。默認端口:9200
es安裝步驟:
1.下載並解壓
wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-6.3.2.tar.gz
tar -xzvf elasticsearch-6.3.2.tar.gz
cd 到./elasticsearch-6.3.2/config/ 目錄下
2.編輯配置文件,將network.host: 0.0.0.0改爲任意訪問ip並保存
vi config/elasticsearch.yml
3.執行./bin/elasticsearch
4.執行常見錯誤解決方案:
問題一 .can not run elasticsearch as root:
解決方案: 不能用root用戶登錄來執行,切換爲普通用戶
問題二.max virtual memory areas vm.max_count [65530] likely too low,increase to at least [262144]
解決方案:虛擬內存小,加大虛擬內存 。
在root用戶下,
修改配置 /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
執行命令:sysctl -p
問題三:max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
解決方案:
vi /etc/security/limits.conf
添加如下內容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
問題四:報錯elastic: Error 403 (Forbidden): blocked by: [FORBIDDEN/12/index read-only / allow delete (api)]; [type=cluster_block_exception]
解決方案:
curl -XPUT -H "Content-Type: application/json" http://127.0.0.1:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
返回結果如下即可
{"acknowledged":true}
5.沒有錯誤的話切換到普通用戶重新執行啓動命令:./bin/elasticsearch
後臺啓動命令:./bin/elasticsearch & [推薦 ] bin/elasticsearch -d
驗證是否啓動成功:curl http://本機IP:9200 ,返回json就表示成功
es安裝可視化頁面kibana
圖形化界面使用教程:https://yq.aliyun.com/articles/205028
kibana API : https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html
1.下載並解壓
wget https://www.elastic.co/cn/downloads/kibana
https://artifacts.elastic.co/downloads/kibana/kibana-6.3.2-linux-x86_64.tar.gz
tar -xzf kibana-6.2.2-linux-x86_64.tar.gz
cd ./kibana/config/ 目錄下
2. 編輯 vi config/kibana.yml
server.port: 5601 //默認端口
server.host: "0.0.0.0" // 任意端口可以訪問
elasticsearch.url: "http://localhost:9200" // 已安裝好的es的ip地址
3. 進入目錄執行命令:./bin/kibana 後臺啓動命令./bin/kibana &
4. 獲取所有ype
curl -XGET 'http://localhost:9200/_mapping?pretty=true'
5. 刪除指定index
curl -XDELETE http://localhost:9200/xxx
6. 刪除指定條件數據 https://blog.csdn.net/QYHuiiQ/article/details/90812570
新建腳本es-index-delete-by-query-30d.sh 。加入
LAST_DATA=`date -d "-30 days" "+%Y-%m-%dT00:00:00"`
echo ${LAST_DATA}
curl -XPOST 'http://127.0.0.1:9200/這裏寫要刪除的index/_delete_by_query' -H 'Content-Type: application/json' -d '
{
"query": {
"bool": {
"must": [
{
"range": {
"value.timestamp": {
"lte":"'${LAST_DATA}'"
}
}
}
]
}
}
}
'
正在上傳…重新上傳取消正在上傳…重新上傳取消正在上傳…重新上傳取消正在上傳…重新上傳取消正在上傳…重新上傳取消轉存失敗重新上傳取消正在上傳…重新上傳取消正在上傳…重新上傳取消正在上傳…重新上傳取消