elk实战分析nginx日志文档

架构:
  kibana <--- es-cluster <--- logstash <--- filebeat

环境准备:
192.168.3.1 node1 node1.xkops.com 内存2G
192.168.3.2 node2 node2.xkops.com
192.168.3.3 node3 node3.xkops.com

---------------elasticserach安装部分----------------
1.在node1|node2上安装jdk,安装elasticsearch并配置集群。
node1:
①.安装jdk1.8_65
[root@node1 ~]# rpm -ivh jdk-8u65-linux-x64.rpm
②.下载安装elasticsearch,并设置开启自启动。
[root@node1 ~]# wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.3.4/elasticsearch-2.3.4.rpm
[root@node1 ~]# rpm -ivh elasticsearch-2.3.4.rpm
[root@node1 ~]# chkconfig --add elasticsearch
③.修改配置文件,并启动服务。
[root@node1 ~]# grep -Ev "^#|^$" /etc/elasticsearch/elasticsearch.yml
cluster.name: elk-xkops
node.name: node-1
network.host: 192.168.3.1
http.port: 9200
discovery.zen.ping.unicast.hosts: ["node2"]
[root@node1 ~]# service elasticsearch start
node2:
①.安装jdk1.8_65
[root@node2 ~]# rpm -ivh jdk-8u65-linux-x64.rpm
②.下载安装elasticsearch,并设置开启自启动。
[root@node2 ~]# wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.3.4/elasticsearch-2.3.4.rpm
[root@node2 ~]# rpm -ivh elasticsearch-2.3.4.rpm
[root@node2 ~]# chkconfig --add elasticsearch
③.修改配置文件,并启动服务。
[root@node2 ~]# grep -Ev "^#|^$" /etc/elasticsearch/elasticsearch.yml
cluster.name: elk-xkops
node.name: node-1
network.host: 192.168.3.2
discovery.zen.ping.unicast.hosts: ["node1"]
[root@node2 ~]# service elasticsearch start
*此时集群配置完成。

2.elasticsearch常用插件安装:
只需在node1(master)上安装即可:
在线安装:
①.安装head插件。
[root@node1 ~]# /usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head
②.安装bigdesk插件。
[root@node1 ~]# /usr/share/elasticsearch/bin/plugin install hlstudio/bigdesk
③.安装kopf插件。
[root@node1 ~]# /usr/share/elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf
离线安装:
①.安装head插件。
[root@node1 ~]# /usr/share/elasticsearch/bin/plugin install file:/elk/soft/elasticsearch-head-master.zip
②.安装bigdesk插件。
[root@node1 ~]# /usr/share/elasticsearch/bin/plugin install file:/elk/soft/bigdesk-master.zip
③.安装kopf插件。
[root@node1 ~]# /usr/share/elasticsearch/bin/plugin install file:/elk/soft/elasticsearch-kopf-master.zip
浏览器端访问插件:
http://192.168.3.1:9200/_plugin/head
http://192.168.3.1:9200/_plugin/bigdesk
http://192.168.3.1:9200/_plugin/kopf

---------------logstash安装部分----------------
1.在node1上安装logstash。(需要jdk,已经安装)
[root@node1 ~]# wget https://download.elastic.co/logstash/logstash/packages/centos/logstash-2.3.4-1.noarch.rpm
[root@node1 ~]# rpm -ivh logstash-2.3.4-1.noarch.rpm

2.编辑配置文件
[root@node1 ~]# cat /etc/logstash/conf.d/logstash.conf

input {
beats {
port =>
codec => "json"
}
}
filter{
if [type] == "nginx"{
date{
locale => "en"
match => ["@timestamp", "UNIX_MS"]
target => "@timestamp"
}}
}
output{
if [type] == "nginx"{
elasticsearch {
hosts => ["192.168.3.1:9200"]
index => "nginx-%{+YYYY.MM.dd}"
flush_size =>
idle_flush_time =>
}}
}

3.启动logstash服务
[root@node1 ~]# service logstash start

---------------kibana安装部分----------------
1.在node1上安装kibana
[root@node1 ~]# wget https://download.elastic.co/kibana/kibana/kibana-4.5.2-1.x86_64.rpm
[root@node1 ~]# rpm -ivh kibana-4.5.2-1.x86_64.rpm

2.配置kibana连接elasticsearch。
[root@node1 ~]# grep -Ev "^#|^$" /opt/kibana/config/kibana.yml
server.port: 5601
server.host: "192.168.3.1"
elasticsearch.url: "http://192.168.3.1:9200"
elasticsearch.preserveHost: true
kibana.index: ".kibana"
kibana.defaultAppId: "discover"
elasticsearch.requestTimeout: 30000
elasticsearch.shardTimeout: 0
elasticsearch.startupTimeout: 5000

3.启动kibana服务
[root@node1 ~]# service kibana start

----------------nginx安装部分-----------------
1.安装nginx和httpd-tools工具包。
[root@node1 ~]# yum -y install nginx httpd-tools
2.添加访问kibana的用户,并设置密码。
[root@node1 ~]# htpasswd -c /etc/nginx/htpasswd.users kibanaadmin
3.反向代理kibana服务,配置文件如下:
[root@node1 ~]# cat /etc/nginx/conf.d/kibana.conf

