Graylog与ELK可以相提并论的一款集中式日志管理方案,支持数据收集、检索、可视化Dashboard。
简介
Graylog最小化架构设计:GrayLog:提供 GrayLog对外接口,具有报警选项的可插入日志和事件分析服务器。
Elasticsearch:一个基于Lucene的文档存储,主要用于日志索引、存储和分析。
MongoDB:存储一些 GrayLog 的配置信息。
Graylog群集架构图:
一体化方案,安装方便,不像ELK有3个独立系统间的集成问题。采集原始日志,并可以事后再添加字段,比如http_status_code,response_time等等。自己开发采集日志的脚本,并用curl/nc发送到Graylog Server,发送格式是自定义的GELF,Flunted和Logstash都有相应的输出GELF消息的插件。自己开发带来很大的自由度。实际上只需要用inotifywait监控日志的modify事件,并把日志的新增行用curl/netcat发送到Graylog Server就可。搜索结果高亮显示,就像google一样。搜索语法简单,比如: source:mongo AND reponse_time_ms:>5000,避免直接输入elasticsearch搜索json语法搜索条件可以导出为elasticsearch的搜索json文本,方便直接开发调用elasticsearch rest api的搜索脚本。
环境部署
Java安装$ yum install java-1.8.0-openjdk-headless.x86_64
MongoDB安装
准备yum源
$ vim /etc/yum.repos.d/mongodb-org-3.2.repo
$ yum install mongodb-org
启动服务
$ sudo chkconfig --add mongod
$ sudo systemctl daemon-reload
$ sudo systemctl enable mongod.service
$ sudo systemctl start mongod.service
Elasticsearch安装
$ rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
$ vim /etc/yum.repos.d/elasticsearch.repo
$ yum install elasticsearch
更改elasticsearch配置文件
$ vim /etc/elasticsearch/elasticsearch.yml
cluster.name: graylog
启动服务
$ chkconfig --add elasticsearch
$ systemctl daemon-reload
$ systemctl enable elasticsearch.service
$ systemctl restart elasticsearch.service
安装Graylog
$ rpm -Uvh https://packages.graylog2.org/repo/packages/graylog-2.3-repository_latest.rpm
$ yum install graylog-server
编辑配置文件 /etc/graylog/server/server.conf 添加 password_secret 、root_password_sha2,执行如下命令,将结果添加到分别添加到配置文件对应的部分。
$ yum install epel-release
$ yum install pwgen
$ pwgen -N 1 -s 96
将结果添加到 配置文件的password_secret 部分。
$ echo -n <pwd> | sha256sum
将结果添加到配置文件的 root_password_sha2 部分。
启动服务
$ sudo chkconfig --add graylog-server
$ sudo systemctl daemon-reload
$ sudo systemctl enable graylog-server.service
$ sudo systemctl start graylog-server.service
然后修改rest_listem_uri和web_listem_uri的IP地址修改为本机的IP。
rest_listen_uri = http://192.168.190.168:9000/api/
web_listen_uri = http://192.168.190.168:9000/
root_timezone = Asia/Shanghai
至此,graylog web已经安装完成,访问http://localhost:9000即可看到web界面。
官方文档:http://docs.graylog.org/en/3.0/pages/getting_started/configure.html
添加日志收集器
测试
执行命令:# echo 'date' | nc 127.0.0.1 5555
安装成功
GELF (Graylog Extended Log Format) 可以接收结构化的事件, 支持压缩(GZIP’d or ZLIB’d)和分块。
GELF message:
version string host string short_message string full_message string timestamp number level number facility string line number file string _[additional field] string or number, 通过 _ 前缀添加自定义的字段
测试命令:
# curl -XPOST http://127.0.0.1:12201/gelf -p0 -d '{"short_message":"Hello jncsy!", "host":"jncsy.org", "facility":"测试", "_foo":"bar"}'
以上简单测试搭建。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。