当前位置: 首页 > 后端技术 > Java

elk7.15.1安装、部署、构建

时间:2023-04-01 17:17:42 Java

ELK介绍ELK是Elasticsearch、Logstash、Kibana这三个开源框架的首字母缩写(但后来出现的Filebeat(beat的一种)可以用来代替数据采集功能Logstash的轻量级)。市面上也叫ElasticStack。Filebeat是一个轻量级的日志数据转发和集中交付工具。Filebeat监控您指定的日志文件或位置,收集日志事件,并将它们转发到Elasticsearch或Logstash进行索引。Filebeat的工作原理如下:当您启动Filebeat时,它会启动一个或多个输入,它会在为日志数据指定的位置查找这些输入。对于Filebeat找到的每个日志,Filebeat都会启动一个收集器。每个收集器读取单个日志以获取新内容,并将新日志数据发送到libbeat,后者聚合事件,并将聚合数据发送到为Filebeat配置的输出。Logstash是一个免费且开放的服务器端数据处理管道,能够从多个来源获取数据、转换数据并将其发送到您最喜欢的“存储库”。Logstash可以动态摄取、转换和传输数据,无论格式或复杂性如何。使用Grok从非结构化数据中获取结构,从IP地址中解码地理坐标,匿名化或排除敏感字段,并简化整体处理。Elasticsearch是ElasticStack的核心分布式搜索和分析引擎。它是一个基于Lucene的、分布式的、通过Restful实现交互的近实时搜索平台框架。Elasticsearch为所有类型的数据提供近乎实时的搜索和分析。无论您拥有结构化或非结构化文本、数字还是地理空间数据,Elasticsearch都可以以支持快速搜索的方式高效地存储和索引这些数据。Kibana是Elasticsearch的一个开源分析和可视化平台,用于搜索和查看交互存储在Elasticsearch索引中的数据。使用Kibana,您可以通过各种图表进行高级数据分析和展示。并且可以为Logstash和ElasticSearch提供一个日志分析友好的web界面,可以对重要的数据日志进行汇总、分析和搜索。它还可以使大量数据更易于理解。操作简单,基于浏览器的用户界面可以快速创建仪表盘(Dashboard),实时展示Elasticsearch动态完整的日志系统。到存储系统存储:存储日志数据分析:支持UI分析警告:可以提供错误报告,监控机制安装jdk17环境root@elk:~#mkdirjdkroot@elk:~#cdjdkroot@elk:~/jdk#wgethttps://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gzroot@elk:~/jdk#tarxfjdk-17_linux-x64_bin.tar.gzroot@elk:~/jdk#cd..root@elk:~#root@elk:~#mvjdk//root@elk:~#vim/etc/profileroot@elk:~#root@elk:~#root@elk:~#tail-n4/etc/profileexportJAVA_HOME=/jdk/jdk-17.0.1/exportPATH=$JAVA_HOME/bin:$PATHexportCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarroot@elk:~#root@elk:~#source/etc/profileroot@elk:~#chmod-R777/jdk/创建elk文件夹并下载所需的包root@elk:~#mkdirelkroot@elk:~#cdelkroot@elk:~/elk#wgethttps://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.15.1-linux-x86_64.tar.gzroot@elk:~/elk#wgethttps://artifacts.elastic.co/downloads/kibana/kibana-7.15.1-linux-x86_64.tar.gzroot@elk:~/elk#wgethttps://artifacts.elastic.co/downloads/logstash/logstash-7.15.1-linux-x86_64。tar.gzroot@elk:~/elk#tarxfkibana-7.15.1-linux-x86_64.tar.gzroot@elk:~/elk#tarxflogstash-7.15.1-linux-x86_64.tar.gzroot@elk:.~/elk#lltotal970288drwxr-xr-x5rootroot4096Oct2006:09./drwx------7rootroot4096Oct2006:04../drwxr-xr-x9rootroot4096Oct722:00elasticsearch-7.15.1/-rw-r--r--1rootroot340849929Oct1413:28elasticsearch-7.15.1-linux-x86_64.tar.gzdrwxr-xr-x10rootroot4096Oct2006:09Kibana-7.15.1-linux-x86_64/-rw-r--r--1根根28375224110月14日13:34Kibana-7.15.1-linux-x86_64.tar.gzdrwxr-xr-x13根root4096Oct2006:09logstash-7.15.1/-rw-r--r--1rootroot368944379Oct1413:38logstash-7.15.1-linux-x86_64.tar.gz在默认设置root@elk:~/elk#cdroot@elk:~#useraddelkroot@elk:~#mkdir/home/elkroot@elk:~#cp-relk//home/elk/root@elk:~#chown-Relk:elk/home/elk/修改系统配置文件root@elk:~#vim/etc/security/limits.confroot@elk:~#root@elk:~#root@elk:~#tail-n3/etc/security/limits.conf*softnofile65536*hardnofile65536root@elk:~#root@elk:~#vim/etc/sysctl.confroot@elk:~#root@elk:~#tail-n2/etc/sysctl.confvm.max_map_count=262144root@elk:~#root@elk:~#sysctl-pvm.max_map_count=262144root@elk:~#修改elk配置文件root@elk:~#su-elk$bashelk@elk:~$cd/elk/elasticsearch-7.15.1/configelk@elk:~/elk/elasticsearch-7.15.1/config$vimelasticsearch.ymlelk@elk:~/elk/elasticsearch-7.15。1/config$elk@elk:~/elk/elasticsearch-7.15.1/config$tail-n20elasticsearch.yml#设置数据存放路径为/data/es-datapath.data:/home/elk/data/#设置日志路径为/log/es-logpath.logs:/home/elk/data/#设置内存不使用swap分区bootstrap.memory_lock:false#当bootstrap.memory_lock配置为true时,它会导致9200反而被监听,原因不明#设置允许所有ip连接elasticsearchnetwork.host:0.0.0.0#开启监听的端口为9200http.port:9500#添加新的参数,为了让elasticsearch-head插件可以访问es(5.x版本,如果没有可以手动添加)http.cors.enabled:truehttp.cors.allow-origin:"*"cluster.initial_master_nodes:["elk"]node.name:elkroot@elk:~/elk/elasticsearch-7.15.1/config#使用elk用户启动elasticsearchroot@elk:~#su-elk$bashelk@elk:~$elk@elk:~$mkdirdataelk@elk:~/elk/elasticsearch-7.15.1/bin$cdelk@elk:~$cd/home/elk/elk/elasticsearch-7.15.1/binelk@elk:~/elk/elasticsearch-7.15.1/bin$。/elasticsearchstart然后访问测试:root@elk:~#curl-Ihttp://192.168.1.19:9500/HTTP/1.1200OKX-elastic-product:ElasticsearchWarning:299Elasticsearch-7.15.1-83c34f456ae29d60e94d886e455e6a3409bba9ed"Elastic-insearchnatureecfeurt未启用。如果没有身份验证,任何人都可以访问您的集群。请参阅https://www.elastic.co/guide/en/elasticsearch/reference/7.15/security-minimal-setup.html以启用安全性。”内容类型:application/json;charset=UTF-8content-length:532root@elk:~#放到后台运行elk@elk:~/elk/elasticsearch-7.15.1/bin$nohup/home/elk/elk/elk/elasticsearch-7.15.1/bin/elasticsearch>>/home/elk/elk/elasticsearch-7.15.1/output.log2>&1&[1]8811elk@elk:~/elk/elasticsearch-7.15.1/bin$elk@elk:~$cdelk/kibana-7.15.1-linux-x86_64/config/elk@elk:~/elk/kibana-7.15.1-linux-x86_64/config$vimkibana.ymlelk@elk:~/elk/kibana-7.15.1-linux-x86_64/config$tail-n18kibana.yml#设置监听端口为5601server.port:5601#设置可访问主机地址server.host:"0.0.0.0"#设置elasticsearch主机地址elasticsearch.hosts:["http://localhost:9500"]#如果elasticsearch设置了用户名和密码,那么就需要配置这两项,没有配置的话不用担心#elasticsearch.username:"user"#elasticsearch.password:"pass"elk@elk:~/elk/kibana-7.15.1-linux-x86_64/config$elk@elk:~$cd/home/elk/elk/kibana-7.15.1-linux-x86_64/binelk@elk:~/elk/kibana-7.15.1-linux-x86_64/bin$./kibana测试访问root@elk:~#curl-Ihttp://192.168.1.19:5601/app/home#/tutorial_directoryHTTP/1.1200OKcontent-security-policy:script-src'unsafe-eval''self';worker-srcblob:'self';style-src'unsafe-inline''self'x-content-类型选项:nosniffreferrer-policy:no-referrer-when-downgradekbn-name:elkkbn-license-sig:aaa69ea6a0792153cde61e88d0cd9bbad7ddcdaec87b613f281dd275e9dbad47content-type:文本/html;charset=utf-8cache-control:private,no-cache,no-store,must-revalidatecontent-length:144351vary:accept-encodingDate:Wed,20Oct202107:11:10GMTConnection:keep-aliveKeep-Alive:超时=120root@elk:~#放到后台运行elk@elk:~/elk/kibana-7.15.1-linux-x86_64/bin$nohup/home/elk/elk/kibana-7.15.1-linux-x86_64/bin/kibana>>/home/elk/elk/kibana-7.15.1-linux-x86_64/output.log2>&1&[2]9378elk@elk:~/elk/kibana-7.15.1-linux-x86_64/bin$输出日志信息到屏幕elk@elk:~$cdelk/logstash-7.15.1/bin/elk@elk:~/elk/logstash-7.15.1/bin$./logstash-e'input{stdin{}}output{stdout{}}'输入123回车,将结果输出到屏幕上{"host"=>"elk","@timestamp"=>2021-10-20T07:15:54.230Z,"@version"=>"1","message"=>""}123{"host"=>"elk","@timestamp"=>2021-10-20T07:15:56.453Z,"@version"=>"1","message"=>"123"}elk@elk:~/elk/logstash-7.15.1/bin$cd../config/elk@elk:~/elk/logstash-7.15.1/config$vimlogstashelk@elk:~/elk/logstash-7.15.1/config$catlogstashinput{#从file文件中读取日志信息{path=>"/var/log/messages"type=>"system"start_position=>"beginning"}}filter{}output{#标准输出标准输出{}}elk@elk:~/elk/logstash-7.15.1/config$mvlogstashlogstash.confelk@elk:~/elk/logstash-7.15.1/config$开始测试elk@elk:~/elk/logstash-7.15.1/config$cd../bin/elk@elk:~/elk/logstash-7.15.1/bin$./logstash-f../config/logstash.conf后台启动elk@elk:~$nohup/home/elk/elk/logstash-7.15.1/bin/logstash-f/home/elk/elk/logstash-7.15.1/config/logstash.conf>>/home/elk/elk/logstash-7.15.1/output.log2>&1&[3]10177elk@elk:~$设置开机自启动elk@elk:~$vimstartup.shelk@elk:~$elk@elk:~$catstartup.sh#!/bin/bashnohup/home/elk/elk/elasticsearch-7.15.1/bin/elasticsearch>>/home/elk/elk/elasticsearch-7.15.1/output.log2>&1&nohup/home/elk/elk/kibana-7.15.1-linux-x86_64/bin/kibana>>/home/elk/elk/kibana-7.15.1-linux-x86_64/output.log2>&1&nohup/home/elk/elk/logstash-7.15.1/bin/logstash-f/home/elk/elk/logstash-7.15.1/config/logstash.conf>>/home/elk/elk/logstash-7.15.1/output.log2>&1&elk@elk:~$elk@elk:~$crontab-enocrontabforelk-使用一个空的选择一个编辑器。要稍后更改,请运行“select-editor”。1./bin/nano<----最简单的2./usr/bin/vim.basic3./usr/bin/vim.tiny4./bin/edChoose1-4[1]:2crontab:安装新的crontabelk@elk:~$elk@elk:~$elk@elk:~$crontab-l@reboot/home/elk/startup.shelk@elk:~$logstash插件logstash是通过插件插件来加强其功能-in分类:inputsinputcodecsdecodingfiltersfiltersoutputsoutputlogstash插件记录在Gemfile文件中elk@elk:~$cdelk/logstash-7.15.1elk@elk:~/elk/logstash-7.15.1$lsGemfileGemfileelk@麋鹿:~/elk/logstash-7.15.1$去其github下载插件,地址为:https://github.com/logstash-p...使用过滤器插件logstash-filter-mutateelk@elk:~/elk/logstash-7.15.1/config$vimlogstash2.conf#创建一个新的配置文件来过滤输入{stdin{}}filter{mutate{split=>["message","|"]}}output{stdout{}}在输入sss|sssni|akok223|23时,数据处理流程会按照|进行分离分隔符:input–>decode–>filter–>decode–>output启动服务再启动logstash服务elk@elk:~$nohup/home/elk/elk/logstash-7.15.1/bin/logstash-f/home/elk/elk/logstash-7.15.1/config/logstash2.conf>>/home/elk/elk/logstash-7.15。1/output.log2>&1&Linux运维交流社区Linux运维交流社区,互联网新闻与技术交流41原创内容公众号本文使用文章同步助手进行同步