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秒缓存