filebeat模塊收集nginx日志

1.修改filebeat配置文件

[root@db01 ~]# cat /etc/filebeat/filebeat.yml
##啟動module
filebeat.config.modules:
##設置module配置文件路徑
  path: ${path.config}/modules.d/*.yml
##設置啟用
  reload.period: 10s

setup.kibana:
  host: "172.16.210.53:5601"

output.elasticsearch:
  hosts: ["172.16.210.53:9200"]
  indices:
  - index: "nginx-access-%{[beat.version]}-%{+yyyy.MM}"
    when.contains:
      fileset.name: "access"

  - index: "nginx-error-%{[beat.version]}-%{+yyyy.MM}"
    when.contains:
      fileset.name: "error"

setup.template.name: "nginx"
setup.template.pattern: "nginx-*"
setup.template.enabled: false
setup.template.overwrite: true
[root@db01 ~]# systemctl restart filebeat ##重啟filebeat
[root@db01 ~]# filebeat modules list ##
Enabled:

Disabled:
apache2
auditd
elasticsearch
--
---

2.啟用nginx模塊

[root@db01 ~]# filebeat modules enable nginx
Enabled nginx

3.修改nginx配置文件為普通格式

[root@db01 ~]# egrep -v "^$|#"  /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
 access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    include /etc/nginx/conf.d/*.conf;
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;
        include /etc/nginx/default.d/*.conf;
        location / {
        }
        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}
[root@db01 ~]# systemctl restart nginx ##重啟nginx

4.安裝elasticearch插件

ingest-geoip一般是下載不下來的,可以點擊ftp://www.lcvcqg.top/software/ingest-geoip-6.6.0.zip下載

[root@db01 ~]# /usr/share/elasticsearch/bin/elasticsearch-plugin install ingest-user-agent
[root@db01 ~]# /usr/share/elasticsearch/bin/elasticsearch-plugin install file:///root/ingest-geoip-6.6.0.zip 
-> Downloading file:///root/ingest-geoip-6.6.0.zip
[=================================================] 100%   
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     WARNING: plugin requires additional permissions     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.lang.RuntimePermission accessDeclaredMembers
* java.lang.reflect.ReflectPermission suppressAccessChecks
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.

Continue with installation? [y/N]y
-> Installed ingest-geoip
[root@db01 ~]# systemctl restart elasticsearch ##重啟es

5.修改nginx模塊配置文件

[root@db01 ~]# vim/etc/filebeat/modules.d/nginx.yml 
- module: nginx
  # Access logs
  access:
    enabled: true

    # Set custom paths for the log files. If left empty,
    # Filebeat will choose the paths depending on your OS.
    ##設置nginx訪問日志路徑
    var.paths: ["/var/log/nginx/access.log"]

  # Error logs
  error:
    enabled: true

    # Set custom paths for the log files. If left empty,
    # Filebeat will choose the paths depending on your OS.
    ##設置nginx錯誤日志路徑
    var.paths: ["/var/log/nginx/error.log"]
[root@db01 ~]# systemctl restart nginx ##重啟nginx

6.回到kibana界面添加索引

image.png

選擇read_timestamp

image.png
image.png

選擇read_timestamp

image.png

7.查看數(shù)據(jù)

點擊discover 選擇要查看的索引項

查看錯誤日志
image.png

查看記錄日志
image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末站粟,一起剝皮案震驚了整個濱河市黍图,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌奴烙,老刑警劉巖助被,帶你破解...
    沈念sama閱讀 219,366評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異切诀,居然都是意外死亡揩环,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,521評論 3 395
  • 文/潘曉璐 我一進店門幅虑,熙熙樓的掌柜王于貴愁眉苦臉地迎上來丰滑,“玉大人,你說我怎么就攤上這事倒庵“” “怎么了?”我有些...
    開封第一講書人閱讀 165,689評論 0 356
  • 文/不壞的土叔 我叫張陵擎宝,是天一觀的道長郁妈。 經(jīng)常有香客問我,道長认臊,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,925評論 1 295
  • 正文 為了忘掉前任锄奢,我火速辦了婚禮失晴,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘拘央。我一直安慰自己涂屁,他們只是感情好,可當我...
    茶點故事閱讀 67,942評論 6 392
  • 文/花漫 我一把揭開白布灰伟。 她就那樣靜靜地躺著拆又,像睡著了一般。 火紅的嫁衣襯著肌膚如雪栏账。 梳的紋絲不亂的頭發(fā)上帖族,一...
    開封第一講書人閱讀 51,727評論 1 305
  • 那天,我揣著相機與錄音挡爵,去河邊找鬼竖般。 笑死,一個胖子當著我的面吹牛茶鹃,可吹牛的內(nèi)容都是我干的涣雕。 我是一名探鬼主播艰亮,決...
    沈念sama閱讀 40,447評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼挣郭!你這毒婦竟也來了迄埃?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,349評論 0 276
  • 序言:老撾萬榮一對情侶失蹤兑障,失蹤者是張志新(化名)和其女友劉穎侄非,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體旺垒,經(jīng)...
    沈念sama閱讀 45,820評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡彩库,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,990評論 3 337
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了先蒋。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片骇钦。...
    茶點故事閱讀 40,127評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖眯搭,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情业岁,我是刑警寧澤,帶...
    沈念sama閱讀 35,812評論 5 346
  • 正文 年R本政府宣布棍好,位于F島的核電站,受9級特大地震影響允耿,放射性物質(zhì)發(fā)生泄漏借笙。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,471評論 3 331
  • 文/蒙蒙 一业稼、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧蚂蕴,春花似錦、人聲如沸骡楼。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,017評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽鸟整。三九已至跨嘉,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間祠乃,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,142評論 1 272
  • 我被黑心中介騙來泰國打工亮瓷, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人嘱支。 一個月前我還...
    沈念sama閱讀 48,388評論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像沛膳,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子汛聚,可洞房花燭夜當晚...
    茶點故事閱讀 45,066評論 2 355