当前位置:   article > 正文

ELK-Kibana 部署

ELK-Kibana 部署

目录

一、在 node1 节点上操作

1.1.安装 Kibana

1.2.设置 Kibana 的主配置文件 

1.3.启动 Kibana 服务 

1.4.验证 Kibana 

1.5.将 Apache 服务器的日志(访问的、错误的)添加到 ES 并通过 Kibana 显示 

1.6. 浏览器访问 

二、部署Filebeat+ELK(ELFK) 

2.1.安装 Filebeat

2.2.设置 Kibana 的主配置文件


一、在 node1 节点上操作

1.1.安装 Kibana

  1. [root@node1 elasticsearch-head]# cd /opt
  2. [root@node1 opt]# rz -E #上传软件包 kibana-5.5.1-x86_64.rpm
  3. [root@node1 opt]# rpm -ivh kibana-5.5.1-x86_64.rpm

1.2.设置 Kibana 的主配置文件 

  1. [root@node1 opt]# vim /etc/kibana/kibana.yml
  2. ##2行,取消注释,kibana服务的默认监听端口为5601
  3. server.port: 5601
  4. ##7行,取消注释,设置kibana的监听地址,0.0.0.0代表所有地址
  5. server.host: "0.0.0.0"
  6. ##21行,取消注释,设置和ES建立连接的地址和端口
  7. elasticsearch.url: "http://192.168.190.101:9200"
  8. ##30行,取消注释,设置在ES中添加.kibana索引
  9. kibana.index: ".kibana"

1.3.启动 Kibana 服务 

  1. [root@node1 opt]# systemctl start kibana.service
  2. [root@node1 opt]# systemctl enable kibana.service
  3. [root@node1 opt]# netstat -natp | grep 5601
  4. tcp 0 0 0.0.0.0:5601 0.0.0.0:* LISTEN 82765/node

1.4.验证 Kibana 

浏览器访问 http://192.168.190.101:5601

第一次登录需要添加一个 ES 索引

点击 create 创建

索引添加完成后,点击 Discover 按钮可查看图表信息及日志信息

1.5.将 Apache 服务器的日志(访问的、错误的)添加到 ES 并通过 Kibana 显示 

apache 服务器

  1. [root@apache opt]# vim /etc/logstash/conf.d/apache_log.conf
  2. input {
  3. file{
  4. path => "/etc/httpd/logs/access_log"
  5. type => "access"
  6. start_position => "beginning"
  7. }
  8. file{
  9. path => "/etc/httpd/logs/error_log"
  10. type => "error"
  11. start_position => "beginning"
  12. }
  13. }
  14. output {
  15. if [type] == "access" {
  16. elasticsearch {
  17. hosts => ["192.168.190.101:9200"]
  18. index => "apache_access-%{+YYYY.MM.dd}"
  19. }
  20. }
  21. if [type] == "error" {
  22. elasticsearch {
  23. hosts => ["192.168.190.101:9200"]
  24. index => "apache_error-%{+YYYY.MM.dd}"
  25. }
  26. }
  27. }
  28. [root@apache opt]# cd /etc/logstash/conf.d
  29. [root@apache conf.d]# /usr/share/logstash/bin/logstash -f apache_log.conf
  30. ······
  31. 23:42:13.199 [Api Webserver] INFO logstash.agent - Successfully started Logstash API endpoint {:port=>9601}

 

1.6. 浏览器访问 

浏览器访问 http://192.168.190.101:9100 查看索引是否创建
可能你只看到了 apache-error,那是因为 access 需要访问 httpd 页面才能生成

浏览器访问 http://192.168.190.101:5601 登录 kibana,添加 apache_access-* 和 apache_error-* 索引,查看日志信息

 

二、部署Filebeat+ELK(ELFK) 

2.1.安装 Filebeat

  1. #上传软件包 filebeat-6.2.4-linux-x86_64.tar.gz 到/opt目录
  2. cd /opt
  3. rz -E
  4. tar zxvf filebeat-6.6.0-linux-x86_64.tar.gz
  5. mv filebeat-6.6.0-linux-x86_64 /usr/local/filebeat

2.2.设置 Kibana 的主配置文件

  1. [root@filebeat opt]# cd /usr/local/filebeat/
  2. [root@filebeat filebeat]# cp filebeat.yml filebeat.yml.bak
  3. [root@filebeat filebeat]# vim filebeat.yml
  4. filebeat.prospectors:
  5. ##21行,指定log类型,从日志文件中读取消息
  6. - type: log
  7. ##24行,开启日志收集功能,默认为false
  8. enabled: true
  9. ##28行,指定监控的日志文件
  10. - /var/log/*.log
  11. ##29行,添加收集/var/log/messages
  12. - /var/log/messages
  13. ##31行,添加以下内容,注意格式
  14. fields:
  15. service_name: filebeat
  16. log_type: log
  17. service_id: 192.168.190.105
  18. #-------------------------- Elasticsearch output ------------------------------
  19. 该区域内容全部注释
  20. #----------------------------- Logstash output --------------------------------
  21. ##157行,取消注释
  22. output.logstash:
  23. ##159行,取消注释,指定logstash的IP和端口号
  24. hosts: ["192.168.190.101:5044"]
  25. [root@filebeat filebeat]# ./filebeat -e -c filebeat.yml
  26. #启动filebeat,-e记录到stderr并禁用syslog /文件输出,-c指定配置文件

 

  1. [root@apache ~]# cd /etc/logstash/conf.d/
  2. [root@apache conf.d]# vim logstash.conf
  3. input {
  4. beats {
  5. port => "5044"
  6. }
  7. }
  8. output {
  9. elasticsearch {
  10. hosts => ["192.168.190.101:9200"]
  11. index => "%{[fields][service_name]}-%{+YYYY.MM.dd}"
  12. }
  13. stdout {
  14. codec => rubydebug
  15. }
  16. }
  17. [root@apache conf.d]# /usr/share/logstash/bin/logstash -f apache_log.conf

  浏览器验证

  1. 浏览器访问,登录 Kibana 测试,
  2. 浏览器访问 http://192.168.190.101:5601 登录 Kibana
  3. 单击“Create Index Pattern”按钮添加索引“filebeat-*”
  4. 单击 “create” 按钮创建,单击 “Discover” 按钮可查看图表信息及日志信息。

 

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/411251
推荐阅读
相关标签
  

闽ICP备14008679号