一.配置nginx

[root@linux-node1 ~]# vim /etc/nginx/nginx.conf
#修改日志格式为json格式,并创建一个nginxweb的网站目录
log_format access_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",'
'"domain":"$host",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"status":"$status"}';
access_log /var/log/nginx/access.log access_json; location /nginxweb {
root html;
index index.html index.htm;
}
[root@linux-node1 ~]# mkdir /usr/share/nginx/html/nginxweb
[root@linux-node1 ~]# echo "<h1> welcome to use Nginx" > /usr/share/nginx/html/nginxweb/index.html
[root@linux-node1 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@linux-node1 ~]# systemctl start nginx

 

二、配置logstash

# vim /etc/logstash/conf.d/nginxlog.conf
input{
file {
path => "/var/log/nginx/access.log"
type => "nginx-access-log"
start_position => "beginning"
stat_interval => "2"
} } output{
elasticsearch {
hosts => ["10.0.0.22:9200"]
index => "logstash-nginx-access-log-%{+YYYY.MM.dd}"
}
}

三、Kibana展示

[[root@saltstack02 ~]# ab -n1000 -c 100 http://10.0.0.22/nginxweb/index.html    #对页面压测

[root@saltstack02 conf.d]# tailf /var/log/nginx/access.log    #nginx的访问日志变成了json格式
{"@timestamp":"2018-06-20T19:14:30+08:00","host":"10.0.0.22","clientip":"10.0.0.22","size":26,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"10.0.0.22","url":"/nginxweb/index.html","domain":"10.0.0.22","xff":"-","referer":"-","status":"200"}
{"@timestamp":"2018-06-20T19:14:30+08:00","host":"10.0.0.22","clientip":"10.0.0.22","size":26,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"10.0.0.22","url":"/nginxweb/index.html","domain":"10.0.0.22","xff":"-","referer":"-","status":"200"}
{"@timestamp":"2018-06-22T09:10:42+08:00","host":"10.0.0.22","clientip":"10.0.0.1","size":26,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"10.0.0.22","url":"/nginxweb/index.html","domain":"10.0.0.22","xff":"-","referer":"-","status":"200"}

Head插件查看:

  

  

 

最新文章

  1. django 模板语法和三种返回方式
  2. MySQL数据库“局部”乱码
  3. CCNA基础 IP地址子网划分
  4. HDU 5791 Two DP
  5. js中数组
  6. 图论(二分图,KM算法):HDU 3488 Tour
  7. 浅谈js闭包
  8. 查看登录用户who
  9. Effective C++:规定20: 宁pass-by-reference-to-const更换pass-by-value
  10. linux下合并pdf
  11. gulp总结
  12. 【UVA 11426】gcd之和 (改编)
  13. SQL自动生成java实体类POJO
  14. nginx平滑升级(1.14--1.15)
  15. ERRORS: ?: (staticfiles.E002) The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.
  16. P5205 【模板】多项式开根
  17. DSP2812&#160; 启动详解
  18. [NOIp2007提高组]矩阵取数游戏
  19. php远程获取图片或文件信息(get_headers,fsocketopen,curl)
  20. 浅谈padding

热门文章

  1. MongoDB 之 aggregate $group 巧妙运用
  2. 谈谈Flash图表中数据的采集
  3. C语言的内存对齐
  4. CodeForces 816C 思维
  5. 1.phpcms 伪静态
  6. Django认证系统实现的web页面
  7. Chapter 4 深入理解Caffe MNIST DEMO中的LeNet网络模型
  8. linux nginx大量TIME_WAIT的解决办法--转
  9. CentOS_5.5_安装GCC编译LiME
  10. Wannacry样本取证特征与清除