通过ELK快速搭建集中化日志平台
ELK就是ElasticSearch + LogStash + Kibana
1、准备工作
ELK下载:https://www.elastic.co/downloads/
jdk version:1.8.0_162
平台:centos6.5
2、环境搭建
ElasticSearch:
(1)不能使用root用户启动,需将elasticsearch文件夹放在执行用户目录下,否则会报错:“错误: 找不到或无法加载主类 org.elasticsearch.tools.launchers.JavaVersionChecker”
(2)插件安装:bin/elasticsearch-plugin install x-pack
(3)修改配置文件 vim config/elasticsearch.yml
cluster.name: myapp
node.name: node0
path.data: /path/to/data
path.logs: /path/to/logs
network.host: 127.0.0.1(若要局域网访问,需要添加端口或直接关闭防火墙)
http.port: 9200
bootstrap.system_call_filter: false(add)
xpack.security.enabled: false(取消用户登陆的验证)
注:尽量保持冒号前面没空格,后面一个空格,不要用tab键,否则会报错:“Exception in thread "main" 2017-11-10 06:29:49,106 main ERROR No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'log4j2.debug' to show Log4j2 internal initialization logging.ElasticsearchParseException[malformed, expected settings to start with 'object', instead was [VALUE_STRING]]”
vim /etc/security/limits.d/90-nproc.conf
elasticsearch soft nproc 4096 # 针对 max number of threads
elasticsearch hard nproc 4096
elasticsearch soft nofile 65536 # 针对 max file descriptors (add)
elasticsearch hard nofile 65536
vim /etc/sysctl.conf
vm.max_map_count=262144 # 针对 max virtual memory areas(add) (sysctl -p 使生效)
Kiabna
(1)解压后,执行“./bin/kibana-plugin install x-pack”安装X-Pack
(2)修改配置文件kibana.yml
elasticsearch.url: "http://192.168.11.13:9200"
server.host: "192.168.11.13"
logstash
(1)解压后,执行“./bin/logstash-plugin install x-pack”安装X-Pack
(2)修改配置文件logstash.yml,添加如下
xpack.monitoring.enabled: true
xpack.monitoring.elasticsearch.url: ["http://192.168.11.13:9200"]([]中填写elasticsearch运行后能访问到的IP和端口)
(3)添加配置文件:logstash.conf
input {
file {
path => "/home/elsearch/error.log"
type => "error"
start_position => "beginning"
}
}
output {
elasticsearch {
hosts => ["192.168.11.13:9200"]
index => "error-%{+YYYY.MM.DD}"
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具