ELK5.4.1搭建部署
大纲:
一、简介
二、Elasticsearch
三、Logstash
四、Kinaba
一、简介
1、核心组成
ELK由Elasticsearch、Logstash和Kibana三部分组件组成;
Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。
Logstash是一个完全开源的工具,它可以对你的日志进行收集、分析,并将其存储供以后使用
kibana 是一个开源和免费的工具,它可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。
2、四大组件
Logstash: logstash server端用来搜集日志;
Elasticsearch: 存储各类日志;
Kibana: web化接口用作查寻和可视化日志;
Logstash Forwarder: logstash client端用来通过lumberjack 网络协议发送日志到logstash server;
3、ELK工作流程
在需要收集日志的所有服务上部署logstash,作为logstash agent(logstash shipper)用于监控并过滤收集日志,将过滤后的内容发送到Redis,然后logstash indexer将日志收集在一起交给全文搜索服务ElasticSearch,可以用ElasticSearch进行自定义搜索通过Kibana 来结合自定义搜索进行页面展示。
4的帮助手册
ELK官网下载:https://www.elastic.co/downloads/
ELK官网文档:https://www.elastic.co/guide/index.html
ELK中文手册:http://kibana.logstash.es/content/elasticsearch/monitor/logging.html
注释
ELK有两种安装方式
(1)集成环境:Logstash有一个集成包,里面包括了其全套的三个组件;也就是安装一个集成包。
(2)独立环境:三个组件分别单独安装、运行、各司其职。(比较常用)
本实验也以第二种方式独立环境来进行演示;单机版主机地址为:10.254.21.18
二、Elasticsearch
1.安装java运行环境
ELK 5.4.1版本对JDK的最低要求是1.8,安装java_1.8版本
解压jdk-8u131-linux-x64.tar.gz
- tarzxvfjdk-8u131-linux-x64.tar.gz
- exportJAVA_HOME="/usr/local/jdk1.8.0_131"
- exportCLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
- exportPATH=$JAVA_HOME/bin:$JRE_HOME/bin:$HADOOP_HOME/bin:$PATH
保存退出,在命令行输入./etc/profile并回车使其生效。
2.关闭防火墙
- serviceiptablesstop
- chkconfigiptablesoff
4.新建用户
默认情况elasticsearch是不允许root用户直接启动的
- groupaddelk
- useraddelk-gelk
至此,前期准备工作结束。
5.安装elasticsearch
从官网下载的elasticsearch-5.4.1.tar.gz
新建/usr/local/elk/目录,在该路目下解压:
- tarzxvfelasticsearch-5.4.1.tar.gz
- mvelasticsearch-5.4.1elasticsearch
配置
- cdelasticsearch
- vimconfig/elasticsearch.yml
- network.host:192.168.1.104#主机IP
- http.port:9200#api接口url
- #以下两个为允许跨域,主要是5.1版本的head插件和以往安装的不一样
- http.cors.enabled:true
- http.cors.allow-origin:"*"
启动(elasticsearch目录下)
- suelk
- ./bin/elasticsearch
若是没有启动成功,可以到/var/log/elasticsearch/elasticsearch.log里看到这两条错误日志
- maxfiledescriptors[4096]forelasticsearchprocesslikelytoolow,increasetoatleast[65536]
- maxnumberofthreads[1024]foruser[lishang]likelytoolow,increasetoatleast[2048]
解决第一个,编辑limits.conf
- vi/etc/security/limits.conf
- *softnofile65536
- *hardnofile131072
- *softnproc2048
- *hardnproc4096
如果虚拟机内存小,也是启动不起来的,需加大内存。
elasticsearch安装使用常见问题及解决:http://www.jb51.cc/article/p-absgvwel-zw.html
6.安装elasticsearch-head插件
5.4版本的elasticsearch没有提供直接插件安装方法,但在该github上该插件作者给出了方法。
- gitclonegit://github.com/mobz/elasticsearch-head.git
如果虚拟机上没有安装node,则要安装node、npm、grunt。
- wgethttps://nodejs.org/dist/v6.11.0/node-v6.11.0-linux-x64.tar.xz
解压node-v6.11.0-linux-x64.tar.xz
tar.xz文件分两步解压
- xz-dnode-v6.10.3-linux-x64.tar.xz
- tarxvfnode-v6.10.3-linux-x64.tar
#设置软连接
- ln-s/usr/local/elk/node-v6.10.3-linux-x64/bin/node/usr/sbin/
- ln-s/usr/local/elk/node-v6.10.3-linux-x64/lib/node_modules/grunt/bin/grunt/usr/sbin/
# 设置npm代理镜像
- npmconfigsetregistryhttps://registry.npm.taobao.org
# 安装、配置grunt
- npminstall-ggrunt
- ln-s/usr/local/elk/node-v6.10.3-linux-x64/lib/node_modules/grunt/bin/grunt/usr/sbin/grunt
安装head
- npminstall
修改_site/app.js
- //把localhost改为ip
- this.base_uri=this.config.base_uri||this.prefs.get("app-base_uri")||"http://localhost:9200";
- this.base_uri=this.config.base_uri||this.prefs.get("app-base_uri")||"http://10.254.21.18:9200";
修改Gruntfile.js
- connect:{
- server:{
- options:{
- hostname:"0.0.0.0",#这里
- port:9100,base:'.',keepalive:true
- }
- }
- }
启动(后台运行)
- nohupgruntserver&
三、Logstash
1.安装logstash-5.4.1.tar.gz
在/usr/local/elk/目录下:
- tarzxvflogstash-5.4.1.tar.gz
- mvlogstash-5.4.1logstash
2.写入elasticsearch
3.文件方式启动
- /usr/local/elk/logstash/bin/logstash-f/usr/local/elk/logstash/config/elastic.conf
4.在elasticsearch中查看
四、Kinaba
1.解压kibana-5.4.1-linux-x86_64.tar.gz
在/usr/local/elk/目录下,
- tarzxvfkibana-5.4.1-linux-x86_64.tar.gz
- mvkibana-5.4.1-linux-x86_64kibana
2.配置
- cd/usr/local/elk/kibana/config
- vimkibana.yml
- server.port:5601
- server.host:"0.0.0.0"
- elasticsearch.url:"http://10.254.21.18:9200"
3.启动(后台运行)
- cd/usr/local/elk/kibana/bin/
- nohup./kibana&
4.kibana索引模式配置
图1
图2
上面两图中红框中index索引必须一致,图一中的create按钮才会出现。然后点击create后大功告成。
如有不明白之处,参见:kibana创建新的index patterns
5.效果图
至此ELK搭建已大功告成。