ELK日志系统:Elasticsearch + Logstash + Kibana 搭建教程

系统架构

安装配置JDK环境

JDK安装(不能安装JRE)

JDK下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

下载包:jdk-8u131-linux-x64.rpm

yum localinstall jdk-8u131-linux-x64.rpm

mvn 安装

  1. cd /usr/local
  2. wget http://www-eu.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
  3. tar xzf apache-maven-3.3.9-bin.tar.gz
  4. mv apache-maven-3.3.9 maven
  5. vi /etc/profile.d/maven.sh
  6. export M2_HOME=/usr/local/maven
  7. export PATH=${M2_HOME}/bin:${PATH}
  8. source /etc/profile.d/maven.sh
  9. mvn -version

安装ElasticSearch

  1. yum install epel-release
  2. yum install npm nodejs
  3. # centos7 若安装nodejs失败,请执行如下命令再重试
  4. rpm -ivh https://kojipkgs.fedoraproject.org//packages/http-parser/2.7.1/3.el7/x86_64/http-parser-2.7.1-3.el7.x86_64.rpm
  5. wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.3.rpm
  6. yum localinstall elasticsearch-6.2.3.rpm
  7. # 修改network.host: 0.0.0.0
  8. vim /etc/elasticsearch/elasticsearch.yml
  9. systemctl start elasticsearch
  10. systemctl enable elasticsearch
  11. systemctl status elasticsearch
  12. # elasticsearch工具目录
  13. /usr/share/elasticsearch/bin/
  14. # 系统要求
  15. vim /etc/security/limits.conf
  16. * soft nofile 65535
  17. * hard nofile 65535
  18. vim /etc/sysctl.conf
  19. vm.max_map_count=262144
  20. # 临时生效命令
  21. sysctl -w vm.max_map_count=262144

安装elasticsearch-head

  1. # 增加新的参数,这样head插件可以访问es
  2. vim /etc/elasticsearch/elasticsearch.yml
  3. http.cors.enabled: true
  4. http.cors.allow-origin: "*"
  5. cd /usr/share/elasticsearch
  6. git clone git://github.com/mobz/elasticsearch-head.git
  7. cd elasticsearch-head
  8. npm install
  9. npm run start
  10. # elasticsearch-head访问地址
  11. http://localhost:9100/
  12. # 若head插件无法连接到es,编辑app.js查找9200修改参数localhost为本机ip
  13. vim _site/app.js

