-
1. filebeat
-
filebeat安装
添加repo源rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
yum 安装cd /etc/yum.repos.d/ vim elastic.repo ''' [elastic-7.x] name=Elastic repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md '''
yum install filebeat systemctl restart filebeat
-
filebeat配置
/etc/filebeat/filebeat.yml# nginx input 开启 - type: log # Change to true to enable this input configuration. enabled: true # Paths that should be crawled and fetched. Glob based paths. paths: - /var/log/nginx/access_spark.log #- c:\programdata\elasticsearch\logs\* ...... # logstatsh output开启 output.logstash: # The Logstash hosts hosts: ["172.17.1.65:5044"]
-
filebeat 调试技巧
filebeat开启后,不会主动输出日志,需要手动运行filebeat,打开调试模式filebeat -e -d "*"
-
-
2.nginx
-
修改nginx配置
/etc/nginx/log_format spark '$remote_addr $time_local $request_method $uri $status'; access_log /var/log/nginx/access_spark.log spark;
-
-
3.logstash + ES + Kibana
-
安装
直接docker安装,有elk的docker镜像docker pull sebp/elk docker run -d -p 5044:5044 -p 5601:5601 -p 9200:9200 -p 9300:9300 -v /var/data/elk:/var/lib/elasticsearch --mount type=bind,source=/var/log/nginx,target=/var/log/nginx --name=elk sebp/elk docker exec -it elk /bin/bash
-
修改配置
修改logstash配置,接收filebeat的input, 输出到ES。
/etc/logstash/conf.d
运行logstash,貌似修改配置后service logstatsh restart 报错,手动运行input { beats { port => 5044 ssl => false #ssl_certificate => "/etc/pki/tls/certs/logstash-beats.crt" #ssl_key => "/etc/pki/tls/private/logstash-beats.key" } } filter { grok { match => {"message" => "%{IPORHOST:remote_addr} %{HTTPDATE:time_local} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:http_version}"} } if "/static" in [request] or "/favicon.ico" in [request] { drop{} } if !("/login" in [request] or "/admin/" in [request] or "/msp/" in [request] or "/company/" in [request] or "/sso_login" in [request]){ drop {} } } output { elasticsearch { hosts => ["localhost:9200"] index => "logstash-nginx-%{+YYYY.MM.dd}" } }
nohup /opt/logstash/bin/logstash -f /etc/logstash/conf.d/beats-access.conf &
-
-
小结
至此一套监控系统就可以使用,可以登录到kibana查看记录,kibana的具体使用会在另外一篇文章介绍。
filebeat+logstash+ES+kibana收集nginx日志
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...