ELK搭建开源日志系统(window版本)—图文详细
日志对于排查错误非常重要,使用linux命令awk sed grep find等命令查询日志非常麻烦,而且很难做数据分析,使用免费开源的ELK可以支撑大规模的日志检索,本文将一步步教怎么快速搭建一个window版本的ELK日志收集系统。
下载elasticsearch、logstash、kibana、filebeat
注意同一系列的版本要一样,防止出现版本不兼容问题,本文使用7.16.0版本,在window系统演示
下载elasticsearch
访问地址为:https://www.elastic.co/cn/downloads/past-releases
点击Donload下载
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lnxsdUYo-1650982517731)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220418221506034.png)]](https://img-blog.csdnimg.cn/af85f120e8224529a70174fe998a6048.png)
跳转到访问地址为: https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-16-0
可以选择window或者linux版本,本文下载window版本
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-M1jRDCQE-1650982517734)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220418222252223.png)]](https://img-blog.csdnimg.cn/a8a44f3c4d7c46ed975c618a4b9ef1bc.png)
下载logstash
点击Donload下载
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-RDykQ2Of-1650982517735)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220418222022349.png)]](https://img-blog.csdnimg.cn/3354463abf4747fdba936c5ebfe34570.png)
跳转到访问地址为: https://www.elastic.co/cn/downloads/past-releases/logstash-7-16-0
选择window版本
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YbuJ55ki-1650982517736)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220418222156985.png)]](https://img-blog.csdnimg.cn/08b110dbac0d46b984815746f81687b5.png)
下载kibana
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-rpJrDCzp-1650982517736)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220418222344389.png)]](https://img-blog.csdnimg.cn/f1a0783343b94da3b19d38c6b792d66b.png)
访问地址为:https://www.elastic.co/cn/downloads/past-releases/kibana-7-16-0
选择window版本
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MXd9av1V-1650982517737)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220418222406775.png)]](https://img-blog.csdnimg.cn/e7fc513d13ab4c4f8ce7df57cbdaefdd.png)
跳转到访问地址为:https://www.elastic.co/cn/downloads/past-releases/filebeat-7-16-0
下载filebeat
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3SQr23uj-1650982517737)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220418222601130.png)]](https://img-blog.csdnimg.cn/3ec0393aa284422c92894bc45f01cfee.png)
选择window版本
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-46KKFSYe-1650982517738)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220418222630758.png)]](https://img-blog.csdnimg.cn/56a5c4c997944fa4a261b8294fbe214a.png)
下载jdk11
由于7.16.0版本需要依赖java jdk11版本,需要将本地java环境切换到jdk11
访问网站: http://www.codebaoku.com/jdk/jdk-oracle-jdk11.html
点击下载
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FwGL7AIQ-1650982517739)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420200908722.png)]](https://img-blog.csdnimg.cn/f7deb92e47d64fb5bf3b0ea81b630c88.png)
全部下载完解压
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-onb7yQoC-1650982517739)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420202003124.png)]](https://img-blog.csdnimg.cn/23e8f095e14d4121824d62ca15b6c5f6.png)
安装jdk11、elasticsearch、kibana、logstash、filebeat
安装jdk11
使用win+X键,并选择Windows终端
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GY7Bzyl7-1650982517740)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420202133767.png)]](https://img-blog.csdnimg.cn/22d1b3007b2a4ea286926b05ee0bcbf5.png)
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jSEXSP3J-1650982517740)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420202251028.png)]](https://img-blog.csdnimg.cn/5f851d70cd2e4eb6b1fa59d723be6412.png)
输入
cd F:\soft\elk
dir
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5Cur3xeu-1650982517741)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420202824707.png)]](https://img-blog.csdnimg.cn/78ad933da87445ed9d1b87c19e6003c3.png)
打开window搜索框搜索环境变量,打开编辑系统环境变量
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kXjAYeAv-1650982517741)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420203326862.png)]](https://img-blog.csdnimg.cn/06697518bafb4293b4299f1b16074100.png)
点击环境变量
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PozDjn3n-1650982517742)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420203449479.png)]](https://img-blog.csdnimg.cn/f246bfdf609a43a6b3df244830a11fa9.png)
添加JAVA_HOME路径
F:\soft\elk\jdk-11.0.13_windows-x64_bin\jdk-11.0.13
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UHOzoqff-1650982517742)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420205025647.png)]](https://img-blog.csdnimg.cn/af06629927d34a1c8a0480bc8984a9fb.png)
将java执行路径添加到Path变量中,输入
%JAVA_HOME%\bin
%JAVA_HOM%\jre\bin
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-r1YdIZGU-1650982517743)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420203823640.png)]](https://img-blog.csdnimg.cn/20fe18bd6aa14954ab66562d88e952e7.png)
新打开一个shell(一定要重新打开一个新的shell才会加载刚配置过的jdk11环境变量)
并执行命令,可以看到jdk11提示输出,表示jdk11安装成功
java -version
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-k2hr9SWx-1650982517743)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420214822004.png)]](https://img-blog.csdnimg.cn/86ccac7d05a74a63bb6239a83a7dd2f7.png)
启动elasticsearch
启动新的shell,并执行命令
cd F:\soft\elk
.\elasticsearch-7.16.0-windows-x86_64\elasticsearch-7.16.0\bin\elasticsearch.bat
如果本地使用localhost访问,不需要修改配置文件,否则需要修改如下
network.host: 0.0.0.0
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mudaFWwp-1650982517744)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423214458423.png)]](https://img-blog.csdnimg.cn/3c252b5bbfc2458cb0c18ad8769ced40.png)
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QhT6ahbV-1650982517744)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420204714883.png)]](https://img-blog.csdnimg.cn/a464acc979544a9b90d743562b57f62a.png)
可以看到elasticsearch执行成功
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yXVfRQmx-1650982517745)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420215030696.png)]](https://img-blog.csdnimg.cn/14b35200346f40ec92ae03a3c4667061.png)
启动kibana
启动新的shell,并执行命令
cd F:\soft\elk
.\kibana-7.16.0-windows-x86_64\kibana-7.16.0-windows-x86_64\bin\kibana.bat
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5LEZYmNQ-1650982517745)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420215355755.png)]](https://img-blog.csdnimg.cn/a4e1094e9df6481ba633948a386c229e.png)
可以看到执行成功
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8PcUKiDE-1650982517746)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420215454109.png)]](https://img-blog.csdnimg.cn/bdbefc9b26b34cad9cd5a33c94ca2166.png)
访问网站,可以看到启动成功
http://localhost:5601/app/home#/
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-L7KOP3WE-1650982517746)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420215557167.png)]](https://img-blog.csdnimg.cn/3d1aafb5456246ceb81986a2aab5bd50.png)
点击Explore on my own
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-AIGFhhA7-1650982517747)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423144541137.png)]](https://img-blog.csdnimg.cn/93bc396b260f4f5cb631510b0ee73db2.png)
启动logstash
在logstash配置文件中,新增文件名log.conf
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HI3UJ5xK-1650982517747)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420220239744.png)]](https://img-blog.csdnimg.cn/491f808249144eaea2e59e67de8c2d0c.png)
内容如下:
输入指定通过5044端口使用Filebeat接收数据。
指定在elasticsearch中创建test的索引,将数据输出到test索引中。
input {
beats {
port => 5044
}
}
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "test"
}
}
启动新的shell,并执行命令
cd F:\soft\elk
.\logstash-7.16.0-windows-x86_64\logstash-7.16.0\bin\logstash.bat -f D:\conf\logstash-8.1.0-windows-x86_64\logstash-8.1.0\config\log.conf

