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

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

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

3、配置:
一、系統配置優化:
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在系統上的用戶
二、jvm.options:
1️⃣配置堆大小爲物理內存一半(最大不超過32G),另一半留給文件緩存;
2️⃣建議使用jdk1.8,堆超過4G時,使用G1進行GC;
三、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: 200mbgit

action.auto_create_index: true #經過logstash自動建立索引,此配置必定要打開github

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

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

5、索引設計/優化:
一、根據數據(日誌)量規劃索引分片:
官方建議每一個ES實例不超過3個分片;每一個分片不超過15G
不過咱們資源有限,每一個分片遠遠超過15G
二、索引mapping,上篇文章已經作過介紹;
三、分析日誌的特色,天天建立一個新索引,便於刪除過時日誌;
四、若是日誌須要長期保存,能夠把超過必定時間的日誌shrink,減小資源佔用
五、不一樣類型的日誌,如:nginx日誌和業務系統日誌,分紅不過的索引分開保存
六、刷新時間:Elasticsearch的默認刷新時間是1秒,爲了提升索引速度,在日誌的使用上能夠適當延遲刷新,如30秒緩存

相關文章
相關標籤/搜索