目的
服务器运维系统日志监控是非常重要的工作.,目前常见的有EFK日志收集系统,实际上是3个系统组成,elasticsearch + filebeat+kibana.这三个软件在 elastic.co上都能下载.目前目前现在这个时期下最新的就可以了.具体下载过程我们就不写了,下载的文件版本如下:
# | 名称 | 备注 | |
1 | elasticsearch | elasticsearch-7.12.1-linux-x86_64.tar.gz |
7.12.1版本,这是三个软件需要版本一致. 主要用来存储和分析数据 |
2 | filebeat | filebeat-7.12.1-linux-x86_64.tar.gz | 用来收集日志信息,该工具比较轻量,行你比较好 |
3 | kibana | kibana-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
查看