第二篇:Filebeat 安装配置

Filebeat 简介:Filebeat 是一款轻量型日志收集工具,可转发汇总日志、文件等内容。

                        其主要特点为:1. 断点续传。(如遇日志转发过程中网络中断,会在恢复后从断开的点继续转发)

                                                2. 自适应转发速率。(当logstash 处理内容满载时会通知filebeat 转发率减少,当logstash 处于轻松状态,Filebeat则加大转发)

 

一、 安装Filebeat:

  1. 登陆cpy01.dev.xjh.com(需要下载其他版本请点击:https://www.elastic.co/cn/downloads/beats/filebeat )

wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.6.1-linux-x86_64.tar.gz -O /opt/filebeat-5.6.1.tar.gz
tar xf filebeat-5.6.1.tar.gz  -C /usr/local/
mv /usr/local/filebeat-5.6.1-linux-x86_64 /usr/local/filebeat-5.6.1

 2. 将/usr/local/filebeat-5.6.1 整个目录拷贝到cpy02.dev.xjh.com和cpy03.dev.xjh.com服务器的/usr/local/目录下

scp -r /usr/local/filebeat-5.6.1 [email protected]:/usr/local/
scp -r /usr/local/filebeat-5.6.1 [email protected]:/usr/local/

二、Filebeat配置文件说明:

Filebeat 作为输出工具,可向多种收集工具发送内容,如:logstash(本实验采用直接输出至logstash)、Elasticsearch、kafka、rabbitmq、redis等......

filebeat.yml 简述:

        yml 文件以键值对形式存在,均已相同缩进代表相同级别,列表由'-' 表示,配置文件采用折叠式命名规范,如:

  

filebeat:
    prospectors:
- input_type :  log
  paths:
- /var/log/message.log
- /usr/local/logs/business.log
意思是:捕获 filebeat.prospectors.0.input+type: log.0./var/log/message.log
和filebeat.prospectors.0.input+type: log.1./usr/local/logs/business.log 两个日志文件

  一般折叠式写成:

filebeat.prospectors:
- input_type :  log
   paths: ["/var/log/message.log","/usr/local/logs/business.log"]

   filebeat.prospectors:    #filebeat 命名规范,表示捕获文件开始

        - input_type :  log     #表示捕获数据类型为log

        paths: ["/var/log/message.log","/usr/local/logs/business.log"] #表示日志文件路径

三、配置Filebeat

  1. 配置输出至logstash

#=========================== Filebeat prospectors =============================
#=========================== 定义捕获的日志文件   =============================
 
filebeat.prospectors:
    - input_type: log
      paths: ["/usr/local/apache-tomcat-7.0.57/logs/*"]
 
 
    - input_type: stdin
#======================== Filebeat Global =====================================
#======================== Filebeat 全局配置 ===================================
filebeat.config_dir:/usr/local/filebeat-5.6.1   #定义filebeat 配置文件目录路径
 
 
#========================= Filebeat Config prospectors=========================
#========================= 配置重新加载配置文件       =========================
filebeat.config.prospectors:
    path : configs/filebeat.yml
    reload.enabled : true
    reload.period : 10s
 
#------------------------- Logstash Output ------------------------------------
#------------------------- 配置输出到logstash ---------------------------------
 
output.logstash:
    hosts: ["cpy04.dev.xjh.com:5044"]  #该列表如果为多个,则采用负载均衡模式发送到列表中的logstash服务器

  2. 配置输出至 kafka

#----------------------------- Kafka output --------------------------------
output.kafka:
  hosts: ["kafka01.dev.xjh.com:9092"]
  topic: "topicname"
  partition.round_robin:
    reachable_only: false
  required_acks: 1
  compression: gzip
  max_message_bytes: 1000000

   3. 配置输出至 elasticsearch

#----------------------------- Elasticsearch output --------------------------------
output.elasticsearch:
hosts:["http://elastic.dev.xjh.com:9200"]
username: "elasticsearch-username"
password: "elasticsearch-password"
template.enabled:true
template.path:"filebeat.template.json"
template.overwrite:false
index:"index-name"
ssl.certificate_authorities:["/etc/pki/root/ca.pem"]
ssl.certificate:"/etc/pki/client/cert.pem"
ssl.key:"/etc/pki/client/cert.key"

   4. 配置输出至 redis

#----------------------------- Elasticsearch output --------------------------------
output.redis:
hosts: ["redis.dev.xjh.com"]
password: "redis-password"
key: "filebeatkeysname"
db: 0
timeout: 10

  5. 配置输出至 console

#-------------------------- Console output ------------------------------
output.console:
  pretty: true

四、检测配置文件是否有效(如无效,大多为缩进引起):

sudo /usr/local/filebeat-5.6.1/filebeat -configtest /usr/local/filebeat-5.6.1/filebeat.yml

五、 启动Filebeat服务:

sudo /usr/local/filebeat-5.6.1/filebeat -c /usr/local/filebeat-5.6.1/filebeat.yml 2>&1 &

  

  

  

     

 

猜你喜欢

转载自www.cnblogs.com/cpy-devops/p/9287498.html