Rsyslog+ELK日志分析系统

这里主要总结一下搭建过程

一.rsyslog

rsyslog是现在大多数linux自带的日志收集,这里主要说一下rsyslog的简单配置。

client端配置它只须要更改准备发送的日志以及在末尾加上Server端使用的协议和IP便可,例如:

#加入如下便可 *.* @10.144.100.32:514

二.logstash配置

logstash只须要将rsyslog收集起来并转发至elasticsearch,配置以下:

vi /etc/logstash.conf

input{
        syslog{
        type=>"system-syslog"
        port=>514
        host=>"10.144.100.32"
        }
        }

        filter{
        date{
        match=>["timestamp","yyyy-MM-dd-HH:mm:ss"]
        locale=>"cn"
        }
        }
        output{
        elasticsearch{
        hosts=>["10.24.180.19:9200"]
        user=>"elastic"
        password=>"123456"
        index=>"blockchain-%{type}-%{+YYYY.MM.dd}"
        codec=>"json"
        }
        stdout{
        codec=>json
        }
}
cd logstash-5.5.1/bin/ ./logstash -f /etc/logstash.conf

三.Elasticsearch搭建

elasticsearch搭建起来比较简单,直接在https://www.elastic.co/downloads/elasticsearch下载elasticsearch压缩包,解压下来。

cd elasticsearch-5.5.1/bin/
./elasticsearch &

本地浏览器访问http://localhost:9200浏览器

*注意:安装elasticsearch尽可能先改一下内核参数和资源参数,我在阿里云上搭建的,默认的内核参数和资源参数可能会致使启动失败。

vim /etc/sysctl.conf #修改或添加如下参数 

fs.file-max=65536 
vm.max_map_count = 262144 

vim /etc/security/limits.conf #修改或添加如下参数 
* soft nofile 65536 
* hard nofile 131072 
* soft nproc 2048 
* hard nproc 4096

elasticsearch有几个比较推荐的插件,这里介绍一下head插件安装,并经过head插件介绍一下elasticsrach的一些基本概念。restful

首先介绍一下head的安装,ES5.0以前head插件是直接能够经过elasticsearch-plugin install安装,5.0以后不能够直接插件安装,但依然是能够安装使用的。

首先,设置下ES同源访问策略:

vim elasticsearch-5.5.0/conf/elasticsearch.yml #在末尾添加以下内容:
 
http.cors.enabled: true 
http.cors.allow-origin: "*"

经过npm进行安装:

git clone git://github.com/mobz/elasticsearch-head.git cd elasticsearch-head npm install npm run start

elasticsearch若是直接暴露在外网上是很是危险的,这里安装一款x-pack插件,可将此端口设置帐户密码。

cd elasticsearch-5.5.0/bin/ ./ealsticseearch-plugin intsall x-pack

安装完x-pack后,直接访问9200端口会提示输入帐号和密码,这增长了elasticsearch的一些安全性,默认的帐号密码是elastic:changeme,更改帐号密码课经过调用restful API

curl -XPUT -u elastic 'localhost:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "elastic" }'

四.Kibana搭建

kibana是配合Elasticsearch一块儿使用的可视化分析平台,说白了就是更形象的表示Elasticsearch的结果。

vim kibana/config/kibana.yml

server.port: 5601 
server.host: 0.0.0.0 
elasticsearch.url: "http://localhost:9200" 
elasticsearch.username: "elastic" 
elasticsearch.password: "changeme"

浏览器输入localhost:5601 查看是否成功

 
Copyright © 2008-2021 lanxinbase.com Rights Reserved. | 粤ICP备14086738号-3 |