filebeat+redis+logstash+els集群+kibana完成搜索过程

1.实验环境:

  使用8台CentOS主机,实现filebeat+redis+logstash+els集群(3台)+kibana来完成搜索日志相关内容,目标:filebeat来完成收集本机http数据,收集完成后发送给redis,redis主要是来避免数据量过大,logstash处理不过来,logstash是用来格式化数据,将收集来的数据格式化成指定格式,els集群是将格式化完成的数据,进行文档分析,,构建索引,提供查询等操作,kibana提供图形化界面查询的组件
逻辑拓扑图


逻辑拓扑图.png

2.实验步骤

本实验所用的四个软件包全部都是5.6版本
下载相关网站:https://www.elastic.co/cn/products
配置前注意事项:1.关闭防火墙。2.关闭SELinux。3.同步时间
步骤1.实现收集httpd服务的日志文件,并将数据发送给redis服务
http+filebeat服务器相关配置

[root@filebeat ~]# yum install -y httpd
[root@filebeat ~]# echo test > /var/www/html/index.html
[root@filebeat ~]# systemctl start httpd
[root@filebeat ~]# rpm -ivh filebeat-5.6.10-x86_64.rpm
相关配置文件
/etc/filebeat/filebeat.full.yml  #模板配置文件
/etc/filebeat/filebeat.yml 主配置文件
配置redis需要从模板文件中将模板复制到主配置文件中
output.redis:
  enabled: true   #开启
  hosts: ["172.18.100.2:6379"] #redis服务器
  port: 6379 
  key: filebeat  #key的名字
  password:  centos #密码若没有设置则不用填
  db: 0 #写入哪个数据库
  datatype: list  #数据类型
  worker: 1  #开几个进行写数据
  loadbalance: true  #是否支持将多个redis中写入
[root@filebeat ~]# systemctl start filebeat

redis相关配置

[root@redis ~]# yum install -y redis
[root@redis ~]# vim /etc/redis.conf
bind 0.0.0.0
port 6379
requirepass centos
[root@nginx1 ~]# systemctl start redis
增加访问日志,在redis中查询
[root@nginx1 ~]# redis-cli -a centos
127.0.0.1:6379> KEYS *
1) "filebeat"   #即可验证成功

步骤2配置logstash从redis中拿数据,并且格式化,然后存入elasticsearch,并且显示
logstash相关配置,配置该服务之前需要安装JVM相关组件

[root@nginx2 ~]# rpm -ivh logstash-5.6.10.rpm
[root@nginx2 ~]# cd /etc/logstash/conf.d/
[root@nginx2 conf.d]# vim redis-logstash-els.conf  #创建文件,只要以.conf结尾即可
input {
        redis {
                batch_count => 1
                data_type => "list"
                key => "filebeat"
                host => "172.18.100.2"
                port => 6379
                password => "centos"
                threads => 5
        }
}
filter {
        grok {
                match => {
                        "message" => "%{HTTPD_COMBINEDLOG}"
                }
                        remove_field => "message"
        }
        date {
                match => ["timestamp","dd/MM/YYYY:H:m:s Z"]
                remove_field => "timestamp"
        }

}
output {
        stdout {
                codec => rubydebug
        }
}
在终端显示格式化好的内容
[root@nginx2 conf.d]# /usr/share/logstash/bin/logstash -f redis-logstash-els.conf
{
        "request" => "/",
          "agent" => "\"curl/7.29.0\"",
         "offset" => 93516,
           "auth" => "-",
          "ident" => "-",
     "input_type" => "log",
           "verb" => "GET",
         "source" => "/var/log/httpd/access_log",
           "type" => "log",
           "tags" => [
        [0] "_dateparsefailure"
    ],
       "referrer" => "\"-\"",
     "@timestamp" => 2018-06-20T15:21:20.094Z,
       "response" => "200",
          "bytes" => "5",
       "clientip" => "127.0.0.1",
           "beat" => {
            "name" => "filebeat.test.com",
        "hostname" => "filebeat.test.com",
         "version" => "5.6.10"
    },
       "@version" => "1",
    "httpversion" => "1.1",
      "timestamp" => "20/Jun/2018:11:21:19 -0400"
}
将output修改成传递给els集群
output {
        elasticsearch {
                hosts => ["http://172.18.100.4:9200/","http://172.18.100.5:9200/","http://172.18.100.6:9200/"]
                index => "logstash-%{+YYYY.MM.dd}"
                document_type => "apache_logs"
        }
}


