CentOS 6.8 ELK:搭建高效日志分析系统
简介


ELK(Elasticsearch、Logstash、Kibana)是一套强大的日志分析解决方案,广泛应用于大数据、日志收集、监控等领域,本文将详细介绍如何在CentOS 6.8系统上搭建ELK环境。
环境准备
- 操作系统:CentOS 6.8
- 硬件要求:CPU 2.0GHz以上,内存2GB以上
- 网络环境:公网IP,确保ELK三组件之间能够正常通信
安装步骤
安装Elasticsearch
(1)下载Elasticsearch安装包:https://www.elastic.co/cn/downloads/elasticsearch
(2)解压安装包:tar -zxvf elasticsearch-6.8.2.tar.gz
(3)进入Elasticsearch目录:cd elasticsearch-6.8.2
(4)配置Elasticsearch:
编辑elasticsearch.yml文件,添加以下内容:
network.host: 192.168.1.100
http.port: 9200 (5)启动Elasticsearch:
./bin/elasticsearch
安装Logstash
(1)下载Logstash安装包:https://www.elastic.co/cn/downloads/logstash
(2)解压安装包:tar -zxvf logstash-6.8.2.tar.gz
(3)进入Logstash目录:cd logstash-6.8.2
(4)配置Logstash:
编辑logstash.conf文件,添加以下内容:
input {
file {
path => "/var/log/*.log"
start_position => "beginning"
}
}
filter {
mutate {
add_tag => ["with_date"]
convert => {
"timestamp" => "date"
}
}
}
output {
elasticsearch {
hosts => ["192.168.1.100:9200"]
}
} (5)启动Logstash:

./bin/logstash -f logstash.conf
安装Kibana
(1)下载Kibana安装包:https://www.elastic.co/cn/downloads/kibana
(2)解压安装包:tar -zxvf kibana-6.8.2-darwin-x86_64.tar.gz
(3)进入Kibana目录:cd kibana-6.8.2-darwin-x86_64
(4)启动Kibana:
./bin/kibana
测试
在浏览器中输入:http://192.168.1.100:5601
在Kibana首页,选择“Dev Tools”,输入以下命令,查看Elasticsearch索引:
GET /_cat/indices?v 查看Logstash日志,确认数据已成功传输到Elasticsearch:
tail -f /var/log/logstash/logstash.log FAQs
问题:Elasticsearch启动失败,报错“max virtual memory areas vm.max_map_count is too low,increase to at least [XXX]”
解答:修改sysctl.conf文件,添加以下内容:
vm.max_map_count = 262144 然后执行:
sysctl -p 问题:Kibana无法连接到Elasticsearch
解答:检查Elasticsearch的配置文件elasticsearch.yml,确保network.host和http.port与实际配置一致。

