当前位置: 首页 > news >正文

Elastic+logstash+filebeat做Nginx日志分析

一、Elasticserach安装
1、Installation(elastic 6.3.2 版本 依赖 java JDK8)

下载合适的版本:
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.0.tar.gz
tar -xvf elasticsearch-6.4.0.tar.gz
cd elasticsearch-6.4.0/bin
./elasticsearch

2、集群健康检查
curl -XGET http://127.0.0.1:9200/_cat/health?v 集群健康查看
curl -XGET http://127.0.0.1:9200/_cat/nodes?v 节点状态查看
curl -XGET http://127.0.0.1:9200/_cat/indices?v 查看索引
curl -XPUT http://127.0.0.1:9200/customer?pretty 添加customer索引
curl -XDELETE http://127.0.0.1:9200/customer?pretty 删除索引

3、Config
cluster.name: 集群名
node.name: 节点名
path.data: 数据存储路径
path.logs: 日志存储路径
network.host: 监听地址
http.port: 监听端口
JVM 配置、logging配置 参考官方文档
重要参数:

Path settings
Cluster name
Node name
Network host
Discovery settings
Heap size
Heap dump path
GC logging
Temp directory
重要的系统参数:

Disable swapping
Increase file descriptors
Ensure sufficient virtual memory
Ensure sufficient threads
JVM DNS cache settings

4、Running as daemon
./bin/elasticsearch -d -p pid 启动
kill cat pid 停止

5、Set up X-Pack
参考x-pack破解方法

二、kibana安装及配置

        wget https://artifacts.elastic.co/downloads/kibana/kibana-6.4.0-linux-x86_64.tar.gz

tar -xzf kibana-6.4.0-linux-x86_64.tar.gz
cd kibana-6.4.0-linux-x86_64/

        1、启动  ./bin/kibana   

        2、config:

server.port: 5601
server.host: "192.168.12.81"
kibana.index: ".kibana"
elasticsearch.username: "elastic"
elasticsearch.password: "dinpay"

三、logstash安装及配置
wget https://artifacts.elastic.co/downloads/logstash/logstash-6.4.0.tar.gz

配置 filebeat 收集Nginx日志: (Nginx.conf)

input {
beats {
port => 5044
codec => "json"
}
}

output {
elasticsearch {
hosts => ["127.0.0.1:9200"]
index => "test1-nginx-access-%{+YYYY.MM.dd}"
template_overwrite => true
user => elastic
password => dinpay
}
}

配置logstash.yml elastic安装在本机(没有配置https)

xpack.monitoring.enabled: true
xpack.monitoring.elasticsearch.username: elastic
xpack.monitoring.elasticsearch.password: dinpay
xpack.monitoring.elasticsearch.url: ["http://127.0.0.1:9200"]

四、filebeat安装及配置

wget https://artifacts.elastic.co/downloads/beats/filebeat/https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.4.0-linux-x86_64.tar.gz

tar -xf filebeat-6.4.0-linux-x86_64.tar.gz

cd filebeat-6.4.0-linux-x86_64

配置 filebeat.yml

  • type: log
    paths:

    • /var/log/nginx/access.log

output.logstash:

hosts: ["192.168.12.81:5044"]

xpack.monitoring:
enabled: true
elasticsearch:
hosts: ["http://192.168.12.81:9200", "http://192.168.12.81:9200"]
username: elastic
password: dinpay

五、Nginx 日志格式配置:

log_format json '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$clientRealIp",'
'"remote_user":"$remote_user",'
'"request":"$request",'
'"http_user_agent":"$http_user_agent",'
'"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",'
'"ss":"$upstream_status"}';

access_log  /var/log/nginx/access.log  json;

map $http_x_forwarded_for $clientRealIp {

""  $remote_addr;

~^(?P<firstAddr>[0-9\.]+),?.*$    $firstAddr;

}

转载于:https://blog.51cto.com/hjt353/2174863

相关文章:

  • Python全栈 Web(JavaScript DOM树、DOM对象、BOM对象)
  • 分布式事务柔性事务解决方案:可靠消息最终一致性(异步确保型) —— 三、生产者实战...
  • MVC过滤器详解
  • 利用ZYNQ SOC快速打开算法验证通路(6)——利用AXI总线实时配置sysGen子系统
  • 【亲测】教你如何搭建 MongoDB 复制集 + 选举原理
  • Python中For循环
  • Linux文件系统分层标准(FHS)
  • 单元测试/部署
  • 手写一个WPF-MVVM
  • 基于lfslivecd-x86-6.3-r2145安装vnc和qemu
  • elementUI树形菜单获取每一级菜单的值
  • window下启动Redis闪退问题解决
  • 安卓投屏助手(B1358)之辅助调试
  • 小程序各种功能代码片段整理---持续更新
  • Educational Codeforces Round 51 (Rated for Div. 2)
  • 【翻译】babel对TC39装饰器草案的实现
  • 03Go 类型总结
  • 0基础学习移动端适配
  • 10个确保微服务与容器安全的最佳实践
  • 2017 年终总结 —— 在路上
  • 2017-09-12 前端日报
  • ECMAScript 6 学习之路 ( 四 ) String 字符串扩展
  • in typeof instanceof ===这些运算符有什么作用
  • Java小白进阶笔记(3)-初级面向对象
  • JS字符串转数字方法总结
  • leetcode386. Lexicographical Numbers
  • node-sass 安装卡在 node scripts/install.js 解决办法
  • Python3爬取英雄联盟英雄皮肤大图
  • Solarized Scheme
  • Vue ES6 Jade Scss Webpack Gulp
  • vue自定义指令实现v-tap插件
  • 从伪并行的 Python 多线程说起
  • 欢迎参加第二届中国游戏开发者大会
  • 开放才能进步!Angular和Wijmo一起走过的日子
  • 前嗅ForeSpider中数据浏览界面介绍
  • 如何用vue打造一个移动端音乐播放器
  • 写代码的正确姿势
  • 优化 Vue 项目编译文件大小
  • 正则表达式-基础知识Review
  • #define,static,const,三种常量的区别
  • #Spring-boot高级
  • (C语言)求出1,2,5三个数不同个数组合为100的组合个数
  • (翻译)Quartz官方教程——第一课:Quartz入门
  • (附源码)springboot青少年公共卫生教育平台 毕业设计 643214
  • (附源码)SSM环卫人员管理平台 计算机毕设36412
  • (附源码)基于SSM多源异构数据关联技术构建智能校园-计算机毕设 64366
  • (强烈推荐)移动端音视频从零到上手(下)
  • (顺序)容器的好伴侣 --- 容器适配器
  • (译) 函数式 JS #1:简介
  • .bat批处理(七):PC端从手机内复制文件到本地
  • .NET/ASP.NETMVC 深入剖析 Model元数据、HtmlHelper、自定义模板、模板的装饰者模式(二)...
  • .NET/C# 在代码中测量代码执行耗时的建议(比较系统性能计数器和系统时间)
  • [Bugku]密码???[writeup]
  • [C/C++]数据结构 堆的详解
  • [c++] 单例模式 + cyberrt TimingWheel 单例分析