检查没有错误即可
[root@nginx2 conf.d]# /usr/share/logstash/bin/logstash -f redis-logstash-els.conf  -t
WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults
Could not find log4j2 configuration at path /usr/share/logstash/config/log4j2.properties. Using default config which logs errors to the console
Configuration OK

步骤3配置els集群服务,需要先安装JVM服务
节点1:

[root@tomcat1 ~]# rpm -ivh elasticsearch-5.6.10.rpm
[root@els1 ~]# vim /etc/elasticsearch/elasticsearch.yml
cluster.name: myels
node.name: els.test.com
network.host: 172.18.100.4
http.port: 9200
discovery.zen.ping.unicast.hosts: ["172.18.100.4", "172.18.100.5","172.18.100.6"]
discovery.zen.minimum_master_nodes: 2

节点2:

[root@tomcat1 ~]# rpm -ivh elasticsearch-5.6.10.rpm
[root@els1 ~]# vim /etc/elasticsearch/elasticsearch.yml
cluster.name: myels
node.name: els.test.com
network.host: 172.18.100.5
http.port: 9200
discovery.zen.ping.unicast.hosts: ["172.18.100.4", "172.18.100.5","172.18.100.6"]
discovery.zen.minimum_master_nodes: 2

节点3:

[root@tomcat1 ~]# rpm -ivh elasticsearch-5.6.10.rpm
[root@els1 ~]# vim /etc/elasticsearch/elasticsearch.yml
cluster.name: myels
node.name: els.test.com
network.host: 172.18.100.6
http.port: 9200
discovery.zen.ping.unicast.hosts: ["172.18.100.4", "172.18.100.5","172.18.100.6"]
discovery.zen.minimum_master_nodes: 2

在els任意一个节点上查看数据

[root@els1 ~]# curl -XGET 'http://172.18.100.4:9200/logstash-2018.06.21?pretty=true'  显示传过来的数据
    "settings" : {
      "index" : {
        "refresh_interval" : "5s",
        "number_of_shards" : "5",
        "provided_name" : "logstash-2018.06.21",
        "creation_date" : "1529545212157",
        "number_of_replicas" : "1",
        "uuid" : "3n74gNpCQUyCLq58vAwL6A",
        "version" : {
          "created" : "5061099"
        }
      }
    }
  }
}

步骤4:配置Nginx反向代理,若其中有一个故障,还可以

[root@mysql1 ~]# yum install -y nginx
[root@mysql1 ~]# vim /etc/nginx/conf.d/test.conf
upstream ser {
        server 172.18.100.4:9200;
        server 172.18.100.5:9200;
        server 172.18.100.6:9200;
}
server {
        listen 80;
        server_name www.test.com;
        root /app/;
        index index.html;
        location / {
                proxy_pass http://ser;
        }
}

步骤5:配置kibana实现图形化查看

server.host: "0.0.0.0"
server.basePath: ""
server.name: "172.18.100.8"
elasticsearch.url: "http://172.18.100.7:80"  #反向代理服务器
elasticsearch.preserveHost: true
kibana.index: ".kibana"

image.png

image.png
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,509评论 6 504
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,806评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,875评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,441评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,488评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,365评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,190评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,062评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,500评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,706评论 3 335
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,834评论 1 347
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,559评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,167评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,779评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,912评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,958评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,779评论 2 354

推荐阅读更多精彩内容