server {
listen ; server_name elk.xkops.com; auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/htpasswd.users; location / {
proxy_pass http://192.168.3.1:5601;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

4.浏览器访问
http://elk.xkops.com

----------------filebeat安装部分-----------------
1.在node3上安装filebeat。
下载官方示例数据(nginx日志):
[root@node3 ~]# wget https://download.elastic.co/demos/kibana/gettingstarted/logs.jsonl.gz

下载软件包:
[root@node3 ~]# wget https://download.elastic.co/beats/filebeat/filebeat-1.2.3-x86_64.rpm
[root@node3 ~]# rpm -ivh /elk/filebeat-1.2.3-x86_64.rpm

2.编辑filebeat配置文件。
*提示:修改logs.jsonl文件内容,取其中偶数行。(sed)
sed -n 'n;p' logs.jsonl >> nginx.log 或者sed -n '2~2p' logs.jsonl >> nginx.log

[root@node3 ~]# grep -Ev "#|^$" /etc/filebeat/filebeat.yml

filebeat:
prospectors:
-
paths:
- /root/nginx.json
document_type: nginx registry_file: /var/lib/filebeat/registry
output:
logstash:
hosts: ["192.168.3.1:5044"]
shipper:
logging:
files:

3.创建mapping映射。
[root@node3 ~]# curl -XPOST 'http://192.168.3.1:9200/_template/filebeat?pretty' -d@/etc/filebeat/filebeat.template.json

4.启动filebeat服务。
[root@node3 ~]# service filebeat start

至此,整个elk搭建完成,可以在kibana展示端进行各种操作,比如检索日志,制作各种展示图表了。

elk实战分析nginx日志文档的更多相关文章

  1. elk平台分析nginx日志的基本搭建

    一.elk套件介绍 ELK 由 ElasticSearch . Logstash 和 Kiabana 三个开源工具组成.官方网站: https://www.elastic.co/products El ...

  2. elk 入门 - 分析nginx日志 + json格式 + 有调试的意识 + elk7.2.0

    1.本次采用的一台主机,将所有的软件安装一台上进行测试工作. 2.安装部署:https://blog.51cto.com/hwg1227/2299995 3.简单调试 输出rubydebug inpu ...

  3. elk收集分析nginx access日志

    elk收集分析nginx access日志 首先elk的搭建按照这篇文章使用elk+redis搭建nginx日志分析平台说的,使用redis的push和pop做队列,然后有个logstash_inde ...

  4. 使用elk+redis搭建nginx日志分析平台

    elk+redis 搭建nginx日志分析平台 logstash,elasticsearch,kibana 怎么进行nginx的日志分析呢?首先,架构方面,nginx是有日志文件的,它的每个请求的状态 ...

  5. 使用Docker快速部署ELK分析Nginx日志实践

    原文:使用Docker快速部署ELK分析Nginx日志实践 一.背景 笔者所在项目组的项目由多个子项目所组成,每一个子项目都存在一定的日志,有时候想排查一些问题,需要到各个地方去查看,极为不方便,此前 ...

  6. 使用elk+redis搭建nginx日志分析平台(引)

    http://www.cnblogs.com/yjf512/p/4199105.html elk+redis 搭建nginx日志分析平台 logstash,elasticsearch,kibana 怎 ...

  7. ELK+redis搭建nginx日志分析平台

    ELK+redis搭建nginx日志分析平台发表于 2015-08-19   |   分类于 Linux/Unix   |  ELK简介ELKStack即Elasticsearch + Logstas ...

  8. 使用Docker快速部署ELK分析Nginx日志实践(二)

    Kibana汉化使用中文界面实践 一.背景 笔者在上一篇文章使用Docker快速部署ELK分析Nginx日志实践当中有提到如何快速搭建ELK分析Nginx日志,但是这只是第一步,后面还有很多仪表盘需要 ...

  9. ELK+Redis 解析Nginx日志

    一.ELK简介 Elk是指logstash,elasticsearch,kibana三件套,我们一般使用它们做日志分析. ELK工作原理图: 简单来讲ELK具体的工作流程就是客户端的logstash ...

随机推荐

  1. df卡住问题解决

    windows的share文件挂载到linux/mnt/share下,当windows重启,会导致df卡住. 运行           1 umount -l /mnt/share 2 killall ...

  2. HDU-统计难题

    DescriptionIgnatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). Inp ...

  3. Code[VS] 2370 LCA 题解

    Code[VS] 2370 小机房的树 题解 RMQ 树链剖分 题目描述 Description 小机房有棵焕狗种的树,树上有N个节点,节点标号为0到N-1,有两只虫子名叫飘狗和大吉狗,分居在两个不同 ...

  4. hbase的查询scan功能注意点(setStartRow, setStopRow)

    来自http://hi.baidu.com/7636553/blog/item/982beb17713bc004972b43ee.html hbase的scan查询功能注意项: Scan scan = ...

  5. LongListSelector with bindable SelectedItem

    using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using Microso ...

  6. 【BUG】wego购物分享系统未登陆分享宝贝时查看宝贝自动新增产品数据

    1.登录微购http://demo.wego360.com/站. 2.分享宝贝功能检索第三方平台商品数据. 1.登录微购http://demo.wego360.com/站. 2.分享宝贝功能检索第三方 ...

  7. linux下获取本机IP

    转载:http://blog.chinaunix.net/uid-20593763-id-1620213.html 源代码级Unix/Linux 通用网卡IP地址获取方法 在Unix和Linux系统下 ...

  8. Android官方提供的下拉刷新控件——SwipeRefreshLayout

    <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q ...

  9. Java 中的 Characters

    1.一般情况下,如果使用单一的 character 值,应该使用原始的 char 类型.比如: public class TestCharacter { public static void main ...

  10. intellij idea 插件 ideaVim

    像Eclipse一样,idea这个公认最好的javaIDE也有Vim插件. 安装方法 File>Settings>Plugins>Install JetBrains plugin.. ...