zoukankan      html  css  js  c++  java
  • 转载他人的efk搭建文章后边有链接和地址

     

    通过部署elasticsearch(三节点)+filebeat+kibana快速入门EFK,并搭建起可用的demo环境测试效果


    目录

    ▪ 用途
    ▪ 实验架构
    ▪ EFK软件安装
    ▪ elasticsearch配置
    ▪ filebeat配置
    ▪ kibana配置
    ▪ 启动服务
    ▪ kibana界面配置
    ▪ 测试
    ▪ 后续文章


    用途

    ▷ 通过filebeat实时收集nginx访问日志、传输至elasticsearch集群
    ▷ filebeat将收集的日志传输至elasticsearch集群
    ▷ 通过kibana展示日志


    实验架构

    ▷ 服务器配置

    ▷ 架构图

    我自己的实验ip:el-192.1168.93.31。192.168.93.38。192.168.93.39  filebeat:192.168.93.40  kibana:192.168.93.32

    后边都已此为准


    EFK软件安装

    版本说明

    ▷ elasticsearch 7.3.2
    ▷ filebeat 7.3.2
    ▷ kibana 7.3.2

    注意事项

    ▷ 三个组件版本必须一致
    ▷ elasticsearch必须3台以上且总数量为单数

    安装路径

    ▷ /opt/elasticsearch
    ▷ /opt/filebeat
    ▷ /opt/kibana

    elasticsearch安装:3台es均执行相同的安装步骤

    mkdir -p /opt/software && cd /opt/software
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.2-linux-x86_64.tar.gz
    tar -zxvf elasticsearch-7.3.2-linux-x86_64.tar.gz
    mv elasticsearch-7.3.2 /opt/elasticsearch
    useradd elasticsearch -d /opt/elasticsearch -s /sbin/nologin
    mkdir -p /opt/logs/elasticsearch
    chown elasticsearch.elasticsearch /opt/elasticsearch -R
    chown elasticsearch.elasticsearch /opt/logs/elasticsearch -R
    
    # 限制一个进程可以拥有的VMA(虚拟内存区域)的数量要超过262144,不然elasticsearch会报max virtual memory areas vm.max_map_count [65535] is too low, increase to at least [262144]
    echo "vm.max_map_count = 655350" >> /etc/sysctl.conf
    sysctl -p

    filebeat安装

    mkdir -p /opt/software && cd /opt/software
    wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.3.2-linux-x86_64.tar.gz
    mkdir -p /opt/logs/filebeat/
    tar -zxvf filebeat-7.3.2-linux-x86_64.tar.gz
    mv filebeat-7.3.2-linux-x86_64 /opt/filebeat

    kibana安装

    mkdir -p /opt/software && cd /opt/software
    wget https://artifacts.elastic.co/downloads/kibana/kibana-7.3.2-linux-x86_64.tar.gz
    tar -zxvf kibana-7.3.2-linux-x86_64.tar.gz
    mv kibana-7.3.2-linux-x86_64 /opt/kibana
    useradd kibana -d /opt/kibana -s /sbin/nologin
    chown kibana.kibana /opt/kibana -R

    nginx安装(用于生成日志,被filebeat收集)

    # 只在192.168.1.11安装
    yum install -y nginx
    /usr/sbin/nginx -c /etc/nginx/nginx.conf

    elasticsearch配置

    ▷ 192.168.1.31 /opt/elasticsearch/config/elasticsearch.yml

    # 集群名字
    cluster.name: my-application
    
    # 节点名字
    node.name: 192.168.1.31
    
    # 日志位置
    path.logs: /opt/logs/elasticsearch
    
    # 本节点访问IP
    network.host: 192.168.1.31
    
    # 本节点访问
    http.port: 9200
    
    # 节点运输端口
    transport.port: 9300
    
    # 集群中其他主机的列表
    discovery.seed_hosts: ["192.168.1.31", "192.168.1.32", "192.168.1.33"]
    
    # 首次启动全新的Elasticsearch集群时,在第一次选举中便对其票数进行计数的master节点的集合
    cluster.initial_master_nodes: ["192.168.1.31", "192.168.1.32", "192.168.1.33"]
    
    # 启用跨域资源共享
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    
    # 只要有2台数据或主节点已加入集群,就可以恢复
    gateway.recover_after_nodes: 2

    ▷ 192.168.1.32 /opt/elasticsearch/config/elasticsearch.yml

    # 集群名字
    cluster.name: my-application
    
    # 节点名字
    node.name: 192.168.1.32
    
    # 日志位置
    path.logs: /opt/logs/elasticsearch
    
    # 本节点访问IP
    network.host: 192.168.1.32
    
    # 本节点访问
    http.port: 9200
    
    # 节点运输端口
    transport.port: 9300
    
    # 集群中其他主机的列表
    discovery.seed_hosts: ["192.168.1.31", "192.168.1.32", "192.168.1.33"]
    
    # 首次启动全新的Elasticsearch集群时,在第一次选举中便对其票数进行计数的master节点的集合
    cluster.initial_master_nodes: ["192.168.1.31", "192.168.1.32", "192.168.1.33"]
    
    # 启用跨域资源共享
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    
    # 只要有2台数据或主节点已加入集群,就可以恢复
    gateway.recover_after_nodes: 2

    ▷ 192.168.1.33 /opt/elasticsearch/config/elasticsearch.yml

    # 集群名字
    cluster.name: my-application
    
    # 节点名字
    node.name: 192.168.1.33
    
    # 日志位置
    path.logs: /opt/logs/elasticsearch
    
    # 本节点访问IP
    network.host: 192.168.1.33
    
    # 本节点访问
    http.port: 9200
    
    # 节点运输端口
    transport.port: 9300
    
    # 集群中其他主机的列表
    discovery.seed_hosts: ["192.168.1.31", "192.168.1.32", "192.168.1.33"]
    
    # 首次启动全新的Elasticsearch集群时,在第一次选举中便对其票数进行计数的master节点的集合
    cluster.initial_master_nodes: ["192.168.1.31", "192.168.1.32", "192.168.1.33"]
    
    # 启用跨域资源共享
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    
    # 只要有2台数据或主节点已加入集群,就可以恢复
    gateway.recover_after_nodes: 2

    filebeat配置

    192.168.1.11 /opt/filebeat/filebeat.yml

    # 文件输入
    filebeat.inputs:
      # 文件输入类型
      - type: log
        # 开启加载
        enabled: true
        # 文件位置
        paths:
          - /var/log/nginx/access.log
        # 自定义参数
        fields:
          type: nginx_access  # 类型是nginx_access,和上面fields.type是一致的
    
    # 输出至elasticsearch
    output.elasticsearch:
      # elasticsearch集群
      hosts: ["http://192.168.1.31:9200",
              "http://192.168.1.32:9200",
              "http://192.168.1.33:9200"]
    
      # 索引配置
      indices:
        # 索引名
        - index: "nginx_access_%{+yyy.MM}"
          # 当类型是nginx_access时使用此索引
          when.equals:
            fields.type: "nginx_access"
    
    # 关闭自带模板
    setup.template.enabled: false
    
    # 开启日志记录
    logging.to_files: true
    # 日志等级
    logging.level: info
    # 日志文件
    logging.files:
      # 日志位置
      path: /opt/logs/filebeat/
      # 日志名字
      name: filebeat
      # 日志轮转期限,必须要2~1024
      keepfiles: 7
      # 日志轮转权限
      permissions: 0600

    kibana配置

    192.168.1.21 /opt/kibana/config/kibana.yml

    # 本节点访问端口
    server.port: 5601
    
    # 本节点IP
    server.host: "192.168.1.21"
    
    # 本节点名字
    server.name: "192.168.1.21"
    
    # elasticsearch集群IP
    elasticsearch.hosts: ["http://192.168.1.31:9200",
                          "http://192.168.1.32:9200",
                          "http://192.168.1.33:9200"]

    启动服务

    # elasticsearch启动(3台es均启动)
    sudo -u elasticsearch /opt/elasticsearch/bin/elasticsearch
    
    # filebeat启动
    /opt/filebeat/filebeat -e -c /opt/filebeat/filebeat.yml -d "publish"
    
    # kibana启动
    sudo -u kibana /opt/kibana/bin/kibana -c /opt/kibana/config/kibana.yml

    上面的启动方法是位于前台运行。systemd配置方法,会在《EFK教程》系列后续文章中提供,敬请关注!


    在这里启动时我遇到的问题是el和kibana启动不了

    解决办法引用下边

    主要出现下面三个错误

    ERROR: [3] bootstrap checks failed
    [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
    [2]: max number of threads [3780] for user [esyonghu] is too low, increase to at least [4096]
    [3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    [2018-12-12T21:54:57,353][INFO ][o.e.n.Node               ] [PlbSkhz] stopping ...
    [2018-12-12T21:54:57,413][INFO ][o.e.n.Node               ] [PlbSkhz] stopped
    [2018-12-12T21:54:57,413][INFO ][o.e.n.Node               ] [PlbSkhz] closing ...
    [2018-12-12T21:54:57,473][INFO ][o.e.n.Node               ] [PlbSkhz] closed
    [2018-12-12T21:54:57,488][INFO ][o.e.x.m.j.p.NativeController] [PlbSkhz] Native controller process has stopped - no new native processes can be started
    解决方法

    [root@localhost ~]# vi /etc/security/limits.conf
    在文件的末尾加上我们之前创建的用户

    elasticsearchsoft nofile 65536
    elasticsearch hard nofile 65536
    elasticsearch soft nproc 4096
    elasticsearch hard nproc 4096
    进入到下面文件夹

    [root@localhost ~]# cd /etc/security/limits.d
    [root@localhost limits.d]# ll
    total 4
    -rw-r--r--. 1 root root 191 Nov  6  2016 20-nproc.conf
     
    [root@localhost limits.d]# vi 20-nproc.conf 
     
    # Default limit for number of user's processes to prevent
    # accidental fork bombs.
    # See rhbz #432903 for reasoning.
     
    *          soft    nproc     4096
    root       soft    nproc     unlimited
    ~                                                                                                                            
    ~  
    将上面内容的*号改成创建时创建的用户名

    # See rhbz #432903 for reasoning.
     
    esyonghu   soft    nproc     4096
    root       soft    nproc     unlimited
    修改下面文件加上内容

    [root@localhost security]# vi /etc/sysctl.conf 
    vm.max_map_count = 655360
    对于上面的内容让其生效

    [root@localhost security]# sysctl -p
    vm.max_map_count = 655360

    原文链接:https://blog.csdn.net/zhanghe687/article/details/84979833

    记得el服务器的内存最低也是4G不然会各种报错,CPU最好为2,处理器为4.

    还有记得全部关闭防火墙。

    kibana界面配置

    1️⃣ 使用浏览器访问192.168.1.21:5601,看到以下界面表示启动成功

    2️⃣ 点"Try our sample data"

    3️⃣ "Help us improve the Elastic Stack by providing usage statistics for basic features. We will not share this data outside of Elastic"点"no”

    4️⃣ "Add Data to kibana"点"Add data"

    5️⃣ 进入视图


    测试

    访问nginx,生成日志

    curl -I "http://192.168.1.11"

    在kibana上查看数据

    1️⃣ 创建索引模板

    2️⃣ 输入你要创建的索引模板的名字

    3️⃣ 查看之前CURL的数据


    https://www.cnblogs.com/fzxiaomange/p/efk-getstart.html 文章来源

     
     
     
  • 相关阅读:
    php中__construct()和__initialize()的区别
    js的栈内存和堆内存
    CC攻击原理及防范方法
    html页面调用js文件里的函数报错onclick is not defined处理方法
    yii2深入理解之内核解析
    Scala Data Structure
    Scala Basis
    【MySql】牛客SQL刷题(下)
    【Flume】知识点整理
    【kafka】生产者API
  • 原文地址:https://www.cnblogs.com/john4415/p/11768504.html
Copyright © 2011-2022 走看看