CentOS上的Filebeat与Elasticsearch的集成可以通过以下步骤实现:
首先,你需要在CentOS上安装Filebeat。你可以从Elastic官方网站下载最新版本的Filebeat,并按照官方文档进行安装。
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.10.0-amd64.deb
sudo dpkg -i filebeat-7.10.0-amd64.deb
安装完成后,你需要配置Filebeat以将日志发送到Elasticsearch。编辑/etc/filebeat/filebeat.yml
文件,进行如下配置:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["localhost:9200"]
index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
在这个配置中:
filebeat.inputs
定义了Filebeat要监控的日志文件路径。output.elasticsearch
定义了Elasticsearch的主机和索引名称。配置完成后,启动Filebeat服务:
sudo systemctl start filebeat
sudo systemctl enable filebeat
如果你还没有安装Elasticsearch,可以从Elastic官方网站下载并安装。以下是安装Elasticsearch的简要步骤:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.0-linux-x86_64.tar.gz
tar -xzf elasticsearch-7.10.0-linux-x86_64.tar.gz
cd elasticsearch-7.10.0
然后编辑config/elasticsearch.yml
文件,确保以下配置:
network.host: 0.0.0.0
http.port: 9200
启动Elasticsearch服务:
./bin/elasticsearch
你可以通过以下命令检查Elasticsearch是否正常运行:
curl -X GET "localhost:9200"
如果Elasticsearch正常运行,你应该会看到类似以下的响应:
{
"name" : "your-node-name",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "your-cluster-uuid",
"version" : {
"number" : "7.10.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "unknown",
"build_date" : "2020-11-11T00:00:00.000Z",
"build_snapshot" : false,
"lucene_version" : "8.7.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
同时,你可以在Kibana中查看Filebeat发送的日志数据。
如果你还没有安装Kibana,可以从Elastic官方网站下载并安装。安装完成后,编辑/etc/kibana/kibana.yml
文件,确保以下配置:
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://localhost:9200"]
启动Kibana服务:
sudo systemctl start kibana
sudo systemctl enable kibana
然后,你可以通过浏览器访问http://your-server-ip:5601
来使用Kibana。
通过以上步骤,你应该能够成功地将CentOS上的Filebeat与Elasticsearch集成,并在Kibana中查看日志数据。