一、ELKStack简介
Elstaicsearch:存储和搜索
logstash:收集
kibana:展示.专门为ES设计的展示平台
二、ELK之生还环境案例
架构图:
环境准备
IP 主机名 操作系统
192.168.56.11 linux-node1 centos7
192.168.56.12 linux-node2 centos7
1、需求分析
生产环境需求分析
访问日志:apache访问日志、nginx访问日志、tomcat
错误日志:error log、java日志(多行处理)
系统日志:/var/log/* 、 syslog
运行日志:程序写的 (file插件)
网络日志:防火墙、交换机、路由器日志
2、前期准备
(1).标准化:
日志存放位置标准化:/data/logs/
日志格式标准化: JSON
命名规则标准化: access_log,error_log,runtime_log
日志切割标准化:按天、按小时
原始日志文件处理标准化: 通过rsync到NAS,然后删除最近三天前的。
(2).工具化:
如何使用logstash进行收集
3、生产环境案例
在192.168.56.11上我们用apache的日志和elasticsearch的日志做分析,用logstash收取apache的访问日志和es的日志(es的日志是java日志),写入redis
[iyunv@linux-node1 /etc/logstash/conf.d]# cat apache.conf
input {
file {
path => "/var/log/httpd/access_log" #apache日志目录
start_position => "beginning" #从头开始收集
type => "apache-accesslog" #日志类型
}
file{
path => "/var/log/elasticsearch/myes.log" #es日志,根据自己的实际情况,在es的配置文件中自己定义
type => "es-log"
start_position => "beginning"
codec => multiline{
pattern => "^\[" #以“[”作为切分java的分隔符
negate => true
what => "previous"
}
}
}
output {
if [type] == "apache-accesslog" {
redis {
host => "192.168.56.12"
port => "6379"
db => "6"
data_type => "list"
key => "apache-accesslog"
}
}
if [type] == "es-log"{
redis {
host => "192.168.56.12"
port => "6379"
db => "6"
data_type => "list"
key => "es-log"
}
}
}
在192.168.56.12上面,从redis中读取日志,并写入elasticsearch;
同时使用logstash收取syslog日志,并写入es;收取syslog,通过网络传输即可,注意要开通514端口。
我们需要修改rsync的配置文件。
[iyunv@linux-node1 /etc/logstash/conf.d]# tail -n 3 /etc/rsyslog.conf
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
*.* @@192.168.56.12:514
# ### end of the forwarding rule ###
[iyunv@linux-node1 /etc/logstash/conf.d]#
查看端口监听情况
[iyunv@linux-node2 conf.d]# netstat -lntp|grep 514
tcp6 0 0 :::514 :::* LISTEN 43148/java
[iyunv@linux-node2 conf.d]# netstat -lnup|grep 514
udp6 0 0 :::514 :::* 43148/java
[iyunv@linux-node2 conf.d]#
端口监听正常
在192.168.56.12的配置文件如下:
[iyunv@linux-node2 conf.d]# cat indexer.conf
input{
redis {
type => "apache-accesslog"
host => "192.168.56.12"
port => "6379"
db => "6"
data_type => "list"
key => "apache-accesslog"
}
syslog {
type => "system-syslog" #收取syslog
port => 514 #监听514端口
}
redis {
type => "es-log"
host => "192.168.56.12"
port => "6379"
db => "6"
data_type => "list"
key => "es-log"
}
}
filter {
if [tyep] == "apache-accesslog"{
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
} #使用grok处理apache的日志
}
output{
if [type] == "apache-accesslog"{
elasticsearch {
hosts => ["192.168.56.11:9200"]
index => "apache-accesslog-%{+YYYY.MM.dd}"
}
}
if [type] == "es-log"{
elasticsearch {
hosts => ["192.168.56.11:9200"]
index => "es-log-%{+YYYY.MM}"
}
}
if [type] == "system-syslog"{
elasticsearch {
hosts => ["192.168.56.11:9200"]
index => "system-syslog-%{+YYYY.MM}"
}
}
}
[iyunv@linux-node2 conf.d]#
注意:
注意:
注意:由于收集的日志类型比较多,最好把type跟index的名称统一,这样不容易搞混
注意:
注意:
注意:如果使用redis list作为elk的消息队列,那么需要对所有的list key的长度进行监控。
比如使用llen key_name获取key的值,再用zabbix设置监控
正常情况下,写入redis的日志会很快被logstash消费掉。
如果忽然涨到了十万,那肯定是故障了,可以在zabbix设置阀值,进行报警。
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com