快速搭建ELK集中化日志管理平台
由于我们的项目是分布式,服务分布于多个服务器上,每次查看日志都要登录不同服务器查看,而且查看起来还比较麻烦,老大让搭一个集中化日志管理的东西,然后就在网上找到了这个东西ELK
ELK就是elastic公司下的三款产品,elasticsearch,logstash,kibana
官网:https://www.elastic.co/cn/products
1.我先解释一下这三个产品的功能
1: elasticsearch (ELK核心)
这是一个Lucene的分布式全搜索框架,可以对日志进行分布式存储
2:logstash
它的功能是分布于各个服务器上做日志的收集,比如192.168.1.45上配置了logstash那么他会自动收集你该服务器上的日志传输给elasticsearch
3: kibana
它可以把elasticsearch中的数据进行报表形式的展示
知道了这些以后我们就已经大体了解到ELK的大体工作流程了
2.快速搭建(在这里我全都搭建在一台服务器上了)
从上图中我们都能看出elasticsearch是核心的一个东西,我们先从它这里开始配置
1.elasticsearch配置
elasticsearch是ELK的核心,而且一定要注意他不能使用root账户启动,所以我们直接新创建一个账户来配置elasticsearch,
首先用useradd 命令创建一个账户 比如我创建的账户是elsearch
直接用elsearch账户登录,然后去官网下载wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.1.tar.gz
1 [elsearch@9378y7s1qz ~]$ tar zxf elasticsearch-6.4.0.tar.gz
2 [elsearch@9378y7s1qz ~]$ cd elasticsearch-6.4.0/conf
接下来需要修改elasticsearch.yml
network.host: 0.0.0.0
http.port: 9200
这个如果不修改,外网是没法访问的
接下来就是启动了到bin目录下运行 ./elasticsearch
这个时候你就会发现启动不了
提示最大此用户的最大能使用的线程数太小,最少需要4096这个量级才能启动,可是这玩意在哪修改呢? 每个用户能打开的文件句柄数也和允许此用户能打开的线程进程数有关,Linux上一切皆文件嘛,线程、进程也是以文件句柄书相关的方式控制的 ulimit -n可以查看当前用户能同时使用的文件句柄数限制,当然这玩意我们可以配置,但是我们配置的属于软件限制,每个电脑都有其极限,这个极限基于硬件,如果硬件限制1024,那么我们软件调整到65535也是无济于事的 上网查了查 需要 vim /etc/security/limits.conf 添加或修改
* soft nofile 65536 * hard nofile 131072 * soft nproc 1024 * hard nproc 4096
提示1024不足,而文件中只有一个1024:* soft nproc 1024,我们按照要求将其更改为2048,然后重新尝试一下
还是没法启动,这个时候会
ERROR: [1] bootstrap checks failed [1]:max virtual memory areas vm.max_map_count [1024] is too low, increase to at least [262144]
这个错误需要vim /etc/sysctl.conf添加
vm.max_map_count=262144
然后sysctl -p 一下即可
我们再次启动,这次就正常了,到这里我们的elasticsearch已经配置好了,接下来我们开始配置logstash
2.logStash配置
还是跟之前一样先下载logstash
wget https://artifacts.elastic.co/downloads/logstash/logstash-6.4.1.tar.gz
然后解压
配置的时候我们需要在config下创建一个配置文件logstash.conf
然后做好input ,filter,output三大块, 其中input是吸取logs文件下的所有log后缀的日志文件,filter是一个过滤函数,这里不用配置,output配置了导入到
hosts为127.0.0.1:9200的elasticsearch中,每天一个索引。
input {
file {
type => "log"
path => "/usr/local/logs/*.log" #这里是你需要收集的日志
start_position => "beginning"
}
} output {
stdout {
codec => rubydebug { }
} elasticsearch {
hosts => "127.0.0.1" #elasticsearch地址
index => "log-%{+YYYY.MM.dd}"
}
}
这些配置完成之后就能到/bin下找到logstash 启动脚本了
在启动的时候需要引用刚才我们创建的配置文件
[root@iZwz95t3hfncu7anavrafmZ bin]# ./logstash -f ../config/logstash.conf >lostash.log
Sending Logstash logs to /usr/local/logstash/logs which is now configured via log4j2.properties
[2018-09-19T21:37:07,725][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified
[2018-09-19T21:37:08,899][INFO ][logstash.runner ] Starting Logstash {"logstash.version"=>"6.4.0"}
[2018-09-19T21:37:13,749][INFO ][logstash.pipeline ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>1, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50}
[2018-09-19T21:37:14,763][INFO ][logstash.outputs.elasticsearch] Elasticsearch pool URLs updated {:changes=>{:removed=>[], :added=>[http://0.0.0.0:9200/]}}
[2018-09-19T21:37:14,783][INFO ][logstash.outputs.elasticsearch] Running health check to see if an Elasticsearch connection is working {:healthcheck_url=>http://0.0.0.0:9200/, :path=>"/"}
[2018-09-19T21:37:15,125][WARN ][logstash.outputs.elasticsearch] Attempted to resurrect connection to dead ES instance, but got an error. {:url=>"http://47.107.75.26:9200/", :error_type=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError, :error=>"Elasticsearch Unreachable: [http://127.0.0.1:9200/][Manticore::SocketException] Connection refused (Connection refused)"}
[2018-09-19T21:37:15,194][INFO ][logstash.outputs.elasticsearch] New Elasticsearch output {:class=>"LogStash::Outputs::ElasticSearch", :hosts=>["//47.107.75.26:9200"]}
[2018-09-19T21:37:15,756][INFO ][logstash.inputs.file ] No sincedb_path set, generating one based on the "path" setting {:sincedb_path=>"/usr/local/logstash/data/plugins/inputs/file/.sincedb_71ed980b1f25dc3be65a3d965d78b265", :path=>["/usr/local/logs/*.log"]}
[2018-09-19T21:37:15,849][INFO ][logstash.pipeline ] Pipeline started successfully {:pipeline_id=>"main", :thread=>"#<Thread:0x123f661f run>"}
[2018-09-19T21:37:15,956][INFO ][logstash.agent ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[2018-09-19T21:37:15,986][INFO ][filewatch.observingtail ] START, creating Discoverer, Watch with file and sincedb collections
[2018-09-19T21:37:16,610][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}
在日志中大概可以看到开启了9200,9300端口。现在logstash已经启动了
3.kibana配置
elasticsearch和logstash已经配置好了,那么我们需要展示就需要kibana了,接下来我们来配置kibana
还是先下载kibana,
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.4.1-linux-x86_64.tar.gz
然后解压,这个依然需要我们在config文件下创建配置文件
[root@slave1 config]# vim kibana.yml elasticsearch.url: "http://localhost:9200"
server.host: 0.0.0.0
然后就是启动bin下的kibana
[root@slave1 bin]# ./kibana
log [01:23:27.650] [info][status][plugin:kibana@5.2.0] Status changed from uninitialized to green - Ready
log [01:23:27.748] [info][status][plugin:elasticsearch@5.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
log [01:23:27.786] [info][status][plugin:console@5.2.0] Status changed from uninitialized to green - Ready
log [01:23:27.794] [warning] You're running Kibana 5.2.0 with some different versions of Elasticsearch. Update Kibana or Elasticsearch to the same version to prevent compatibility issues: v5.6.4 @ 192.168.23.151:9200 (192.168.23.151)
log [01:23:27.811] [info][status][plugin:elasticsearch@5.2.0] Status changed from yellow to green - Kibana index ready
log [01:23:28.250] [info][status][plugin:timelion@5.2.0] Status changed from uninitialized to green - Ready
log [01:23:28.255] [info][listening] Server running at http://0.0.0.0:5601
log [01:23:28.259] [info][status][ui settings] Status changed from uninitialized to green – Ready
4.现在我们已经全部搭建好了
剩下的就是访问了,来看看我的页面
OK,我们现在ELK已经成功搭建了
快速搭建ELK集中化日志管理平台的更多相关文章
- 使用Docker快速部署ELK分析Nginx日志实践(二)
Kibana汉化使用中文界面实践 一.背景 笔者在上一篇文章使用Docker快速部署ELK分析Nginx日志实践当中有提到如何快速搭建ELK分析Nginx日志,但是这只是第一步,后面还有很多仪表盘需要 ...
- 基础架构之日志管理平台搭建及java&net使用
在现代化的软件开发流程中,日志显得非常的重要,不可能再零散的游离在各个项目中,等查看日志的时候再登录服务器去到特定的目录去查看,这显然很繁琐且效率低下,所有整合一套日志管理平台,也显得非常重要,这篇文 ...
- .NetCore快速搭建ELK分布式日志中心
懒人必备:.NetCore快速搭建ELK分布式日志中心 该篇内容由个人博客点击跳转同步更新!转载请注明出处! 前言 ELK是什么 它是一个分布式日志解决方案,是Logstash.Elastaics ...
- 2019你该掌握的开源日志管理平台ELK STACK
转载于https://www.vtlab.io/?p=217 在企业级开源日志管理平台ELK VS GRAYLOG一文中,我简单阐述了日志管理平台对技术人员的重要性,并把ELK Stack和Gra ...
- ELK+Kafka 企业日志收集平台(一)
背景: 最近线上上了ELK,但是只用了一台Redis在中间作为消息队列,以减轻前端es集群的压力,Redis的集群解决方案暂时没有接触过,并且Redis作为消息队列并不是它的强项:所以最近将Redis ...
- Centos7.5搭建ELK-6.5.0日志分析平台
Centos7.5搭建ELK-6.5.0日志分析平台 1. 简介 工作工程中,不论是开发还是运维,都会遇到各种各样的日志,主要包括系统日志.应用程序日志和安全日志,对于开发人员来说,查看日志,可以实时 ...
- 使用Docker快速搭建ELK环境
今天由于Win系统的笔记本没带回家,其次Docker在非Linux系统下都需要安装额外的软件去镜像才行 所以感觉没有差别,先直接用Mac搭建一遍呢, 本篇部分命令和配置内容为摘抄 Mac下使用Dock ...
- 使用Docker快速部署ELK分析Nginx日志实践
原文:使用Docker快速部署ELK分析Nginx日志实践 一.背景 笔者所在项目组的项目由多个子项目所组成,每一个子项目都存在一定的日志,有时候想排查一些问题,需要到各个地方去查看,极为不方便,此前 ...
- Go语言学习之13 日志管理平台开发
主要内容: 1. ElasticSearch介绍与使用2. kibana介绍与使用 1. ElasticSearch安装 详见上节内容2. kibana安装 (1) 下载ES,下载地址:https:/ ...
随机推荐
- django-Celery分布式队列简单使用
介绍: Celery 是一个简单.灵活且可靠的,处理大量消息的分布式系统,并且提供维护这样一个系统的必需工具. 它是一个专注于实时处理的任务队列,同时也支持任务调度. worker:是一个独立的进程, ...
- cstringlist
CStringList类成员 构造 CStringList 构造一个空的CString对象列表 首/尾访问 GetHead 返回此列表(不能是空的)中头部的元素 GetTail 返回此列表(不能是 ...
- WPF在win7运行时报'Initialization of 'System.Windows.Setter' threw an exception.'
写的一个WPF程序,在win10运行好好的,在win7就报'Initialization of 'System.Windows.Setter' threw an exception.' 原来是xaml ...
- transition-分栏按钮动画
=> css: .cateBtn{ position: relative; background: #fff; border: 1px solid #ddd; border-radius: ...
- js的三种对象
JS中,可以将对象分为“内部对象”.“宿主对象”和“自定义对象”三种. 1,内部对象 js中的内部对象包括Array.Boolean.Date.Function.Global.Math.Number. ...
- Linux - VMware和Centos安装
目录 Linux - VMware和Centos安装 选择性 下载centos系统ISO镜像 安装虚拟机VMware虚拟机 1. 准备vmware软件 2. 解压软件包, 当前选择vm12 3. vm ...
- Square words(codevs 3301)
题目描述 Description 定义square words为: 1.长度为偶数. 2.前一半等于后一半. 比如abcabc和aaaa都是square words,但是abcabcab和aaaaa都 ...
- hdu_1005_Number Sequence_201310222120
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 【ACM】hdu_zs3_1007_Rails_201308100802
Rails Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other)Total Submissi ...
- POJ 1416 Shredding Company 回溯搜索 DFS
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6173 Accepted: 3361 ...