日志收集系统EFK安装及配置

本文详细介绍了如何安装和配置ELK堆栈(Elasticsearch、Filebeat和Kibana),包括设置系统参数、修改配置文件、安装步骤和启用nginx日志收集。重点在于使用这三个工具实现服务器运维的日志监控。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目的

服务器运维系统日志监控是非常重要的工作.,目前常见的有EFK日志收集系统,实际上是3个系统组成,elasticsearch +  filebeat+kibana.这三个软件在 elastic.co上都能下载.目前目前现在这个时期下最新的就可以了.具体下载过程我们就不写了,下载的文件版本如下:

#名称 备注
1elasticsearchelasticsearch-7.12.1-linux-x86_64.tar.gz

7.12.1版本,这是三个软件需要版本一致.

主要用来存储和分析数据

2filebeatfilebeat-7.12.1-linux-x86_64.tar.gz用来收集日志信息,该工具比较轻量,行你比较好
3kibanakibana-7.12.1-linux-x86_64.tar.gz图形化结果显示工具

系统架构图如下,我们这里暂时不采用kafka/logstatsh组件,直接由filebeat输送给ES集群

实际架构如下

这里写图片描述

 

安装步骤

创建用户和准备文件

创建efk用户,并且把下载的文件复制到/home/efk目录下

#useradd efk
#su - ufk
$ls -l
total 624448
-rw-r--r--. 1 efk efk     11185 May 16 11:00 ansible-k8s.tar.gz
-rw-r--r--. 1 efk efk 325529336 May 16 11:00 elasticsearch-7.12.1-linux-x86_64.tar.gz
-rw-r--r--. 1 efk efk  32835893 May 16 11:00 filebeat-7.12.1-linux-x86_64.tar.gz
-rw-r--r--. 1 efk efk 281051589 May 16 11:00 kibana-7.12.1-linux-x86_64.tar.gz

 修改系统参数.

elasticsearch运行时刻,对系统有一定的要求. 需要增加 同时打开文件的数量,并且对增加内存锁

vi /etc/security/limits.d/20-mem.conf
* soft nofile 261444
* hard nofile 262144
efk soft memlock unlimited
efk  hard memlock unlimited

 修改进程数

vim /etc/security/limits.d/20-nproc.conf
* soft nproc unlimited
root soft nproc unlimited

修改map最大数

 vim /etc/sysctl.conf
vm.max_map_count = 262144
sysctl -p

解压压缩包,修改elasticsearch配置文件,在安装目录的config目录下.


node.name: node-1 #此处修改
network.host: 0.0.0.0 #此处修改,0.0.0.0表示侦听所有IP地址
http.port: 9200 # 此处修改
discovery.seed_hosts: ["node-1"] # 修改此处
cluster.initial_master_nodes: ["node-1"] 修改此处

解压压缩包,修改kibanna配置在安装目录的config目录下

[efk@efkserver config]$ sed -n '/^[^#]/p' kibana.yml
server.port: 5601 #修改此处
server.host: "0.0.0.0"  #修改此处
elasticsearch.hosts: ["http://localhost:9200"] #修改此处

启动elasticsearch和kibana

elasticsearch -d

nohup kibana 2>logs/kibana.log >&2 &

访问192.168.11.174:5601

配置filebeat

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /var/log/*.log
setup.kibana:
    host: "localhost:5601"
output.elasticsearch:
  hosts: ["localhost:9200"]

启动filebeat

nohup filebeat 2>/dev/null >&2 & 

 启用nginx日志

filebeat enable nginx

修改modules.d 下的nginx.yml

# Module: nginx
# Docs: https://www.elastic.co/guide/en/beats/filebeat/7.x/filebeat-module-nginx.html

- module: nginx
  # Access logs
  access:
    enabled: true

    # Set custom paths for the log files. If left empty,
    # Filebeat will choose the paths depending on your OS.
    var.paths: [/www/wwwlogs/*log] #修改

  # Error logs
  error:
    enabled: true

    # Set custom paths for the log files. If left empty,
    # Filebeat will choose the paths depending on your OS.
    var.paths: [/www/wwwlogs/*.error.log]

  # Ingress-nginx controller logs. This is disabled by default. It could be used in Kubernetes environments to parse ingress-nginx logs
  ingress_controller:
    enabled: false

    # Set custom paths for the log files. If left empty,
    # Filebeat will choose the paths depending on your OS.
    #var.paths:

启动

filebeat setup && filebeat -e

查看

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老骥又出发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值