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 安装

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

安装ElasticSearch

yum install epel-release
yum install npm nodejs
# centos7 若安装nodejs失败,请执行如下命令再重试
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
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.3.rpm
yum localinstall elasticsearch-6.2.3.rpm
# 修改network.host: 0.0.0.0
vim /etc/elasticsearch/elasticsearch.yml
systemctl start elasticsearch
systemctl enable elasticsearch
systemctl status elasticsearch
# elasticsearch工具目录
/usr/share/elasticsearch/bin/
# 系统要求
vim /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
vim /etc/sysctl.conf
vm.max_map_count=262144
# 临时生效命令
sysctl -w vm.max_map_count=262144

安装elasticsearch-head

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

安装filebeat

wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.2.3-x86_64.rpm
yum localinstall filebeat-6.2.3-x86_64.rpm
vim /etc/filebeat/filebeat.yml
# 修改paths配置路径
# 将enabled设置为true!!
# 将Filebeat和Logstash连接起来
# 将output.elasticsearch注释掉#
# 打开Logstash的注释
# 修改完成后的配置如下:
grep -vE "^$|#|;" /etc/filebeat/filebeat.yml
filebeat.prospectors:
- type: log
enabled: true
paths:
- /var/log/*.log
exclude_lines: ['^DBG', '^OK','^$'] #排查DBG、OK和空行
include_lines: ['^ERR', '^WARN']
exclude_files: ['.gz$', '*error.log']
filebeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false
setup.template.settings:
index.number_of_shards: 3
setup.kibana:
output.logstash:
hosts: ["localhost:5044"]
# 启动filebeat
systemctl start filebeat
systemctl enable filebeat
systemctl status filebeat

安装logstash

wget https://artifacts.elastic.co/downloads/logstash/logstash-6.2.3.rpm
yum localinstall logstash-6.2.3.rpm
vim /etc/logstash/logstash.yml
# 修改path.config配置
path.config: /etc/logstash/conf.d
vim /etc/logstash/conf.d/logstash.conf
input {
beats {
port => 5044
}
} filter {
grok {
match => {
"request" => "\s+(?<api_path>.+?)(\?.*)?\s+"
}
}
grok {
match => {
"agent" => "(?<browser>Maxthon|QQBrowser|Chrome|Safari|Firefox|Opera|MSIE?)(/[0-9.]+)?"
}
}
grok {
match => {
"agent" => "(?<os>Android|SymbianOS|Macintosh|iPad|iPhone|iPod|Linux|Windows?)"
}
}
mutate {
split => [ "upstreamtime", "," ]
}
} output {
elasticsearch {
hosts => ["192.168.1.216:9200"]
index => "logstash-%{+YYYY.MM.dd}_log"
}
stdout { codec => rubydebug }
}
# 给logstash做软连接
ln -s /usr/share/logstash/bin/logstash /usr/bin/logstash
systemctl start logstash
systemctl enable logstash
systemctl status logstash
cd /usr/share/logstash/bin
# 解析配置文件并报告任何出现错误的错误
logstash -f logstash.conf --config.test_and_exit
# 窗口启动 (以下启动方式不推荐,服务启动即可)
logstash -f /etc/logstash/conf.d/logstash.conf
# 后台运行
nohup logstash -f /etc/logstash/conf.d &
nohup logstash -f /etc/logstash/conf.d > logstash.log 2>&1 &

安装kibana

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

安装nginx

yum install nginx httpd-tools
htpasswd -c /etc/nginx/htpasswd.users XXX vi /etc/nginx/conf.d/kibana.conf
server {
listen 80;
server_name 192.168.1.216;
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/htpasswd.users;
location / {
proxy_pass http://localhost:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
} systemctl enable nginx
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. 基于vue-cli快速构建

    基于vue-cli快速构建 https://www.jianshu.com/p/2769efeaa10a   Vue是近两年来比较火的一个前端框架(渐进式框架吧),与reactjs和angularjs ...

  2. 在线生成二维码的API接口

    现在很多大网站都有这样的一个功能,使用手机扫描一下网页上的二维码便可快速在手机上访问网站.想要实现这样的功能其实很简单,下面麦布分享几个在线生成网址二维码的API接口.都是采用http协议接口,无需下 ...

  3. jQuery(六)、事件

    1 页面载入 1.ready(fn) 当DOM载入完后绑定一个要执行的函数. 这是事件模块中最重要的一个函数,可以极大地提高web应用程序的响应速度. $(document).ready(functi ...

  4. Spring中关于AOP的实践之概念

    一.什么是AOP AOP:也称作面向切面编程 在分享几个概念执行我想先举个栗子(可能例子举得并不是特别恰当): 1.假如路人A走在大街上,被一群坏人绑架了: 2.警察叔叔接到报警迅速展开行动:收集情报 ...

  5. 前端入门20-JavaScript进阶之异步回调的执行时机

    声明 本系列文章内容全部梳理自以下几个来源: <JavaScript权威指南> MDN web docs Github:smyhvae/web Github:goddyZhao/Trans ...

  6. 【esri-loader】帮助文档翻译 part2 用法

    esri-loader怎么用?看完不要太清楚. [未完待续]!!! Q1: 在哪里用? 这是我最疑惑的问题之一,我知道要用esri-loader,肯定是某条js导入语句起作用的,但是你得告诉我写在哪里 ...

  7. 设计模式系列之装饰模式(Decorator Pattern)

    装饰器模式(Decorator Pattern)允许向一个现有的对象添加新的功能,同时又不改变其结构.这种类型的设计模式属于结构型模式,它是作为现有的类的一个包装.这种模式创建了一个装饰类,用来包装原 ...

  8. 本地Windows环境Dubbo搭建测试

    Dubbo介绍 Dubbo[]是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案. 其核心部分包含: 远程通讯: 提供对多种基于长连接的NIO框架抽象封装, ...

  9. Maven deploy部署jar包到远程私仓

    Maven deploy部署jar包到远程私仓 maven deploy介绍 maven中的仓库分为两种,snapshot快照仓库和release发布仓库.snapshot快照仓库用于保存开发过程中的 ...

  10. c#实现用SQL池(多线程),定时批量执行SQL语句 【转】

    在实际项目开发中,业务逻辑层的处理速度往往很快,特别是在开发Socket通信服务的时候,网络传输很快,但是一旦加上数据库操作,性能一落千丈,数据库操作的效率往往成为一个系统整体性能的瓶颈.面对这问题, ...