赞
踩
在原有的ELK基础:
安装nginx服务:
# yum install epel-release
# yum install nginx
开启nginx服务:
# systemctl enable nginx
# systemctl start nginx
验证:
# netstat -lptnu|grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 73887/nginx: master
tcp6 0 0 :::80 :::* LISTEN 73887/nginx: master
安装ab压测工具,生成测试数据:
# yum install httpd-tools
ab -n 1000 -c 1000 http://192.168.191.131/index.html
-n:请求数
-c:并发数
注意:并发数不能大于请求数!!
编辑nginx.conf:
# vim nginx.conf input { file { path => "/var/log/nginx/access.log" type => "nginx-log" start_position => "beginning" } } filter { grok { match => {"message" => "%{NGX}"} } } output{ elasticsearch { hosts => "192.168.191.130:9200" index => "nginx_log-%{+YYYY.MM.dd}" } }
修改配置文件:
# vim pipelines.yml
- pipeline.id: nginx
path.config: "/etc/logstash/conf.d/nginx.conf"
验证index是否创建成功!
方法1:tailf /var/log/elasticsearch/wg007.log
方法2;url -X GET http://192.168.191.130:9200/_cat/indices?v
如果index没有创建成功,需要做:
1:chmod 777 /var/log -R
2: ab命令压测nginx服务,生成测试数据。
编辑"%{NGX} 匹配模式:
# vim /usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/logstash-patterns-core-4.1.2/patterns/nginx
NGX %{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}"
可视化操作:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。