可以看到启动成功

启动filebeat
新建日志log测试日志文件夹
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UtCfe7cj-1650982517748)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420221138864.png)]](https://img-blog.csdnimg.cn/1c4516757925427ca52a10262a58ae72.png)
进入log文件夹,创建data.log文件
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vyEY1SCK-1650982517749)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420221231158.png)]](https://img-blog.csdnimg.cn/42439654224b4b41b774d41d5cb9c3d5.png)
内容为
[08/Nov/2019:11:40:24 +0800] tc-com.net - - 192.168.12.58 192.168.12.58 192.168.15.135 80 GET 200 /geccess/services/capability/L6JN4255 ?pageIndex=1&pageSize=2000&vehicleType=0 21067 17 totalTime:54ms
[08/Nov/2019:11:40:24 +0800] tc-com.net - - 192.168.12.58 192.168.12.58 192.168.15.135 80 GET 200 /geccess/services/capability/L6JN4255 ?pageIndex=1&pageSize=2000&vehicleType=0 21067 17 totalTime:63ms
[08/Nov/2019:11:40:24 +0800] tc-com.net - - 192.168.12.58 192.168.12.58 192.168.15.135 80 GET 200 /geccess/services/capability/L6JN4255 ?pageIndex=1&pageSize=2000&vehicleType=0 21067 17 totalTime:75ms
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Rh0XjjNA-1650982517749)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420221403224.png)]](https://img-blog.csdnimg.cn/650299ac7fb24f8496afcca10bf7b59e.png)
编辑filebeat文件
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-cwtil5RN-1650982517750)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420221433916.png)]](https://img-blog.csdnimg.cn/9539c36e2e664812b7805c06d87e0b51.png)
将enable改成true,同时设置日志路径为
F:\soft\elk\log\*.log

将filebeat.config.modules的enable改成true
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PHjGM6Ln-1650982517751)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423144213743.png)]](https://img-blog.csdnimg.cn/322656c0f3ae41d49c00c3a48d5e77eb.png)
将输出到elasticsearch中使用#注释去掉,并将输出到logstash注释删除掉
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UaIm5SRp-1650982517751)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420221708300.png)]](https://img-blog.csdnimg.cn/604b192dfc50468d8545d5cbd710ca2c.png)
cd F:\soft\elk
.\filebeat-7.16.0-windows-x86_64\filebeat.exe -e -c F:\soft\elk\filebeat-7.16.0-windows-x86_64\filebeat.yml
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ZPeFdsyc-1650982517751)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220420222240061.png)]](https://img-blog.csdnimg.cn/6fa3142416564d9ba80fd78ddba5f5ef.png)
可以看到filebeat运行成功
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-a1vR2LBy-1650982517752)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423144343293.png)]](https://img-blog.csdnimg.cn/7d9a313011b343739daf7e8e8c648d97.png)
kibana查询日志
命令查询创建的索引数据
访问网站,并点击左上角
http://localhost:5601/app/home#/

左侧向下滑动,选中management,并点击Dev Tools
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yx5gzdLw-1650982517753)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423144617902.png)]](https://img-blog.csdnimg.cn/30d6fb514eef49c9b813bb9c2e34f3cc.png)
在Console输入下面命令
GET /_cat/indices?v
在点击绿色执行按钮,可以看到,索引test已经创建
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9ZTXTByS-1650982517753)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423144938859.png)]](https://img-blog.csdnimg.cn/c76eeef53907418c8ed1d4bea1c8c6c2.png)
输入下面命令,查询索引test的数据,可以看到日志数据已经成功上传
GET test/_search
{
"query": {
"match_all": {}
}
}
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-y0GYYIvY-1650982517753)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423145332557.png)]](https://img-blog.csdnimg.cn/2d6a57732a4247468dc78312a9084ca4.png)
通过界面查看和索引日志数据
点击Stack Management
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7jrL9Ijp-1650982517754)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423145805250.png)]](https://img-blog.csdnimg.cn/c2dd32bb5b3b445c892723e464f4d627.png)
选择Index Patterns

输入索引名称test,可以看到有匹配的,选择时间字段为@timestamp,点击Create Index pattern
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ZQxqJs3p-1650982517756)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423150226384.png)]](https://img-blog.csdnimg.cn/df74c5e413234b42a460de99d24465f7.png)
看到创建成功
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6NdIMLsK-1650982517756)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423150259353.png)]](https://img-blog.csdnimg.cn/63079ea46d2f4c9e8c6b07a96304c3bf.png)
选择Discover
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wNH6lY3A-1650982517757)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423150342241.png)]](https://img-blog.csdnimg.cn/e6255899ff5b41159b2cf03556aa4db9.png)
可以看到默认为test索引
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8kXBFOcK-1650982517757)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423150404995.png)]](https://img-blog.csdnimg.cn/f458eb61858041f98646402d1ea4de4f.png)
选择时间范围大一点
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jOMCB58K-1650982517757)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423150440112.png)]](https://img-blog.csdnimg.cn/5bebb18508234d4292f72c4285da813c.png)
点击Update
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zcTLOozG-1650982517758)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423150502069.png)]](https://img-blog.csdnimg.cn/e240821f30f844168320cc58bf8b9882.png)
可以看到数据完全被加载出来
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sF395OA6-1650982517758)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423150517409.png)]](https://img-blog.csdnimg.cn/958576a47c20466189093393548950bd.png)
通过关键词totalTime搜索,点击Refresh,可以看到下面搜索高量的部分
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DXEg3AMC-1650982517759)(https://raw.githubusercontent.com/panguchuangshi/hexo-img/main/img/image-20220423150630046.png)]](https://img-blog.csdnimg.cn/7609a63248754026b81d7c93f7c8d3f5.png)
总结
可以看到一个简单的日志收集系统搭建成功,我们可以根据这套系统收集日志,并做分析,本文只是针对window版本的介绍,后续会在linux版本搭建一套,步骤基本一致,更多实用搜索功能敬请期待。
|