如何将本地的日志写入到es集群

如何将本地的日志写入到es集群,第1张

将node.name的值设置为test-node2,总之必须和之前配置值不同。

两台es服务同时起来,因为配置文件中均默认cluster.name=elasticsearch,所以这两台机器自动构建成一个集群,集群名字为elasticsearch。

3、elasticsearchservicewrapper安装

这个是对elasticsearch执行命令的包装服务,安装之后,方便elasticsearch的启动,停止等等 *** 作。

(1)下载elasticsearchservicewrapper

安装准备:

filebeat-6.6.0-linux-x86_64.tar.gz

elasticsearch-6.2.4.tar.gz

强烈建议filebeat和es采用一个大版本,否则可能造成意向不到的问题!

elasticsearch-7.XX需要更高版本的java(11),而提高es的版本也需要提高filebeat的版本!

安装步骤:

[if !supportLists]1、 [endif]上传elasticsearch-6.2.4.tar.gz安装包,tar -zxvf elasticsearch-6.2.4.tar.gz 解压。

[if !supportLists]2、 [endif]创建es用户和用户组,并将es的目录权限赋予es用户和用户组(ES不能用root启动)

[if !supportLists]3、 [endif]配置好集群参数,启动es

[if !supportLists]4、 [endif]使用命令(如url http://localhost:9200)返回结果意味集群启动没有问题

[if !supportLists]5、 [endif]上传filebeat-6.6.0-linux-x86_64.tar.gz安装包至采集机,tar -zxvf filebeat-6.6.0-linux-x86_64.tar.gz解压。

[if !supportLists]6、 [endif]切至安装目录,vim filebeat.yml修改对应内容,如图:(注意配置文件缩进)

调度平台的日志默认存放在/logs/logs.log中,es集群配置多个可以用“,”隔开。如:

hosts:["10.10.31.5:9200","10.10.31.6:9200"]

配置文件设置

#filebeat.yml

filebeat.inputs:

- type: log

  enabled: true

  paths:

  - /logs/logs.log

  #请给出日志文件名

  json.keys_under_root: true

  json.overwrite_keys: true

  exclude_files: ['.gz$']

  #     fields:

  #     component: nginx        #添加标签,字段名不可与日志中重复

  fields_under_root: true

  tail_files: true

processors:

- drop_fields:

    fields: ["ecs","agent","host","input"]

logging:

  files:

    rotateeverybytes: 10485760

output.elasticsearch:

  hosts: ["10.2.15.54:9200"]

7、命令nohup ./filebeat -e -c filebeat.yml >filebeat.log &启动

8、验证命令./filebeat test output,输出结果如图则正常:

9、查看es是否正常接收到日志

日志增大,则代表正常,可尝试使用

curl -H "Content-Type: application/json" http://10.2.15.54:9200/filebeat-6.6.0-2021.11.02/_search -d '{"query":{"term":{"ruleCode":{"value":"test02","boost":1.0}}}}'

命令进行验证


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/7374294.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-04
下一篇 2023-04-04

发表评论

登录后才能评论

评论列表(0条)

保存