統一日誌ELK部署配置(4)——elasticsearch

一、下載:
1、官網下載Elasticsearch:
https://www.elastic.co/downloads/elasticsearch
我使用的版本是5.6.4,原來使用5.5.3發現此版本shrink時有bug,在5.6.4中解決
2、下載IK分詞插件:
https://github.com/medcl/elasticsearch-analysis-ik/releases

二、安裝:
1、解壓Elasticsearch包到安裝目錄;
2、解壓ik分詞包,複製到Elasticsearch的plugins目錄下,把文件夾名改爲ik

三、配置:
1、系統配置優化:
1️⃣關閉系統swapping;
2️⃣最好使用SSD作爲本地存儲,避免使用NFS;
3️⃣系統其他配置:
修改/etc/security/limits.conf
es - nofile 65536#open files
es soft nproc 65536#max user processes
es hard nproc 65536#max user processes
es soft memlock unlimited#virtual memory
es hard memlock unlimited#virtual memory
/etc/sysctl.conf添加配置信息
vm.max_map_count=262144
/sbin/sysctl-p#生效配置
注:es爲Elasticsearch在系統上的用戶
2、jvm.options:
1️⃣配置堆大小爲物理內存一半(最大不超過32G),另外一半留給文件緩存;
2️⃣建議使用jdk1.8,堆超過4G時,使用G1進行GC;
3、elasticsearch.yml
#================ Elasticsearch Configuration ====================
#-------------------------------- Cluster -----------------------------------
cluster.name: iss-elk-log
#--------------------------------- Node ------------------------------------
node.name: node-1
node.master: true
node.data: true
#-------------------------------- Paths ------------------------------------
path.data: "/mnt/elasticsearch-5.6.4/data,/mnt/esdata/data1"
path.logs: "/mnt/elasticsearch-5.6.4/logs"
#-------------------------------- Memory -----------------------------------
bootstrap.memory_lock: true
bootstrap.system_call_filter: false
#------------------------------ Network -----------------------------------
network.host: 0.0.0.0
http.port: 8200
transport.tcp.port: 8300
http.type: netty3 #5.x版本的一個問題,處於netty版本兼容期間的bug,需要配置
transport.type: netty3
#------------------------------ Discovery ----------------------------------
#------我使用的阿里雲,網絡不是很穩定,防止網絡抖動時shards來回切換,存活檢查適當放寬
discovery.zen.ping.unicast.hosts: ["節點1IP", "節點2IP", "節點3IP"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.fd.ping_interval: 10s
discovery.zen.fd.ping_timeout: 120s
discovery.zen.fd.ping_retries: 6
#------------------------------- Gateway -----------------------------------
gateway.recover_after_nodes: 3 #參考總節點數
#------------------------------ Various -----------------------------------
#---集羣重啓時的恢復,默認配置太小,適量改大
action.destructive_requires_name: true
cluster.routing.allocation.node_initial_primaries_recoveries: 6
cluster.routing.allocation.disk.threshold_enabled: true
cluster.routing.allocation.node_concurrent_recoveries: 6
indices.recovery.max_bytes_per_sec: 200mb

action.auto_create_index: true #通過logstash自動創建索引,此配置一定要打開

http.cors.enabled: true
http.cors.allow-origin: "*" #允許http訪問

四、啓動
在bin目錄下執行./elasticsearch -d啓動,不過有shell能力的建議通過shell來做好管理

五、索引設計/優化:
1、根據數據(日誌)量規劃索引分片:
官方建議每個ES實例不超過3個分片;每個分片不超過15G
不過我們資源有限,每個分片遠遠超過15G
2、索引mapping,上篇文章已經做過介紹;
3、分析日誌的特點,每天創建一個新索引,便於刪除過期日誌;
4、如果日誌需要長期保存,可以把超過一定時間的日誌shrink,減少資源佔用
5、不同類型的日誌,如:nginx日誌和業務系統日誌,分成不過的索引分開保存
6、刷新時間:Elasticsearch的默認刷新時間是1秒,爲了提高索引速度,在日誌的使用上可以適當延遲刷新,如30秒

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章