日志分析ELK平台,由ElasticSearch、Logstash和Kiabana三个开源工具组成。
官方网站:https://www.elastic.co/products
Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。
Logstash是一个完全开源的工具,他可以对你的日志进行收集、过滤,并将其存储供以后使用(如,搜索)。
Kibana 也是一个开源和免费的工具,它Kibana可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。
ELK原理图:
如图:Logstash收集AppServer产生的Log,并存放到ElasticSearch集群中,而Kibana则从ES集群中查询数据生成图表,再返回给Browser。
ELK平台搭建系统环境
System: Centos release 6.7(Final)
ElasticSearch: elasticsearch-5.3.1.tar.gz
Logstash: logstash-5.3.1.tar.gz
Kibana: kibana-5.3.1-linux-x86_64.tar.gz
Java: openjdk version ”1.8.0_131″
ELK官网下载:https://www.elastic.co/downloads/
JAVA环境配置
下载最新版本1.8.0_131
cd /tmp/
wgethttp://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
tar zxfjdk-8u131-linux-x64.tar.gz -C /usr/local/
vim /etc/profile
添加如下内容
JAVA_HOME=/usr/local/jdk1.8.0_131
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME PATH CLASSPATH
source /etc/profile
ElasticSearch配置
wgethttps://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.3.1.tar.gz
useradd elktest
tar-zxvfelasticsearch-5.3.1.tar.gzcdelasticsearch-5.3.1viconfig/elasticsearch.yml
修改以下配置项:
(路径需要先自行创建,并且elktest用户可读写)
cluster.name:elk_clusternode.name:node0path.data:/tmp/elasticsearch/datapath.logs:/tmp/elasticsearch/logsnetwork.host: 192.168.1.5http.port:9200
其他的选项保持默认,然后启动ES:
su elktest#ES不允许root启动服务 必须是普通用户
./bin/elasticsearch
配置Logstash
wgethttps://artifacts.elastic.co/downloads/logstash/logstash-5.3.1.tar.gz
tar-zxvflogstash-5.3.1.tar.gzcdlogstash-5.3.1
viconfig/test_es.conf
input { file { path = “/tmp/test.log” #测试文件 }}filter {}output { stdout { codec = rubydebug } elasticsearch { index = “test_%{+YYYY.MM.dd}”#索引信息 hosts = [ “192.168.1.5:9200” ] }}
./bin/logstash -f config/test_es.conf #启动服务
配置Kibana:
wgethttps://artifacts.elastic.co/downloads/kibana/kibana-5.3.1-linux-x86_64.tar.gz
tar-zxvfkibana-5.3.1-linux-x86.tar.gzcdkibana-5.3.1-linux-x86viconfig/kibana.ymlserver.port:5601server.host:”192.168.1.5″elasticsearch.url:http://192.168.1.5:9200kibana.index:”.kibana.yml”./bin/kibana
部署中的常见错误及解决方法
1、启动elasticsearch 如出现异常 can not run elasticsearch as root
解决方法:创建ES 账户,修改文件夹 文件 所属用户 组
2、启动异常:ERROR: bootstrap checks failedsystem call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
解决方法:在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory下面:bootstrap.memory_lock: falsebootstrap.system_call_filter: false
3、启动后,如果只有本地可以访问,尝试修改配置文件 elasticsearch.yml中network.host(注意配置文件格式不是以 # 开头的要空一格, : 后要空一格)为 network.host: 0.0.0.0默认端口是 9200注意:关闭防火墙 或者开放9200端口
4、ERROR: bootstrap checks failedmax file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]max number of threads [1024] for user [lishang] likely too low, increase to at least [2048]
解决方法:切换到root用户,编辑limits.conf 添加类似如下内容vi /etc/security/limits.conf添加如下内容:* soft nofile 65536* hard nofile 131072* soft nproc 2048* hard nproc 4096
5、max number of threads [1024] for user [lish] likely too low, increase to at least [2048]解决方法:切换到root用户,进入limits.d目录下修改配置文件。vi /etc/security/limits.d/90-nproc.conf修改如下内容:* soft nproc 1024#修改为* soft nproc 20486、max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]解决方法:切换到root用户修改配置sysctl.confvi /etc/sysctl.conf添加下面配置:vm.max_map_count=655360并执行命令:sysctl -p然后,重新启动elasticsearch,即可启动成功。
版权声明:原创作品,如需转载,请注明出处。否则将追究法律责任 单机 系统详解 ELK歌里唱的是“你离开我,就是旅行的意义”,