作者介绍:简历上没有一个精通的运维工程师,下面的思维导图也是预计更新的内容和当前进度(不定时更新)。
中间件,我给它的定义就是为了实现某系业务功能依赖的软件,包括如下部分:
Web服务器
代理服务器
ZooKeeper
Kafka
RabbitMQ
Hadoop HDFS
Elasticsearch ES (本章节)
上个小节我们使用了curl命令对ES基本的基本的写入和查询,实际上我们真实的环境都会使用Beats组件来进行数据写入,他也是ES官方给我们提供的数据写入工具。
Elasticsearch Beats 是 Elastic Stack (ELK Stack) 生态系统中一组轻量级、单一用途的数据采集器。它们被设计用来将各种类型的数据从成百上千台机器和系统轻松、高效地发送到 Elasticsearch 或 Logstash 进行集中存储和分析。
主要成员(官方 Beats):Filebeat
1.安装Filebeat
#这里选择的是和es完全一致的版本
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.17.29-x86_64.rpm
rpm -ivh filebeat-7.17.29-x86_64.rpm
2.配置Filebeat
[root@localhost filebeat]# cat filebeat.yml
filebeat.inputs:
- type: filestream
enabled: true
paths:
- /var/log/nginx/access.log
- /var/log/nginx/error.log
fields:
log_type: "nginx"
fields_under_root: true
output.elasticsearch:
hosts: ["192.168.31.171:9200", "192.168.31.172:9200", "192.168.31.173:9200"]
index: "nginx-%{+yyyy.MM.dd}-%{+HHmm}" # 自定义索引名,每分钟一个索引
# 必须添加的模板配置
setup.template:
name: "nginx_template"
pattern: "nginx-*"
enabled: true
overwrite: true
setup.ilm.enabled: false # 禁用ILM
3.启动Filebeat
Filebeat会维持读取的日志的偏移量,也就是如果Filebeat意外中断,重启恢复以后,他会接着上次的地方继续提交日志,避免重复提交。
systemctl enable filebeat
systemctl start filebeat
#Filebeat 的 注册表文件(Registry File),记录文件上传位置
[root@localhost filebeat]# ll /var/lib/filebeat/registry/filebeat/
total 5188
-rw------- 1 root root 3985404 Aug 5 22:11 log.json
-rw------- 1 root root 15 Aug 5 21:55 meta.json
[root@localhost filebeat]#
4.检查索引
这里刚好还有一个索引刚刚创建,因为数据还未同步,还没有变成green状态。当然这个由于未单独定义,使用的默认配置1分区,1副本。
[root@localhost nginx]# curl -XGET 'http://192.168.31.171:9200/_cat/indices'
green open nginx-2025.08.05-2156 SzGsufACQXathMWsio1Bqg 1 1 55458 0 9.2mb 4.6mb
green open nginx-2025.08.05-2200 rYbTn5C6QDqy_OgXfLPLIQ 1 1 24476 0 4.1mb 2mb
green open nginx-2025.08.05-2201 6PDT9FOdRVGGkWw-YApjcQ 1 1 31448 0 5mb 2.7mb
green open nginx-2025.08.05-2157 WZ62OI21QrOpbPddK_WXDg 1 1 25326 0 4.3mb 2.1mb
yellow open nginx-2025.08.05-2202 3aO7sXbBTESv9HBf812eBA 1 1 1826 0 219.2kb 219.2kb
green open nginx-2025.08.05-2158 dndUfDKTRi6TZ7aOEPMxaw 1 1 23726 0 4mb 2mb
green open nginx-2025.08.05-2159 vP78Dg7MR_qCw5_1dYEIzA 1 1 39462 0 7.4mb 3.4mb