作者 GitiJun 2019.08.26 09:28:02 写了58篇文章,回复33人, 在Windows服务器上安装ELK V7 阅读:1515· 评论:0· 喜欢:1 在Windows服务器上安装ELK ------ ElasticSearch是一个基于Lucene的开源分布式搜索服务器。它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是第二流行的企业搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。 在elasticsearch中,所有节点的数据是均等的。 Logstash是一个完全开源的工具,它可以对你的日志进行收集、过滤、分析,支持大量的数据获取方法,并将其存储供以后使用(如搜索)。说到搜索,logstash带有一个web界面,搜索和展示所有日志。一般工作方式为c/s架构,client端安装在需要收集日志的主机上,server端负责将收到的各节点日志进行过滤、修改等操作在一并发往elasticsearch上去。 Kibana 是一个基于浏览器页面的Elasticsearch前端展示工具,也是一个开源和免费的工具,Kibana可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。 ## 准备清单 ## 参考部署环境 - Os :Windows 7 以上 - logstash版本:logstash-2.2.1 - elasticsearch版本:elasticsearch-2.2.0 - kibana版本:kibana-4.4.2-windows - nxlog版本:2.8.1248 - Java版本:jdk-8 ## 下载源 Java: http://www.oracle.com/technetwork/java/javase/downloads/index.html Logstash: https://www.elastic.co/downloads/logstash Elasticsearch: https://www.elastic.co/downloads/elasticsearch Kibana: https://www.elastic.co/downloads/kibana Nxlog: http://nxlog.org/products/nxlog-community-edition/download Nssm: https://nssm.cc/download ## 帮助文档 Logstash https://www.elastic.co/guide/en/logstash/current/codec-plugins.html Elasticsearch https://www.elastic.co/guide/en/elasticsearch/guide/current/index.html Kibana https://www.elastic.co/guide/en/kibana/current/index.html Nxlog http://nxlog.org/docs nssm:https://nssm.cc/usage # 开始 ## 根据当前下载清单,软件清单都是新的,所以依赖环境也不相同 时间定位在 2019-08-21 此时各个版本情况如下: elasticsearch-7.3.0-windows-x86_64 (需要JDK11) kibana-7.3.0-windows-x86_64 logstash-7.3.0 nxlog-ce-2.10.2150 node-v10.16.3-x64 elasticsearch-head 由于Logstash服务依赖ES服务,Kibana服务依赖Logstash和ES,所以ELK的服务启动顺序为:ES->Logstash->Kibana,为了配合服务启动顺序,我们安装顺序和启动顺序保持一致。 ## 安装java ## 安装nxlog ## 启动elasticsearch 进入到 elasticsearch-6.4.2\bin 目录,地址栏 cmd 运行 elasticsearch-service.bat install 接着继续运行elasticsearch-service.bat manager 弹出的属性框中,配置 Startup type 为 Automatic,并且启动即可。默认内存1G。 访问 http://localhost:9200/ ``` { "name" : "DESKTOP-D9FT3SK", "cluster_name" : "elasticsearch", "cluster_uuid" : "A1ht8l1NRg6bFtzUTpwc2A", "version" : { "number" : "7.3.0", "build_flavor" : "default", "build_type" : "zip", "build_hash" : "de777fa", "build_date" : "2019-07-24T18:30:11.767338Z", "build_snapshot" : false, "lucene_version" : "8.1.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } ``` ### 安装插件 (V5,6,7版本开始用Node安装Head插件,其他低版本才用plugin命令方式安装) 注:es5以上版本安装head需要安装node和grunt(之前的直接用plugin命令即可安装) elasticsearch-plugin.bat install mobz/elasticsearch-head elasticsearch-plugin.bat install mobz/elasticsearch-head http://localhost:9200/_plugin/head/ 下面开始准备安装HEAD插件 从地址:https://nodejs.org/en/download/ 下载相应系统的msi,双击安装。 安装完成用cmd进入安装目录执行 node -v可查看版本号 执行 npm install -g grunt-cli 安装grunt ,安装完成后执行grunt -version查看是否安装成功,会显示安装的版本号 开始安装head 请参考 https://blog.csdn.net/weixin_41575259/article/details/82531276 进入es安装目录下的config目录,修改elasticsearch.yml文件.在文件的末尾加入以下代码 ``` http.cors.enabled: true http.cors.allow-origin: "*" # 参考页面这行要去掉,否则无法启动 node.master: true # 参考页面这行要去掉,否则无法启动 node.data: true ``` 然后去掉network.host: 192.168.0.1的注释并改为network.host: 0.0.0.0,去掉cluster.name;node.name;http.port的注释(也就是去掉#) ②双击elasticsearch.bat重启es 这时可能ES服务会有异常,先卸载服务 sc delete elasticsearch-service-x64,需要重新上面操作安装一次。 安装 ``` C:\ELK\elasticsearch-7.3.0\bin>sc delete elasticsearch-service-x64 [SC] DeleteService 成功 C:\ELK\elasticsearch-7.3.0\bin>elasticsearch-service.bat install Installing service : "elasticsearch-service-x64" Using JAVA_HOME (64-bit): "C:\Program Files\Java\jdk-11" -Xms1g;-Xmx1g;-XX:+UseConcMarkSweepGC;-XX:CMSInitiatingOccupancyFraction=75;-XX:+UseCMSInitiatingOccupancyOnly;-Des.networkaddress.cache.ttl=60;-Des.networkaddress.cache.negative.ttl=10;-XX:+AlwaysPreTouch;-Xss1m;-Djava.awt.headless=true;-Dfile.encoding=UTF-8;-Djna.nosys=true;-XX:-OmitStackTraceInFastThrow;-Dio.netty.noUnsafe=true;-Dio.netty.noKeySetOptimization=true;-Dio.netty.recycler.maxCapacityPerThread=0;-Dlog4j.shutdownHookEnabled=false;-Dlog4j2.disable.jmx=true;-Djava.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp\elasticsearch;-XX:+HeapDumpOnOutOfMemoryError;-XX:HeapDumpPath=data;-XX:ErrorFile=logs/hs_err_pid%p.log;-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m;-Djava.locale.providers=COMPAT;-Dio.netty.allocator.type=unpooled;-XX:MaxDirectMemorySize=536870912 The service 'elasticsearch-service-x64' has been installed. ``` 启动 ``` C:\ELK\elasticsearch-7.3.0\bin>elasticsearch-service.bat manager Successfully started service manager for 'elasticsearch-service-x64'. ``` 可能出现问题:ES服务启动后,10秒左右就停止了。 ③在https://github.com/mobz/elasticsearch-head中下载head插件,选择下载zip https://github.com/mobz/elasticsearch-head Running with built in server ``` git clone git://github.com/mobz/elasticsearch-head.git cd elasticsearch-head npm install npm run start ``` 下载PhantomJS可能失败导致安装失败 ``` PhantomJS not found on PATH Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-windows.zip Saving to C:\Users\ADMINI~1\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip Receiving... [===-------------------------------------] 7% Error making request. Error: read ECONNRESET at TLSWrap.onStreamRead (internal/stream_base_commons.js:111:27) ``` 直接下载 PhantomJS 到 上面提示路径(可以用迅雷下载,中途也会失败,重试就好了) 放入C:\Users\Administrator\AppData\Local\Temp\phantomjs\ 再安装尝试,即成功。 ``` npm WARN deprecated phantomjs-prebuilt@2.1.16: this package is now deprecated > phantomjs-prebuilt@2.1.16 install C:\ELK\elasticsearch-7.3.0\elasticsearch-head\node_modules\phantomjs-prebuilt > node install.js PhantomJS not found on PATH Download already available at C:\Users\ADMINI~1\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip Verified checksum of previously downloaded file Extracting zip contents Removing C:\ELK\elasticsearch-7.3.0\elasticsearch-head\node_modules\phantomjs-prebuilt\lib\phantom Copying extracted folder C:\Users\ADMINI~1\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip-extract-1566439029393\phantomjs-2.1.1-windows -> C:\ELK\elasticsearch-7.3.0\elasticsearch-head\node_modules\phantomjs-prebuilt\lib\phantom Writing location.js file Done. Phantomjs binary available at C:\ELK\elasticsearch-7.3.0\elasticsearch-head\node_modules\phantomjs-prebuilt\lib\phantom\bin\phantomjs.exe npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) added 67 packages from 69 contributors and audited 1768 packages in 31.608s found 40 vulnerabilities (19 low, 2 moderate, 19 high) run `npm audit fix` to fix them, or `npm audit` for details ``` 启动服务 C:\ELK\elasticsearch-7.3.0\elasticsearch-head>grunt server ``` Running "connect:server" (connect) task Waiting forever... Started connect web server on http://localhost:9100 ``` open http://localhost:9100/ This will start a local webserver running on port 9100 serving elasticsearch-head ### 安装 Logstash 在logstash文件夹的bin目录里新建logstash.conf配置文件,具体内容如下,具体参数可以自定义: 安装 Logstash打开 \logstash-6.4.2\config 目录创建 logstash-test.conf 文件, 内容为: ``` input { file { path => "E:/springcloud-log/elasticsearch-6.4.2/logs/*.*" start_position => "beginning" }}output { elasticsearch { hosts => ["localhost:9200"] }} ``` 地址 E:/springcloud-log/elasticsearch-6.4.2/logs/*.* , 该文件夹下可以放置一些日志文件,Logstash读取之后推给 Elasticsearch。 进入\logstash-6.4.2\bin 目录下 运行 cmd : logstash -f ..\config\logstash-test.conf 注意:这里要等一段时间,各位不要心急!!!! 启动脚本 ``` logstash -f ../config/logstash-test.conf logstash.bat -f ../config/logstash-test.conf ``` 配置文件内容 ``` # Sample Logstash configuration for creating a simple # Beats -> Logstash -> Elasticsearch pipeline. input { file { path => "C:/ELK/temp/logsource/*.*" start_position => "beginning" } } output { elasticsearch { hosts => ["http://localhost:9200"] } } ``` #### 注意 在Windows中,文件路径中分隔符要使用/而不是\。如果使用了\,那么*匹配将会失败。 作者:Lzc_Java 链接:https://www.jianshu.com/p/88b46dc1045f 来源:简书 简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。 ### 安装 Kibana Kibana 使用nssm安装服务,可以添加依赖服务,然后启动即可。 启动脚本用bin路径下的kibana.bat即可。 完成之后登入对应的网址 http://localhost:5601 https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html windows环境下搭建ELK(6.5.4版本) - 简书 https://www.jianshu.com/p/88b46dc1045f # 至此,ELK在windows上的环境全部部署完毕!!! 接下来就开始如何使用了 !!! 你知道的, 为了搜索… | Elasticsearch: 权威指南 | Elastic https://www.elastic.co/guide/cn/elasticsearch/guide/current/intro.html ``` Installing service : "elasticsearch-service-x64" Using JAVA_HOME (64-bit): "C:\Program Files\Java\jdk-11" -Xms1g;-Xmx1g;-XX:+UseConcMarkSweepGC;-XX:CMSInitiatingOccupancyFraction=75;-XX:+UseCMSInitiatingOccupancyOnly;-Des.networkaddress.cache.ttl=60;-Des.networkaddress.cache.negative.ttl=10;-XX:+AlwaysPreTouch;-Xss1m;-Djava.awt.headless=true;-Dfile.encoding=UTF-8;-Djna.nosys=true;-XX:-OmitStackTraceInFastThrow;-Dio.netty.noUnsafe=true;-Dio.netty.noKeySetOptimization=true;-Dio.netty.recycler.maxCapacityPerThread=0;-Dlog4j.shutdownHookEnabled=false;-Dlog4j2.disable.jmx=true;-Djava.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp\elasticsearch;-XX:+HeapDumpOnOutOfMemoryError;-XX:HeapDumpPath=data;-XX:ErrorFile=logs/hs_err_pid%p.log;-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m;-Djava.locale.providers=COMPAT;-Dio.netty.allocator.type=unpooled;-XX:MaxDirectMemorySize=536870912 The service 'elasticsearch-service-x64' has been installed. ``` # 注意事项 ### 在Windows服务器上安装ELK logstash在windows平台下不能监控磁盘文件,用nxlog代替,监控文件并把内容发送到logstash ## Java环境变量设置 ### Java11 点击环境变量->新建->变量名JAVA_HOME,变量值JDK11的安装目录如【C:\Program Files\Java\jdk-11\】 编辑Path变量 把括号中的变量【%JAVA_HOME%\bin;】 这个变量插入最前面,注意要有分号和后面的变量间隔开。 ### Java1.8 #### JAVA_HOME 变量 变量值:C:\Program Files\Java\jdk1.7.0 JAVA_HOME C:\Program Files (x86)\Java\jdk1.8.0_131 #### CLASSPATH 变量 变量值:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar; CLASSPATH .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar #### Path 变量 变量值:;%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin; Path中添加 C:\Program Files (x86)\Java\jdk1.8.0_131\bin C:\Program Files (x86)\Java\jre1.8.0_131\bin #### 确认安装成功 然后确认 java -version 或者 javac ### 参考网址 https://www.cnblogs.com/zella/p/8309646.html 赞 | 1 赏 标签:none