题外内容:

因本IIS服务器经过硬件负载均衡进行代理转,导致IIS无法直接识别出外部客户端IP地址,因此需要安装x_forward_for功能用于识别,参考如下文章:https://blog.csdn.net/hzfw2008/article/details/105066565/

一、Windows下载安装Logstash

下载地址:https://www.elastic.co/cn/downloads/logstash image.png 备注:下载解压后,即可直接使用,不需要额外安装JAVA

二、设置IIS的格式输出

image.png image.png image.png image.png

三、IIS输出的日志内容

2021-09-18 00:01:55 10.224.48.91 GET /news_d.aspx 220.181.108.83 3ww.junhua.net 200 35

四、Logstash解释IIS配置文件

input {
    file {
        path => ["C:/inetpub/logs/wmsvc/W3SVC2/*.log"]
        type => "web-iis"
    }
}
filter {
    grok {
        match => ["message", "%{TIMESTAMP_ISO8601:log_timestamp} %{IPORHOST:serverip} %{WORD:method} %{URIPATH:page} %{IPORHOST:clientip} %{NUMBER:status} %{NUMBER:respone_time}"]
    }
    geoip {
                source => "clientip"
                target => "geoip"
                add_field => ["[geoip][coordinates]","%{[geoip][longitude]}"]
                add_field => ["[geoip][coordinates]","%{[geoip][latitude]}"]
        }
}
output {
    elasticsearch {
        user => "elastic"
        password => "password"
        hosts => ["http://10.224.14.14:9200","http://10.224.14.15:9200","http://10.224.14.16:9200"]
        index => "logstash-%{type}-%{+YYYY.MM.dd}"
    }
}

五、logstash运行方式

image.png

六、Kibana展示效果

image.png