20309 发表于 2019-1-28 13:07:18

ELK实时日志分析平台环境部署-2

编辑nginx配置文件,修改以下内容(在http模块下添加)  log_format json '{"@timestamp":"$time_iso8601",'
  '"@version":"1",'
  '"client":"$remote_addr",'
  '"url":"$uri",'
  '"status":"$status",'
  '"domian":"$host",'
  '"host":"$server_addr",'
  '"size":"$body_bytes_sent",'
  '"responsetime":"$request_time",'
  '"referer":"$http_referer",'
  '"ua":"$http_user_agent"'
  '}';
  修改access_log的输出格式为刚才定义的json
  access_loglogs/elk.access.logjson;
  继续修改apache的配置文件
  LogFormat "{ \
  \"@timestamp\": \"%{%Y-%m-%dT%H:%M:%S%z}t\", \
  \"@version\": \"1\", \
  \"tags\":[\"apache\"], \
  \"message\": \"%h %l %u %t \\\"%r\\\" %>s %b\", \
  \"clientip\": \"%a\", \
  \"duration\": %D, \
  \"status\": %>s, \
  \"request\": \"%U%q\", \
  \"urlpath\": \"%U\", \
  \"urlquery\": \"%q\", \
  \"bytes\": %B, \
  \"method\": \"%m\", \
  \"site\": \"%{Host}i\", \
  \"referer\": \"%{Referer}i\", \
  \"useragent\": \"%{User-agent}i\" \
  }" ls_apache_json
  一样修改输出格式为上面定义的json格式
  CustomLog logs/access_log ls_apache_json
  编辑logstash配置文件,进行日志收集
  vim /etc/logstash/conf.d/full.conf
  input {
  file {
  path => "/var/log/messages"
  type => "system"
  start_position => "beginning"
  }
  file {
  path => "/var/log/secure"
  type => "secure"
  start_position => "beginning"
  }
  file {
  path => "/var/log/httpd/access_log"
  type => "http"
  start_position => "beginning"
  }
  file {
  path => "/usr/local/nginx/logs/elk.access.log"
  type => "nginx"
  start_position => "beginning"
  }
  }
  output {    if == "system" {
  elasticsearch {
  hosts => ["192.168.1.202:9200"]
  index => "nagios-system-%{+YYYY.MM.dd}"
  }
  }
  if == "secure" {
  elasticsearch {
  hosts => ["192.168.1.202:9200"]
  index => "nagios-secure-%{+YYYY.MM.dd}"
  }
  }    if == "http" {
  elasticsearch {
  hosts => ["192.168.1.202:9200"]
  index => "nagios-http-%{+YYYY.MM.dd}"
  }
  }    if == "nginx" {
  elasticsearch {
  hosts => ["192.168.1.202:9200"]
  index => "nagios-nginx-%{+YYYY.MM.dd}"
  }
  }
  }
  运行看看效果如何
  logstash -f /etc/logstash/conf.d/full.conf

页: [1]
查看完整版本: ELK实时日志分析平台环境部署-2