ELK——FileBeat配置ngnix log改为解析Json

FileBeat的版本为7.3.2,版本不同添加的参数不同!!!

第一步:改Ngnix
编辑ngnix.conf文件,在http模块下如下添加

http {

  include       mime.types;
    default_type  application/octet-stream;
	
	#这里是默认给的示例
    #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  logs/access.log  main;

    #z这里默认的是main
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" '
                                          '$http_host '
                      ' $upstream_response_time  $request_time  $upstream_addr ';
     #在此处添加                 
    log_format  log_json  '{"@timestamp": "$time_local","user_ip":"$http_x_real_ip","lan_ip":"$remote_addr","log_time":"$time_iso8601","user_req":"$request","http_code":"$status","body_bytes_sents":"$body_bytes_sent","req_time":"$request_time","user_ua":"$http_user_agent"}';
    
     #最后指定log文件输出的类型为上方添加的log_json
     access_log  /var/log/nginx/access.log  log_json;

#下面的http模块的其它配置不做展示
...

然后可以重启ngnix验证日志是否改为了json.

./nginx -s reload

在这里插入图片描述
第二步:修改FileBeat
接着修改FileBeat的配置文件filebeat.yml

#=========================== Filebeat inputs =============================

filebeat.inputs:

# Each - is an input. Most options can be set at the input level, so
# you can use different inputs for various configurations.
# Below are the input specific configurations.

- 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.log  #指定监听的日志
    #- c:\programdata\elasticsearch\logs\*
  #主要是添加下方三个配置,记得和上方的paths对其(它们属于同级)
  json.keys_under_root: true
  json.add_error_key: true
  json.message_key: log

最后重启FileBeat,去ES插件上查看log日志是否已经为json
在这里插入图片描述
更改完成!
FileBeat的版本为7.3.2,版本不同添加的参数不同!!!

ELK是一个常用的日志分析系统,其中E代表Elasticsearch搜索引擎,L代表Logstash日志收集和处理工具,K代表Kibana可视化工具。filebeat是一个轻量级的日志收集器,可以将日志发送到ELK中进行分析。 以下是在Linux系统上配置ELKfilebeat的步骤: 1. 安装Java运行环境 ELK需要Java环境来运行,可以通过以下命令安装OpenJDK 8: ``` sudo apt-get update sudo apt-get install openjdk-8-jdk ``` 2. 安装Elasticsearch Elasticsearch是ELK系统的核心组件,可以通过以下命令安装: ``` wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - sudo apt-get install apt-transport-https echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list sudo apt-get update sudo apt-get install elasticsearch ``` 安装完成后,通过以下命令启动Elasticsearch: ``` sudo systemctl start elasticsearch ``` 3. 安装Logstash Logstash用于将日志收集到Elasticsearch中进行分析,可以通过以下命令安装: ``` sudo apt-get install logstash ``` 安装完成后,可以通过以下命令启动Logstash: ``` sudo systemctl start logstash ``` 4. 安装Kibana Kibana用于可视化Elasticsearch中的日志数据,可以通过以下命令安装: ``` sudo apt-get install kibana ``` 安装完成后,可以通过以下命令启动Kibana: ``` sudo systemctl start kibana ``` 5. 配置filebeat filebeat用于将日志发送到ELK中进行分析,可以通过以下命令安装: ``` curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.6.2-linux-x86_64.tar.gz tar xzvf filebeat-7.6.2-linux-x86_64.tar.gz cd filebeat-7.6.2-linux-x86_64/ ``` 配置filebeat,可以编辑filebeat.yml文件: ``` filebeat.inputs: - type: log enabled: true paths: - /var/log/*.log output.elasticsearch: hosts: ["localhost:9200"] username: "elastic" password: "changeme" ``` 以上配置表示收集/var/log目录下的所有日志,并将其发送到Elasticsearch中。 启动filebeat: ``` sudo ./filebeat -e ``` 以上是在Linux系统上配置ELKfilebeat的步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值