统一日志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;
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日志和业务系统日志,分成不过的索引分开保存

猜你喜欢

转载自blog.51cto.com/jfzhang/2129750