安装ELK Stack海量日志分析系统

安装ELK Stack海量日志分析系统


较为常见的ELK stack架构

主机名主机地址角色
node1   192.168.31.201   Elasticsearch、jdk1.8、Kibana  
node2   192.168.31.202   Elasticsearch、jdk1.8  
node3   192.168.31.203   Elasticsearch、jdk1.8  
node4   192.168.31.204   logstash、jdk1.8  
node5   192.168.31.205   redis  
node6   192.168.31.206   logstash、nginx、jdk1.8  
一、安装Logstash #编辑repo文件,这里配置一个清华的yum源。 [root@bc ~]# vim /etc/yum.repos.d/logstash24.repo [logstash2.4-tsinghua] name=logstash24 baseurl=https://mirrors.tuna.tsinghua.edu.cn/ELK/yum/logstash-2.4/ enabled=1 gpgcheck=0 #安装logstash [root@bc ~]# yum install logstash-2.4.1 -y #输出执行路径 [root@bc ~]# export PATH=/opt/logstash/bin/:$PATH 测试能否正常运行: 1.编辑文件 [root@bc ~]# vim basic input{ stdin{} } output{ stdout { codec => rubydebug } }

从标准输入读取(键盘),输出到标准输出(屏幕)

2.使用指定文件运行logstash,测试是否正常运行 [root@bc ~]# logstash -f basic Settings: Default pipeline workers: 1 Pipeline main started hello world { "message" => "hello world", "@version" => "1", "@timestamp" => "2017-03-03T02:16:51.538Z", "host" => "bc.com" }

这里我们键盘输入的是hello world

二、Elasticsearch 1.配置yum源 #编辑repo文件,这里配置一个清华的yum源。 [root@bc ~]# vim /etc/yum.repos.d/elasticsearch24.repo [elasticsearch2.4-tsinghua] name=logstash24 baseurl=https://mirrors.tuna.tsinghua.edu.cn/ELK/yum/elasticsearch-2.x/ enabled=1 gpgcheck=0 #安装elasticsearch [root@bc ~]# yum install elasticsearch-2.4.4 -y #启动 [root@bc ~]# service elasticsearch start Starting elasticsearch (via systemctl): [ OK ] 2.测试elasticsearch是否正常运行 [root@bc ~]# curl -i -XGET 'localhost:9200/' HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8 Content-Length: 367 { "name" : "Jericho Drumm", "cluster_name" : "elasticsearch", "cluster_uuid" : "vLUapCyRRK6YH2ilwdPMkQ", "version" : { "number" : "2.4.4", "build_hash" : "fcbb46dfd45562a9cf00c604b30849a6dec6b017", "build_timestamp" : "2017-01-03T11:33:16Z", "build_snapshot" : false, "lucene_version" : "5.5.2" }, "tagline" : "You Know, for Search" } 3.构建elasticsearch集群 [root@node3 ~]# vim /etc/elasticsearch/elasticsearch.yml cluster.name: "elasticsearch" #集群名字 node.name: "node3.bc.com" #节点名字,三个节点都需要不同的名字以示区分 network.host: 0.0.0.0 #监听地址 http.port: 9200 #浏览器访问地址 discovery.zen.ping.unicast.hosts: ["node2.bc.com", "node3.bc.com", "node1.bc.com"] #node1,node2,node3三个节点的单播通信,告诉大家自己的存活状态。 注意:这个地方是最坑的!!!

冒号后面,逗号后边少一个空格都会启动失败。

4.为elasticsearch安装插件 1.安装kopf插件 [root@node2 ~]# /usr/share/elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf/ 2.安装head插件 [root@node2 ~]# /usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head 3.查看已经安装的插件 [root@node2 ~]# /usr/share/elasticsearch/bin/plugin list Installed plugins in /usr/share/elasticsearch/plugins: - head - license - kopf 需要注意的是:

1.三个节点的插件必须都安装,否则启动不了。
systemctl status elasticsearch一般会报错: IllegalArgumentException[No custom metadata prototype registered for type
2.本地没有插件的话会自动从github下载
比较坑的是,elaticsearch的不同版本plugin这个命令的使用方法可能会不同
不过可以用-h来显示使用方法,命令不要复制就用。

5.使用浏览器访问 浏览器输入elasticsearch节点之一的地址: :9200/_plugin/head/

安装ELK Stack海量日志分析系统


elk.jpg

使用logstash内置的匹配规则,匹配httpd的日志格式

1.这个不是必要的配置文件,我们在这里先探究一下默认的匹配规则有什么用。

#编写一个叫apachelog.conf的文件,用来写匹配httpd日志的规则。 [root@bc ~]# vim apachelog.conf input { file { path => ["/var/log/httpd/access_log"] type => "apachelog" start_position => "beginning" } } filter { grok { match => { "message" => "%{COMBINEDAPACHELOG}" } } } output { stdout { codec => rubydebug } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/871a9a8bd82e43a28372bc8fa39dee82.html