之前发了一个复杂版本的,今天发一个json格式的
ELK最大的难度就是logstash的启动配置文件
各种格式的不适应,总是conf报错
ELK 5.1.1
单机10.130.24.111
---------开发内网
nginx
配置
/usr/local/nginx/conf/nginx.conf
nginx stop:
pkill nginx
/usr/local/nginx/sbin/nginx -s stop
nginx log:
/usr/local/nginx/logs
tail -f /usr/local/nginx/logs/access.log
echo "">/usr/local/nginx/logs/access.log
log_format log_json '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$remote_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"http_host":"$host",'
'"url":"$uri",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"agent":"$http_user_agent",'
'"status":"$status"}';
access_log logs/access_nginx.json log_json;
具体文件见:
链接:https://pan.baidu.com/s/1rnJwuxxadvw9Mzc5EP8TAg
提取码:ksk2
复制这段内容后打开百度网盘手机App,操作更方便哦
---------------------
logstash
logstash
input {
file {
type => "nginx-access"
path => "/usr/local/nginx/logs/access_nginx.json"
start_position => "beginning"
codec => "json"
}
}
filter {
if [type] == "nginx-access"{
geoip {
source => "clientip"
target => "geoip"
database => "/home/elasticresearch/soft/logstash-5.1.1/GeoLite2-City.mmdb"
add_field => ["[geoip][coordinates]", "%{[geoip][longitude]}"]
add_field => ["[geoip][coordinates]", "%{[geoip][latitude]}"]
}
}
}
output {
if [type] == "nginx-access" {
stdout{
codec=>rubydebug
}
elasticsearch {
action => "index"
hosts => "10.130.24.111:9200"
index => "logstash-slow-%{+yyyy.MM.dd}"
}
}
}
/home/elasticresearch/soft/logstash-5.1.1/bin/logstash -f /home/elasticresearch/soft/logstash-5.1.1/nginx_access.conf &
nginx_access.conf见
链接:https://pan.baidu.com/s/1ZjqMJ9mofF7jLSRRh3AT2g
提取码:ur6p
复制这段内容后打开百度网盘手机App,操作更方便哦