zoukankan      html  css  js  c++  java
  • elasticSearch插件的安装以及使用nginx的modles收集nginx的日志

    1、首先在windows环境上搭建es的集群

    集群的配置如下

    #node01的配置:
    cluster.name: es-itcast-cluster
    node.name: node01
    node.master: true
    node.data: true
    network.host: 0.0.0.0
    http.port: 9200   
    transport.tcp.port: 9300   
    discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"]
    discovery.zen.minimum_master_nodes: 2
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    #node01的配置:
    cluster.name: es-itcast-cluster
    node.name: node02
    node.master: true
    node.data: true
    network.host: 0.0.0.0
    http.port: 9201  
    transport.tcp.port: 9301   
    discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"]
    discovery.zen.minimum_master_nodes: 2
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    #node01的配置:
    cluster.name: es-itcast-cluster
    node.name: node03
    node.master: true
    node.data: true
    network.host: 0.0.0.0
    http.port: 9202   
    transport.tcp.port: 9302   
    discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"]
    discovery.zen.minimum_master_nodes: 2
    http.cors.enabled: true
    http.cors.allow-origin: "*"

    在linux环境下配置es集群的配置文件为

    ELasticsearch的集群是由多个节点组成的,通过cluster.name设置集群名称,并且用于区分其它的集群,每个节点
    通过node.name指定节点的名称。
    Elasticsearch中,节点的类型主要有4种:
    master节点
    配置文件中node.master属性为true(默认为true),就有资格被选为master节点。
    master节点用于控制整个集群的操作。比如创建或删除索引,管理其它非master节点等。
    data节点
    配置文件中node.data属性为true(默认为true),就有资格被设置成data节点。
    data节点主要用于执行数据相关的操作。比如文档的CRUD
    客户端节点
    配置文件中node.master属性和node.data属性均为false
    北京市昌平区建材城西路金燕龙办公楼一层 电话:400-618-9090
    该节点不能作为master节点,也不能作为data节点。
    可以作为客户端节点,用于响应用户的请求,把请求转发到其他节点
    部落节点
    当一个节点配置tribe.*的时候,它是一个特殊的客户端,它可以连接多个集群,在所有连接的集群上执行
    搜索和其他操作。

    #启动3个虚拟机,分别在3台虚拟机上部署安装Elasticsearch
    mkdir /itcast/es-cluster
    #分发到其它机器
    scp -r es-cluster elsearch@192.168.40.134:/itcast
    #node01的配置:
    cluster.name: es-itcast-cluster
    node.name: node01
    node.master: true
    node.data: true
    network.host: 0.0.0.0
    http.port: 9200
    discovery.zen.ping.unicast.hosts: ["192.168.40.133","192.168.40.134","192.168.40.135"]
    discovery.zen.minimum_master_nodes: 2
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    #node02的配置:
    cluster.name: es-itcast-cluster
    node.name: node02
    node.master: true
    node.data: true
    network.host: 0.0.0.0
    http.port: 9200
    discovery.zen.ping.unicast.hosts: ["192.168.40.133","192.168.40.134","192.168.40.135"]
    discovery.zen.minimum_master_nodes: 2
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    #node03的配置:
    cluster.name: es-itcast-cluster
    node.name: node02
    node.master: true
    node.data: true
    network.host: 0.0.0.0
    http.port: 9200
    discovery.zen.ping.unicast.hosts: ["192.168.40.133","192.168.40.134","192.168.40.135"]
    discovery.zen.minimum_master_nodes: 2
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    #分别启动3个节点
    ./elasticsearch

    特别需要的是下面参数

    特别说明:
    如果在配置文件中discovery.zen.minimum_master_nodes设置的不是N/2+1时,会出现脑裂问题,之前宕机
    的主节点恢复后不会加入到集群。

    接下来我们要安装es的插件:插件一定要和es的版本一致,例如当前es是6.2.4版本,那离线安装插件的版本也必须是6.2.4版本

    接下来我们要安装三个插件analysis-ik、ingest-geoip和ingest-user-agent

    在线安装插件的方式

    sudo bin/elasticsearch-plugin install ingest-user-agent
    sudo bin/elasticsearch-plugin install ingest-geoip

    离线安装的方式:

    下载对应的插件版本,当前es是6.2.4,插件一定要是6.2.4版本,如果是其他版本就会报错

    elasticsearch-plugin install file:C:UsersAdministratorDesktopELKes-clusteringest-geoip-6.2.4.zip

    离线安装ingest-geoip-6.2.4.zip

    4.7Module
    前面要想实现日志数据的读取以及处理都是自己手动配置的,其实,在Filebeat中,有大量的Module,可以简化我
    们的配置,直接就可以使用,如下

    ./filebeat modules list
    Enabled:
    Disabled:
    apache2
    auditd
    elasticsearch
    haproxy
    icinga
    iis
    kafka
    1 2 3 4 5 6 7 8 9
    10
    11
    12
    北京市昌平区建材城西路金燕龙办公楼一层 电话:400-618-9090
    可以看到,内置了很多的module,但是都没有启用,如果需要启用需要进行enable操作:
    可以发现,nginxmodule已经被启用。
    4.7.1nginx module 配置
    kibana
    logstash
    mongodb
    mysql
    nginx
    osquery
    postgresql
    redis
    suricata
    system
    traefik

    可以看到,内置了很多的module,但是都没有启用,如果需要启用需要进行enable操作:
    可以发现,nginxmodule已经被启用

     

    nginx module 配置

    - module: nginx
      # Access logs
      access:
        enabled: true
        var.paths: ["C:/Users/Administrator/Desktop/ELK/nginx-1.15.5/nginx-1.15.5/logs/access.log"]
        # Set custom paths for the log files. If left empty,
        # Filebeat will choose the paths depending on your OS.
        #var.paths:
    
      # Error logs
      error:
        enabled: true
        var.paths: ["C:/Users/Administrator/Desktop/ELK/nginx-1.15.5/nginx-1.15.5/logs/error.log"]
        # Set custom paths for the log files. If left empty,
        # Filebeat will choose the paths depending on your OS.
        #var.paths:

    在这里指定nginx日志的位置

    var.paths: ["C:/Users/Administrator/Desktop/ELK/nginx-1.15.5/nginx-1.15.5/logs/access.log"]

    接下来配置配置filebeat的配置文件

    filebeatwithnginxmoudles.yml

    #============================= Filebeat modules ===============================
    
    filebeat.config.modules:
      # Glob pattern for configuration loading
      path: ${path.config}/modules.d/*.yml
      reload.enabled: true
    setup.template.settings:
      index.number_of_shards: 3
    
    
    setup.kibana:
    
    
    #----------------------------- Logstash output --------------------------------
    output:
      elasticsearch:
        hosts: ["127.0.0.1:9200","127.0.0.1:9201","127.0.0.1:9202"]
    
    
      

    整个filebeat的配置文件我们都要分析下

    filebeat.config.modules:
    # Glob pattern for configuration loading
    path: ${path.config}/modules.d/*.yml
    reload.enabled: true

    这个配置就会去加载上面的modules.d目录下面的nginx.yml配置文件,在这个配置文件中使用moudles来收集nginx的配置文件

    output:
    elasticsearch:
    hosts: ["127.0.0.1:9200","127.0.0.1:9201","127.0.0.1:9202"]

    这个指定filebeat收集到日志之后直接发送到es的集群中

    setup.template.settings:
    index.number_of_shards: 3

    这个指定一个索引文件存储在3个分片中

      es-head中0 1 2 就是对于的分片,每个文档都是分别存储在上面的三个分片中

  • 相关阅读:
    SpringBoot 之基础学习篇.
    Java 反射机制
    第二十二节,TensorFlow中的图片分类模型库slim的使用、数据集处理
    第二十一节,条件变分自编码
    第二十节,变分自编码
    第十九节,去噪自编码和栈式自编码
    使用webdriver+urllib爬取网页数据(模拟登陆,过验证码)
    第十八节,自编码网络介绍及代码实现
    第十七节,受限玻尔兹曼机网络及代码实现
    第二十二节,TensorFlow中RNN实现一些其它知识补充
  • 原文地址:https://www.cnblogs.com/kebibuluan/p/12200642.html
Copyright © 2011-2022 走看看