ELK企业级日志分析平台——logstash

部署

新建一台虚拟机elk4部署logstash

复制代码
[root@elk4 ~]# yum install -y jdk-11.0.15_linux-x64_bin.rpm

[root@elk4 ~]# yum install -y logstash-7.6.1.rpm

命令方式

复制代码
[root@elk4 bin]# /usr/share/logstash/bin/logstash -e 'input { stdin { } } output { stdout {} }'

elasticsearch输出插件

复制代码
[root@elk4 conf.d]# pwd

[root@elk4 conf.d]# vim test.conf

input {
        stdin { }
}

output {
        stdout {}

        elasticsearch {
                hosts => "192.168.92.31:9200"
                index => "logstash-%{+YYYY.MM.dd}"
        }
}
复制代码
[root@elk4 conf.d]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/test.conf

启动成功后录入数据,ctrl+c退出

elasticsearch-head插件

安装依赖

复制代码
[root@k8s1 ~]# yum install -y bzip2

[root@k8s1 ~]# tar jxf phantomjs-2.1.1-linux-x86_64.tar.bz2

[root@k8s1 ~]# cd phantomjs-2.1.1-linux-x86_64

[root@k8s1 phantomjs-2.1.1-linux-x86_64]# cp bin/phantomjs /usr/local/bin/

[root@k8s1 ~]# yum install -y fontconfig

[root@k8s1 ~]# phantomjs

安装插件

复制代码
[root@k8s1 ~]# rpm -ivh nodejs-9.11.2-1nodesource.x86_64.rpm

[root@k8s1 ~]# yum install -y unzip

[root@k8s1 ~]# unzip elasticsearch-head-master.zip

[root@k8s1 ~]# cd elasticsearch-head-master/

[root@k8s1 elasticsearch-head-master]# npm install  --registry=https://registry.npm.taobao.org

[root@k8s1 elasticsearch-head-master]# vim _site/app.js

启动服务

复制代码
[root@k8s1 elasticsearch-head-master]# npm run start &
复制代码
[root@k8s1 elasticsearch-head-master]# netstat -antlp|grep :9100

修改es配置

复制代码
[root@elk1 ~]# vim /etc/elasticsearch/elasticsearch.yml

http.cors.enabled: true
http.cors.allow-origin: "*"

[root@elk1 ~]# systemctl  restart elasticsearch.service

访问:192.168.92.11:9100

file输入插件

复制代码
[root@elk4 conf.d]# vim es.conf

input {
      #file {
      #       path => "/var/log/messages"
      #       start_position => "beginning"
      #  }

      syslog {}

}


output {
        stdout {}

        elasticsearch {
                hosts => "192.168.92.31:9200"
                index => "rsyslog-%{+YYYY.MM.dd}"
        }
}
复制代码
[root@elk4 conf.d]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/test.conf

.sincedb文件保存文件读取进度,避免数据冗余读取

复制代码
[root@elk4 file]# pwd

[root@elk4 file]# l.

sincedb文件一共6个字段

  1. inode编号
  2. 文件系统的主要设备号
  3. 文件系统的次要设备号
  4. 文件中的当前字节偏移量
  5. 最后一个活动时间戳(浮点数)
  6. 与此记录匹配的最后一个已知路径

删除后重新读取

复制代码
[root@elk4 file]# rm -f .sincedb_452905a167cf4509fd08acb964fdb20c

syslog 插件

logstash伪装成日志服务器

复制代码
[root@elk4 conf.d]# vim test.conf

input {
        syslog {}
}

output {
         stdout {}

        elasticsearch {
                hosts => "192.168.92.31:9200"
                index => "syslog-%{+YYYY.MM.dd}"
        }

}

[root@elk4 conf.d]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/test.conf

配置客户端日志输出

root@server1 \~\]# vim /etc/rsyslog.conf 去掉以下行的注释 ![](https://file.jishuzhan.net/article/1728208243299192833/202cad9543ce5fac85d33aee767e4ba9.webp) ![](https://file.jishuzhan.net/article/1728208243299192833/530f76b891c7bc2e4b38c3f0e29b29db.webp) [root@elk1 ~]# systemctl restart rsyslog.service ![](https://file.jishuzhan.net/article/1728208243299192833/d9a10229926c98c973f5bfa1fb4b77cd.webp) ## **多行过滤插件** 从server1拷贝模板文件 [root@elk1 elasticsearch]# pwd [root@elk1 elasticsearch]# scp my-es.log elk4:/var/log/ ![](https://file.jishuzhan.net/article/1728208243299192833/4a0fe320b79526f828609b0dbdbecab0.webp) [root@elk4 conf.d]# vim my-es-log.conf input { file { path => "/var/log/my-es.log" start_position => "beginning" codec => multiline { pattern => "^\[" negate => true what => previous } } } output { stdout {} elasticsearch { hosts => "192.168.92.31:9200" index => "myeslog-%{+YYYY.MM.dd}" } } ![](https://file.jishuzhan.net/article/1728208243299192833/5ac38c64cd74c557a91750aff1a35ff8.webp) [root@elk4 conf.d]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/test.conf ![](https://file.jishuzhan.net/article/1728208243299192833/7c51d6dfc363d8f043efd416703a2555.webp) ## **grok过滤** [root@elk4 ~]# yum install -y httpd [root@elk4 ~]# systemctl enablel --now httpd [root@elk4 ~]# echo www.westos.org > /var/www/html/index.html 访问此站点生成日志信息 ab -c 1 -n 500 http://192.168.92.34/index.html 编写文件 [root@elk4 conf.d]# vim grok.conf input { file { path => "/var/log/httpd/access_log" start_position => "beginning" } } filter { grok { match => { "message" => "%{HTTPD_COMBINEDLOG}" } } } output { stdout {} elasticsearch { hosts => "192.168.92.31:9200" index => "apachelog-%{+YYYY.MM.dd}" } } ![](https://file.jishuzhan.net/article/1728208243299192833/807d7db64243a104176e7003585894e6.webp) [root@elk4 conf.d]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/grok.conf ![](https://file.jishuzhan.net/article/1728208243299192833/053b7cb66f0ab37bc55aae7bade987b4.webp)

相关推荐
小猪咪piggy17 小时前
【JavaEE】(24) Linux 基础使用和程序部署
linux·运维·服务器
IT 小阿姨(数据库)18 小时前
PgSQL中pg_stat_user_tables 和 pg_stat_user_objects参数详解
linux·运维·数据库·sql·postgresql·oracle
❀͜͡傀儡师18 小时前
Docker部署搜索引擎SearXNG
运维·docker·容器·searxng
虎头金猫18 小时前
如何在Linux上使用Docker在本地部署开源PDF工具Stirling PDF:StirlingPDF+cpolar让专业操作像在线文档一样简单
linux·运维·ubuntu·docker·pdf·开源·centos
荣光波比19 小时前
Nginx 实战系列(七)—— Nginx一键安装脚本详解
运维·nginx·自动化·云计算
sinat_6020353619 小时前
模块与包的导入
运维·服务器·开发语言·python
2301_8101545519 小时前
VM中CentOS 7密码重置
linux·运维·centos
网硕互联的小客服19 小时前
408 Request Timeout:请求超时,服务器等待客户端发送请求的时间过长。
运维·服务器
王伯安呢20 小时前
告别线缆束缚!AirDroid Cast 多端投屏,让分享更自由
运维·服务器·教程·投屏·airdroid cast·多端互投
逍遥浪子~20 小时前
搭建本地gitea服务器
运维·服务器·gitea