Elastic stack 是指由Elasticsearch、Logstash、Kibana和Kafka、Filebeat组成的日志分析平台,即传统的ELK加上Kafka和Filebeat,可以将系统、网站、应用等日志进行收集、过滤、清洗,然后进行集中存放,最终用于实时检索和分析。

本文介绍如何在主机上安装并配置Filebeat。
点击此处访问Filebeat下载地址,本文以7.6.2版本为例,下载后解压并编辑配置文件。
| 
					 1 2 3  | 
						wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.6.2-linux-x86_64.tar.gz # 下载32位版本 # wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.6.2-linux-x86.tar.gz  | 
					
以下是CentOS7下yum安装方法:
| 
					 1  | 
						rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch  | 
					
修改配置/etc/yum.repos.d/filebeat.repo:
| 
					 1 2 3 4 5 6 7 8  | 
						[elastic-7.x] name=Elastic repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md  | 
					
| 
					 1  | 
						yum -y install filebeat  | 
					
配置Filebeat
将日志输出至kafka,注意行首的空格,修改配置filebeat.yml:
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28  | 
						filebeat.inputs: - type: log   enabled: true   paths:     - /var/log/nginx/access_json.log #  exclude_lines: ['Info'] #  multiline.pattern: '^\[' #  multiline.negate: true #  multiline.match: after #  ignore_older: 3h filebeat.config.modules:   path: ${path.config}/modules.d/*.yml   reload.enabled: false setup.template.settings:   index.number_of_shards: 3 #fields: #  appname: App_Name output.kafka:   hosts: ["10.10.200.201:9092","10.10.200.202:9092","10.10.200.203:9092"]   topic: 'Topic_Name'   partition.round_robin:     reachable_only: true   required_acks: 1 #  compression: gzip #  max_message_bytes: 1000000 processors:   - add_host_metadata: ~   - add_cloud_metadata: ~  | 
					
启动filebeat
根据实际情况选择启动命令:
| 
					 1 2 3 4 5 6  | 
						# 方式一 systemctl start filebeat # 方式二 nohup ./filebeat -e -c filebeat.yml >/dev/null 2>&1 & # 方式三 nohup ./filebeat -e -c filebeat.yml &  | 
					
建议加入开机自启动,本文略。
常用命令
| 
					 1 2 3 4 5  | 
						# 启用kafka模块 ./filebeat modules enable kafka #禁用elasticsearch模块 ./filebeat modules disable elasticsearch  | 
					
至此,Elastic Stack 全套服务已经部署完毕。
原创文章禁止转载:技术学堂 » Elastic.stack集群部署课程六·Filebeat

技术学堂
					














