Graylog:强大的日志管理系统
Graylog是一款开源的日志管理系统,可以从任何来源解析和丰富日志消息,有线和事件数据,从而为第三方收集器(如fluentd,beats和nxlog)提供集中式配置管理系统。 例如,使用Graylog可以丰富使用从IP地址转换的地理坐标的日志消息,或将用户ID映射到用户名。
特征
Graylog最著名的功能包括:
- 中央日志管理系统,使您的团队可以访问运行时配置和日志数据,而无需接触Graylog服务器。
- 将用户分组到角色以简化权限管理。 Graylog有一个非常强大的系统来限制用户的数据访问,这真的很方便。
- LDAP集成
- REST API用于编程日志访问数据。
目标
先决条件
- 一台运行Ubuntu 16.04至少有2GB RAM的服务器。
- MongoDB. http://www.linuxidc.com/Linux/2017-07/145526.htm
- Elasticsearch 2.x. http://www.linuxidc.com/Linux/2017-07/145588.htm
- Oracle JDK 8. http://www.linuxidc.com/Linux/2017-07/145563.htm
入门
如果您的系统符合上述先决条件,则可以启动Graylog 2安装过程。
运行命令更新服务器:
$ sudo apt-get update && sudo apt-get upgrade $ sudo apt-get install apt-transport-https uuid-runtime pwgen
配置 Elasticsearch
如上所述,Graylog 2.0.0(及更高版本)需要Elasticsearch 2.x. 您需要修改Elastisearch配置文件:/etc/elasticsearch/elasticsearch.yml,设置集群名称,使其与Graylog配置文件中的集合名称相匹配。 在本教程中,选择的群集名称为graylog。
使用文本编辑器,打开Elasticsearch配置文件:
$ sudo $EDITOR /etc/elasticsearch/elasticsearch.yml
搜索cluster.name行并取消注释。 接下来,修改如下:
# ---------------------------------- Cluster ----------------------------------- # # Use a descriptive name for your cluster: # cluster.name: graylog #
保存并关闭文件,然后重新启动Elasticsearch服务:
$ sudo systemctl restart elasticsearch
安装 Graylog
一旦服务器配置完成,我们可以转到Graylog安装。 使用以下命令配置Graylog存储库:
$ wget https://packages.graylog2.org/repo/packages/graylog-2.2-repository_latest.deb $ sudo dpkg -i graylog-2.2-repository_latest.deb
接下来,安装包:
$ sudo apt-get update && sudo apt-get install graylog-server
在安装过程结束时,启用Graylog以在引导时启动:
$ systemclt enable graylog-server
在启动Graylog之前,我们需要配置它。
配置 Graylog
Graylog配置文件是/etc/graylog/server/server.conf。 在我们可以启动日志管理程序之前,必须先编辑这个文件中的一些参数。
首先,我们需要设置password_secret值。 这个长度必须至少为64个字符。 我们将使用pwgen生成它。
您可以使用apt安装此工具:
$ sudo apt-get install pwgen
接下来,使用sed,我们将生成的字符直接写入到Graylog配置文件中:
$ sudo -E sed -i -e "s/password_secret =.*/password_secret = $(pwgen -N 1 -s 128)/" /etc/graylog/server/server.conf
为了检查一切是否正确完成,请使用以下代码:
$ cat /etc/graylog/server/server.conf | grep password_secret
该命令应显示password_secret行。我们的情况如下
password_secret = hjg5nBbZQcgLVW3do5uw1irfbq9UiRwhISZgPie8r96dejt4hgWdHUJcIaK1onQfFFatbrPZ3WV4yEhoqX9ITtaEUmn9SKn2aRT62uCO9KRZGK81q2xrO1aMQnOELPqP
下一步是设置root_password_sha2,这是我们所需密码的SHA-256散列。 首先,执行以下命令:
$ sudo sed -i -e "s/root_password_sha2 =.*/root_password_sha2 = $(echo -n 'your_password' | shasum -a 256 | cut -d' ' -f1)/" /etc/graylog/server/server.conf
为了能够连接到Graylog,我们还必须将rest_listen_uri和web_listen_uri值配置为可以连接到的机器的主机名或公共IP地址。 Web界面URI和REST API必须由使用Web界面的所有人访问,这意味着Graylog必须在公共网络接口上侦听。
打开Graylog配置文件:
$ sudo $EDITOR /etc/graylog/server/server.conf
在此文件中,搜索rest_listen_uri行,默认情况下为:
# REST API listen URI. Must be reachable by other Graylog server nodes if you run a cluster. # When using Graylog Collectors, this URI will be used to receive heartbeat messages and must be accessible for all collectors. rest_listen_uri = http://127.0.0.1:9000/api/
将127.0.0.1替换为服务器公用IP。
接下来,搜索web_liste_uri行:
# Web interface listen URI. # Configuring a path for the URI here effectively prefixes all URIs in the web interface. This is a replacement # for the application.context configuration parameter in pre-2.0 versions of the Graylog web interface. #web_listen_uri = http://127.0.0.1:9000/
取消注释,并更改IP,就像在rest_listen_api步骤中所做的那样。
保存并关闭文件,然后启动Graylog:
$ sudo systemctl start graylog-server
使用以下代码检查Graylog状态:
$ sudo systemctl status graylog-server
graylog-server.service - Graylog server Loaded: loaded (/usr/lib/systemd/system/graylog-server.service; enabled; vend Active: active (running) ...
测试 Graylog
使用客户端上的Web浏览器,请访问http://192.168.1.138:9000/。 浏览器将显示登录页面
使用admin作为用户名,并在配置步骤('your_password')中输入密码。
登录后,您将看到一个“入门”页面:
通过进入系统System>输入Inputs,我们可以访问输入配置。
这是配置所有输入的地方,这是Graylog中用于日志管理的数据收集的第一步。
结论
在这一点上,我们有一台Graylog服务器在Ubuntu 16.04机器上正确启动并运行。 在将来的指南中,我们将看到如何配置输入并将数据从服务器发送到这个强大的日志管理系统。
我们还将了解如何配置多节点Graylog系统,以实现更高级的日志管理。
完整PDF文档可以到Linux公社资源站下载:
------------------------------------------分割线------------------------------------------
具体下载目录在 /2017年资料/7月/15日/Ubuntu 16.04上安装配置 Graylog 2 日志管理系统/
------------------------------------------分割线------------------------------------------