ELK收集nginx log(ab压测 可视化)

ELK最基本的搭建,不然这个无法进行操作,这是网址:
https://blog.csdn.net/fenghumen/article/details/109083538

1 在192.168.1.5上安装nginx服务

yum -y install epel-release
yum -y install nginx

2 开启nginx服务

systemctl enable nginx
systemctl start nginx

验证

[[email protected] conf.d]# 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 

3 安装ab压测工具,生成测试数据

yum -y install httpd-tools
ab -n 1000 -c 1000 http://192.168.1.5/index.html

-n:请求数
-c:并发数
注意:并发数不能大于请求数!!

4 编辑nginx.conf

[[email protected] conf.d]# cat nginx.conf 
input {
    
 file {
    
  path => "/var/log/nginx/access.log"
  type => "nginx-log"
  start_position => "beginning"
 }

}
output{
    
 elasticsearch {
    
  hosts => "192.168.1.4:9200"
  index => "nginx_log-%{+YYYY.MM.dd}"
 }
}

[[email protected] logstash]# cat pipelines.yml 
- pipeline.id: nginx
  path.config: "/etc/logstash/conf.d/nginx.conf"

5 验证index是否创建成功!

方法1

tailf /var/log/elasticsearch/wg007.log

方法2

url -X GET http://192.168.1.4:9200/_cat/indices?v 

如果index没有创建成功,需要做:

1.chmod 777 /var/log -R
2.ab命令压测nginx服务,生成测试数据。

6 编辑nginx.conf

添加filter模块

filter {
    
 grok {
    
  match => {
    "message" => "%{NGX}"}
 }
}

7 编辑"%{NGX} 匹配模式

[[email protected] patterns]# pwd
/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/logstash-patterns-core-4.1.2/patterns
[[email protected] patterns]# vim 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}"

8 可视化操作:

1 添加一个状态码统计图

pie--Terms--status.keyword

2 统计nginx的pv,uv

metric

3 统计访问前10的ip地址

Horizontal Bar 直方图

8.4 统计网站访问趋势图

Line

猜你喜欢

转载自blog.csdn.net/fenghumen/article/details/109105424