環境:
192.168.10.129
安裝ES 9200,kibana:5601
192.168.10.131
安裝了logstash:9600
登錄到131上
[root@localhost patterns]# pwd
/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-patterns-core-4.1.2/patterns
將創建好的nginx_access文件上傳至這個目錄下
vim nginx_access
URIPARAM1 [A-Za-z0-9$.+!*'|(){},~@#%&/=:;_?\-\[\]]*
NGINXACCESS %{IPORHOST:client_ip} (%{USER:ident}|- ) (%{USER:auth}|-) \[%{HTTPDATE:timestamp}\] "(?:%{WORD:verb} (%{NOTSPACE:request}|-)(?: HTTP/%{NUMBER:http_version})?|-)" %{NUMBER:status} (?:%{NUMBER:bytes}|-) "(?:%{URI:referrer}|-)" "%{GREEDYDATA:agent}"
添加logstash的nginx 日志收集配置文件
logstash grok 內置正則:https://github.com/logstash-plugins/logstash-patterns-core/blob/master/patterns/grok-patterns
vim /etc/logstash/conf.d/nginx.conf
input {
file {
path => "/usr/local/nginx/logs/access.log"
type => "nginx-log"
start_position => "beginning"
}
}
filter {
grok {
match => { "message" => "%{NGINXACCESS}" }
}
}
output {
elasticsearch {
hosts => ["192.168.10.129:9200"]
index => "nginx_log-%{+YYYY.MM.dd}"
}
}
注意:如果你的log放在/var/log下請給chmod 777 /var/log -R
添加nginx日志的可視化圖形
1 添加狀態碼統計餅狀圖






2 添加一個統計pv的圖形



3 添加ip訪問量前10的ip



4 訪問量趨勢圖



5 添加一個儀表盤




沒有nginx 索引需注意以下幾點:
1:chmod 777 /var/log/nginx -R
2: pipiline.yml 文件
3:nginx log 里要有內容 可以用ab壓測用具生成一些日志