安装filebeat

  1. wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.2.3-x86_64.rpm
  2. yum localinstall filebeat-6.2.3-x86_64.rpm
  3. vim /etc/filebeat/filebeat.yml
  4. # 修改paths配置路径
  5. # 将enabled设置为true!!
  6. # 将Filebeat和Logstash连接起来
  7. # 将output.elasticsearch注释掉#
  8. # 打开Logstash的注释
  9. # 修改完成后的配置如下:
  10. grep -vE "^$|#|;" /etc/filebeat/filebeat.yml
  11. filebeat.prospectors:
  12. - type: log
  13. enabled: true
  14. paths:
  15. - /var/log/*.log
  16. exclude_lines: ['^DBG', '^OK','^$'] #排查DBG、OK和空行
  17. include_lines: ['^ERR', '^WARN']
  18. exclude_files: ['.gz$', '*error.log']
  19. filebeat.config.modules:
  20. path: ${path.config}/modules.d/*.yml
  21. reload.enabled: false
  22. setup.template.settings:
  23. index.number_of_shards: 3
  24. setup.kibana:
  25. output.logstash:
  26. hosts: ["localhost:5044"]
  27. # 启动filebeat
  28. systemctl start filebeat
  29. systemctl enable filebeat
  30. systemctl status filebeat

安装logstash

  1. wget https://artifacts.elastic.co/downloads/logstash/logstash-6.2.3.rpm
  2. yum localinstall logstash-6.2.3.rpm
  3. vim /etc/logstash/logstash.yml
  4. # 修改path.config配置
  5. path.config: /etc/logstash/conf.d
  6. vim /etc/logstash/conf.d/logstash.conf
  7. input {
  8. beats {
  9. port => 5044
  10. }
  11. }
  12. filter {
  13. grok {
  14. match => {
  15. "request" => "\s+(?<api_path>.+?)(\?.*)?\s+"
  16. }
  17. }
  18. grok {
  19. match => {
  20. "agent" => "(?<browser>Maxthon|QQBrowser|Chrome|Safari|Firefox|Opera|MSIE?)(/[0-9.]+)?"
  21. }
  22. }
  23. grok {
  24. match => {
  25. "agent" => "(?<os>Android|SymbianOS|Macintosh|iPad|iPhone|iPod|Linux|Windows?)"
  26. }
  27. }
  28. mutate {
  29. split => [ "upstreamtime", "," ]
  30. }
  31. }
  32. output {
  33. elasticsearch {
  34. hosts => ["192.168.1.216:9200"]
  35. index => "logstash-%{+YYYY.MM.dd}_log"
  36. }
  37. stdout { codec => rubydebug }
  38. }
  39. # 给logstash做软连接
  40. ln -s /usr/share/logstash/bin/logstash /usr/bin/logstash
  41. systemctl start logstash
  42. systemctl enable logstash
  43. systemctl status logstash
  44. cd /usr/share/logstash/bin
  45. # 解析配置文件并报告任何出现错误的错误
  46. logstash -f logstash.conf --config.test_and_exit
  47. # 窗口启动 (以下启动方式不推荐,服务启动即可)
  48. logstash -f /etc/logstash/conf.d/logstash.conf
  49. # 后台运行
  50. nohup logstash -f /etc/logstash/conf.d &
  51. nohup logstash -f /etc/logstash/conf.d > logstash.log 2>&1 &

安装kibana

  1. wget https://artifacts.elastic.co/downloads/kibana/kibana-6.2.3-x86_64.rpm
  2. yum localinstall kibana-6.2.3-x86_64.rpm
  3. vim /etc/kibana/kibana.yml
  4. # 修改elasticsearch.url参数
  5. server.host: "0.0.0.0"
  6. elasticsearch.url: "http://localhost:9200"
  7. systemctl start kibana
  8. systemctl enable kibana
  9. systemctl status kibana

安装nginx

  1. yum install nginx httpd-tools
  2. htpasswd -c /etc/nginx/htpasswd.users XXX
  3. vi /etc/nginx/conf.d/kibana.conf
  4. server {
  5. listen 80;
  6. server_name 192.168.1.216;
  7. auth_basic "Restricted Access";
  8. auth_basic_user_file /etc/nginx/htpasswd.users;
  9. location / {
  10. proxy_pass http://localhost:5601;
  11. proxy_http_version 1.1;
  12. proxy_set_header Upgrade $http_upgrade;
  13. proxy_set_header Connection 'upgrade';
  14. proxy_set_header Host $host;
  15. proxy_cache_bypass $http_upgrade;
  16. }
  17. }
  18. systemctl enable nginx
  19. systemctl start nginx

验证

echo "hello world" >/var/opt/log/a.log

curl http://localhost:9200/_search?pretty 查看输出

删除索引

curl -XDELETE http://localhost:9200/twitter

curl -XDELETE http://localhost:9200/_all

列出所有索引

curl -u elastic:changeme 'http://localhost:9200/_cat/indices?v'

查看节点个数

curl http://localhost:9200/_cluster/health?pretty

已知bug

Chrome浏览器插件可能导致kibana显示存在bug,可通过禁用浏览器插件浏览

ELK日志系统:Elasticsearch+Logstash+Kibana+Filebeat搭建教程的更多相关文章

  1. 【linux】【ELK】搭建Elasticsearch+Logstash+Kibana+Filebeat日志收集系统

    前言 ELK是Elasticsearch.Logstash.Kibana的简称,这三者是核心套件,但并非全部. Elasticsearch是实时全文搜索和分析引擎,提供搜集.分析.存储数据三大功能:是 ...

  2. ELK (Elasticsearch , Logstash, Kibana [+FileBeat])

    ELK 简述: ELK 是: Elasticsearch , Logstash, Kibana 简称, 它们都是开源软件. Elasticsearch[搜索]是个开源分布式基于Lucene的搜索引擎, ...

  3. ELK系列(1) - Elasticsearch + Logstash + Kibana + Log4j2快速入门与搭建用例

    前言 最近公司分了个ELK相关的任务给我,在一边学习一边工作之余,总结下这些天来的学习历程和踩坑记录. 首先介绍下使用ELK的项目背景:在项目的数据库里有个表用来存储消息队列的消费日志,这些日志用于开 ...

  4. Centos7下使用ELK(Elasticsearch + Logstash + Kibana)搭建日志集中分析平台

    日志监控和分析在保障业务稳定运行时,起到了很重要的作用,不过一般情况下日志都分散在各个生产服务器,且开发人员无法登陆生产服务器,这时候就需要一个集中式的日志收集装置,对日志中的关键字进行监控,触发异常 ...

  5. ELK(elasticsearch+logstash+kibana)入门到熟练-从0开始搭建日志分析系统教程

    #此文篇幅较长,涵盖了elk从搭建到运行的知识,看此文档,你需要会点linux,还要看得懂点正则表达式,还有一个聪明的大脑,如果你没有漏掉步骤的话,还搭建不起来elk,你来打我. ELK使用elast ...

  6. 【转】ELK(ElasticSearch, Logstash, Kibana)搭建实时日志分析平台

    [转自]https://my.oschina.net/itblog/blog/547250 摘要: 前段时间研究的Log4j+Kafka中,有人建议把Kafka收集到的日志存放于ES(ElasticS ...

  7. 【Big Data - ELK】ELK(ElasticSearch, Logstash, Kibana)搭建实时日志分析平台

    摘要: 前段时间研究的Log4j+Kafka中,有人建议把Kafka收集到的日志存放于ES(ElasticSearch,一款基于Apache Lucene的开源分布式搜索引擎)中便于查找和分析,在研究 ...

  8. 02篇ELK日志系统——升级版集群之kibana和logstash的搭建整合

    [ 前言:01篇LK日志系统已经把es集群搭建好了,接下来02篇搭建kibana和logstash,并整合完成整个ELK日志系统的初步搭建. ] 1.安装kibana 3台服务器: 192.168.2 ...

  9. 搭建Elasticsearch Logstash Kibana 日志系统

    分布式系统下由于日志文件分布在不同的系统上,分析比较麻烦,通过搭建elk日志系统,可快速排查日志信息. Elasticsearch是大数据处理框架,使用的分布式存储,可存储海量数据:基于Lucense ...

随机推荐

  1. C#工具:加密解密帮助类

    using System; using System.IO; using System.Security.Cryptography; using System.Text; //加密字符串,注意strE ...

  2. PostgreSQL相关整理

    PostgreSQL权限管理之创建可更新表的普通用户 https://my.oschina.net/aven92/blog/528943 PostgreSQL学习手册(角色和权限) http://ww ...

  3. Java虚拟机垃圾收集算法

    1.标记-清除算法 标记-清除算法分为 "标记" 和 "清除" 两个步骤:首先标记出所有需要回收的对象,然后在标记完成后统一回收所有被标记的对象,是垃圾收集算法 ...

  4. spring2.0 mybatis JDBC配置

    mybatis 搭建 <!--连接池--> <dependency> <groupId>org.springframework.boot</groupId&g ...

  5. html 微信video放大后无法返回问题

    android  video播放视频放大后无法返回,先debug下debugx5.qq.com 发现用的不是X5内核 直接激活  debugmm.qq.com/?forcex5=true  问题解决 ...

  6. 《JavaScript高级程序设计》笔记:事件(十三)

    事件流 事件冒泡 IE的事件流叫做事件冒泡,即事件开始时由最具体的元素接收,然后逐级向上传播到较为不具体的节点(文档).如下代码: <body> <div id="myDi ...

  7. Dynamics CRM项目实例之七:站点地图修改,联系人-订单-积分管理

    关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复138或者20141229可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me!        前面文章发表后,不 ...

  8. SAP MM 采购ERP顾问咨询费限制总金额的框架协议实现方案

    SAP MM 采购ERP顾问咨询费限制总金额的框架协议实现方案 [业务场景] 采购部门与ERP咨询公司签订了一个框架协议,只规定不同级别顾问的人天费用,不限定这些不同级别咨询顾问的具体采购的人天数,但 ...

  9. Android Material Design控件使用(一)——ConstraintLayout 约束布局

    参考文章: 约束布局ConstraintLayout看这一篇就够了 ConstraintLayout - 属性篇 介绍 Android ConstraintLayout是谷歌推出替代PrecentLa ...

  10. swing Jframe 界面风格

    用法:在jframe里面 UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel" ...