Linux——ELK(Elasticsearch + Logstash + Kibana)企业日志分析之linux系统history收集展示
最近一方面给自己开发的平台套模板,一方面研究一些新的技术,比如今天介绍的elk,下面是介绍一下我是如何使用elk收集linux系统history与展示的。一、效果图
下面是效果图,感觉满足你需求在继续看
http://s3.运维网.com/wyfs02/M00/74/79/wKioL1YfAU2jMKYsAAXAnHuyzeQ728.jpg
下面是具体介绍
1、Linux系统历史命令数据总量
http://s3.运维网.com/wyfs02/M01/74/7D/wKiom1YfAZfSziq4AACjySrLFq0907.jpg
主要是展示所选时间段接收history数据总量,比如昨天我总共收集了1002条数据
2、Linux系统历史命令监控主机数量
http://s3.运维网.com/wyfs02/M00/74/79/wKioL1YfAhPB0bs4AACV6SfiWCk618.jpg
主要是监控总共有多少台主机开始收集history日志数据
3、LInux系统历史命令运行最多Top5
http://s3.运维网.com/wyfs02/M00/74/7D/wKiom1YfAjTAwD9aAADoB6gywXQ361.jpg
主要是介绍运行最多的命令,比如第一个ll命令运行最多
4、Linux系统历史命令登陆主机Top5
http://s3.运维网.com/wyfs02/M02/74/79/wKioL1YfAomDAsxdAADlUVGCFMA501.jpg
主要是介绍登陆主机ip最多的前5个
5、Linux系统历史命令时间数据总量
http://s3.运维网.com/wyfs02/M01/74/7D/wKiom1YfAqPzRkB7AAHNlXSdpH0389.jpg
主要介绍各时间段收集的数据总量
6、Linux系统历史命令数据
http://s3.运维网.com/wyfs02/M02/74/7D/wKiom1YfAtTRHQGuAAQFedGroNw800.jpg
主要是展示每条收集数据内容,包括收集时间、收集的主机名、当前登陆ip、登陆用户、当前用户、运行命令。
二、logstash安装
我使用的elk架构如下
http://s3.运维网.com/wyfs02/M00/74/7A/wKioL1YfA1_zpefQAAFY7Lj_vh0308.jpg
ps:这个图是网上找的
我的elk版本分别为
logstash 1.5.4-1
redis 3.0.4
elasticsearch 1.7.1
kibana 4.1.1
下面介绍如何安装elk
其实shipper与indexer的logstash安装一样,只不过是配置文件不一样
先介绍如何安装logstash
我使用yum安装,下面是安装yum源
12345678cat >>/etc/yum.repos.d/logstash.repo ["/var/log/command.log"]type => "command"codec => "json" }} output {redis { host => ["10.10.125.8:6379"] data_type =>"list"key => "logstash:redis" } } 这个配置就是收集/var/log/command.log的日志,这个日志是记录history命令的,output输出到redis服务。
下面是如何记录history历史命令
在/etc/bashrc里添加
123456789cat >>/etc/bashrc> /var/log/command.log'EOF 然后source /etc/bashrc
查看一下/var/log/command.log
http://s3.运维网.com/wyfs02/M02/74/7D/wKiom1YfBVCj7xakAAiv_doGFP0568.jpg
是一个json格式的,包括时间、主机名、登陆ip、登陆用户、当前用户、命令
下面是indexer的配置
12345678910111213141516171809:25:19 # cat /etc/logstash/conf.d/logstash_indexer.confinput {redis { host => "10.10.125.8" port => "6379" data_type => "list" key => "logstash:redis" type => "redis-input"}}output { elasticsearch { host =>"172.16.3.72" codec => "json" protocol => "http" } stdout {}} 其中10.10.125.8是redis服务器,172.16.3.72是elasticsearch的ip
启动的话就使用/etc/init.d/logstash start
三、redis安装
1、下载
1wget http://download.redis.io/releases/redis-3.0.4.tar.gz 2、解压
1tar zxvf redis-3.0.4.tar.gz -C /usr/local/ 3、安装
12cd /usr/local/redis-3.0.4make 4、复制程序变量
12cp src/redis-cli /usr/bincp src/redis-server /usr/bin 5、创建目录
1mkdir conf log db data 6、配置文件
12345678910111213141516171819202122232425262728293031323334353637383940414243# cat conf/redis-6379.conf |grep -v "^#"|sed '/^$/d'daemonize yespidfile /var/run/redis_6379.pidport 6379bind 10.10.125.8timeout 0tcp-keepalive 0loglevel noticelogfile /var/log/redis/redis_6379.logdatabases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename redis_6379.rdbdir /usr/local/redis-3.0.4/db/slave-serve-stale-data yesslave-read-only yesrepl-disable-tcp-nodelay noslave-priority 100appendonly noappendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mblua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-entries 512list-max-ziplist-value 64set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes 7、启动redis
1redis-server /usr/local/redis-3.0.4/conf/redis-6379.conf 四、安装elasticsearch
1、安装
123curl -L -O https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.1.zipunzip elasticsearch-1.7.1.zipcdelasticsearch-17.1 2、配置
123409:52:38 # grep -v "^#" config/elasticsearch.yml |sed '/^$/d'cluster.name: dl-elknode.name: "elk-bj-1-server"node.master: true 就配置了集群命令与节点名字
3、启动
1bin/elasticsearch -d 这样elk就都安装完成了,我也没写的太详细,大家有需求可以自己查看官方介绍安装。
附件里我把我的Dashboard与相应视图都export了,大家需要可以自行import,但一定注意版本。
导入的顺序是:
1、Linux系统历史命令图形.json;
2、Linux系统历史命令搜索.json;
3、Linux系统历史命令数据视图.json.
本文出自 “吟—技术交流” 博客,请务必保留此出处http://dl528888.blog.运维网.com/2382721/1703059
页:
[1]