elk:filebeat

elk:filebeat日志收集工具和logstash相同

filebeat是一个轻量级的日志收集工具,所使用的系统资源比logstash部署和启动时使用的资源要小的多。

filebeat可以运行在非java环境,他可以代替logstash在非java环境上收集日志。

filebeat无法实现数据的过滤,一般是结果logstash的数据过滤功能一块使用。

filebeat收集的数据可以发往多个主机,远程收集

mysql

systemctl stop firewalld

setenforce 0

logstash:

tar -xf filebeat-6.7.2-linux-x86_64.tar.gz

mv filebeat-6.7.2-linux-x86_64 filebeat

vim /etc/logstash/logstash.yml (可以不改/etc/logstash/conf.d)

所有

yum install ntpdate -y

ntpdate ntp.aliyun.com

date

logstash:

yum -y install nginx

systemctl restart nginx

vim /etc/nginx/nginx.conf

vim /var/www/html/index.html

this is httpd

cd /usr/share/nginx/html

this is nginx/index.html

cd /var/log/nginx

ll

chmod 777 access.log error.log

cd /opt

cd filebeat/

cp filebeat.yml filebear.yml.bak

vim filebeat.yml

148行,150行

161行,163行

cd /opt

mkdir log

cd /etc/logstash/conf.d

vim file_nginx.conf

input {

beats { port => "5044" }

}

output {

if "nginx" in [tags] {

elasticsearch {

hosts => [ "192.168.233.12:9200","192.168.233.13:9200" ]

index =>"%{[fields][service_name]}-%{+YYYY.MM.dd}"

}

}

stdout {

codec => rubydebug

}

}

wq!

cd /opt/filebeat

nohup ./filebeat -e -c filebeat.yml > filebeat.out &

nohup 表示在后台记录执行命令的过程

./filebeat 运行文件

-e 使用标准输出的同时禁用syslog文件输出

-c 指定配置文件

> filebeat 执行过程输出到filebeat.out这个文件当中

& 后台运行

cd /opt/filebeat

tail -f filebeat.out

cd /opt/log

ls

logstash -f file_nginx.conf --path.data /opt/test1 &

测试访问:192.168.233.11:8080

192.168.233.11:8080/test

logstash收集日志的过程:

input()

filter(过滤)

output(发送es实例)

本地收集:

远程收集,远程收集多个日志,

mysql1:

vim /etc/my.cnf

general_log =ON

general_log_file=/usr/local/mysql/data/mysql_general.log

systemctl restart mysqld

cd /usr/local/mysql/data/

创建一个库,新建一个表

cd /usr/local/mysql/data

cat mysql_general.log

yum -y install nginx

yum -y install httpd

vim /etc/nginx/nginx.conf

systemctl restart nginx

systemctl restart httpd

vim /var/www/html/index.html

this is httpd

vim /usr/share/nginx/html/index.html

this is nginx

cd /opt

把filebeat拖进去

tar -xf filebeat-6.7.2-linux-x86_64.tar.gz

mv filebeat-6.7.2-linux-x86_64 filebeat

cd filebeat/

cp filebeat.yml filebeat.yml.bak

vim filebeat.yml

161行,163行

paths:

  • /var/log/nginx/access.log

  • /var/log/nginx/error.log

tags: ["nginx_18"]

fields:

service_name: 192.168.66.18_nginx

log_type: nginx

from: 192.168.66.18

  • type: log

enabled: true

paths:

  • /etc/httpd/logs/access_log

  • /etc/httpd/logs/error_log

tags: ["httpd_18"]

fields:

service_name: 192.168.66.18_httpd

log_type: httpd

from: 192.168.66.18

  • type: log

enabled: true

paths:

  • /usr/local/mysql/data/mysql_general.log

tags: ["mysql_18"]

fields:

service_name: 192.168.66.18_mysqld

log_type: mysql

from: 192.168.66.18

cd /var/log/nginx

chmod 777 access.log error.log

cd /etc/httpd/logs

chmod 777 access_log error_log

cd /usr/local/mysql/data

chmod 777 mysql_general.log

elk:

cd /opt/log

vim nhm_18.conf

input {

beats { port => "5045" }

}

output {

if "nginx_18" in [tags] {

elasticsearch {

hosts => ["192.168.66.15:9200","192.168.66.16:9200"]

index =>"%{[fields][service_name]}-%{+YYYY.MM.dd}"

}

}

if "httpd_18" in [tags] {

elasticsearch {

hosts => ["192.168.66.15:9200","192.168.66.16:9200"]

index =>"%{[fields][service_name]}-%{+YYYY.MM.dd}"

}

}

if "mysql_18" in [tags] {

elasticsearch {

hosts => ["192.168.66.15:9200","192.168.66.16:9200"]

index =>"%{[fields][service_name]}-%{+YYYY.MM.dd}"

}

}

stdout {

codec => rubydebug

}

wq!

mysql:

nohup ./filebeat -e -c filebeat.yml > filebeat.out &

elk

logstash -f nhm_21.conf --path.data /opt/test2 &

##lofgstash 可以使用任意端口,只有没被占用都可以使用,推荐1024之后开始

logstash 性能上的优化:logstash启动是在jvm虚拟机当中其中,启动一次至少要占500M内存。

elk

vim logstash.yml

41行

pipeline.workers:2

##logstash的工作线程,默认值就是cpu数,4 2 8 4 给一半即可 2核2G

45行

pipeline.bash.size:125

##一次性能够批量处理检索事件的大小 125条数。200

50行

pipeline.batch.delay:50

##查询更新的延迟,50毫秒,也可以自行调整 15 10 也要看机器性能

相关推荐
hujun86109 小时前
Ubuntu安装无线网卡
linux
Johny_Zhao9 小时前
CentOS Stream 8 高可用 Kuboard 部署方案
linux·网络·python·网络安全·docker·信息安全·kubernetes·云计算·shell·yum源·系统运维·kuboard
卖猪肉的痴汉11 小时前
1.1 Linux 编译FFmpeg 4.4.1
linux·ffmpeg
哲讯智能科技11 小时前
苏州SAP代理商:哲讯科技助力企业数字化转型
大数据·运维·人工智能
十五年专注C++开发11 小时前
Qt .pro配置gcc相关命令(三):-W1、-L、-rpath和-rpath-link
linux·运维·c++·qt·cmake·跨平台编译
qq_6285157612 小时前
Centos与RockLinux设置静态ip
linux·运维·centos
程序员老乔12 小时前
【Dify系列】【一】【安装与部署】【ubuntu22.04安装docker部署dify1.4.2】
运维·docker·容器
程序猿小D13 小时前
第27节 Node.js Buffer
linux·开发语言·vscode·node.js·c#·编辑器·vim
沧浪之水1201013713 小时前
linux常用命令
linux·运维·服务器
梦会实现13 小时前
无外接物理显示器的Ubuntu系统的远程桌面连接(升级版)
linux·运维·ubuntu·计算机外设