在本指南中,我们将带您完成在 CentOS 8 / RHEL 8 上使用 Elasticsearch 7.x 和 MongoDB 4.x 安装 Graylog 的步骤。Graylog 是一个开源日志管理系统,它允许系统管理员/开发人员从多个日志源聚合多达 TB 的日志数据。它具有高度的可扩展性以适应任何基础架构。
Graylog 带有直观的用户界面、快速而强大的搜索功能、警报和报告。它让您可以将系统分组到流中,以便于日志搜索和适当的管理。Graylog UI 简单直观,具有完整的用户管理和对 LDAP 的支持。
在 CentOS 8 / RHEL 8 Linux 上安装 Graylog 4.x
Graylog 需要 Java、Elasticsearch 和 MongoDB。Elasticsearch 负责日志存储。我们将从安装依赖项开始,然后安装 Graylog。
注意:这是在 CentOS 8 / RHEL 8 上安装 Graylog 的单服务器。对于多集群设置,请参阅 Graylog 官方文档。
第 1 步:配置 SELinux
如果您在系统上使用 SELinux,请设置以下设置:
sudo yum -y install curl vim policycoreutils python3-policycoreutils
sudo setsebool -P httpd_can_network_connect 1
sudo semanage port -a -t http_port_t -p tcp 9000
sudo semanage port -a -t http_port_t -p tcp 9200
sudo semanage port -a -t mongod_port_t -p tcp 27017
第 2 步:在 RHEL/CentOS 8 上安装 Java
由于 Elasticsearch 依赖于 Java 8,您需要在安装 Elasticsearch RHEL 8 / CentOS 8 之前将其安装在您的系统上。
sudo yum install java-11-openjdk java-11-openjdk-devel
确认Java安装:
$ java -version
java version "11.0.12" 2021-07-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.12+8-LTS-237)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.12+8-LTS-237, mixed mode)
第 3 步:在 RHEL 8 / CentOS 8 上安装 Elasticsearch 6
添加 Elasticsearch 存储库:
cat <<EOF | sudo tee /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/oss-7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
然后安装 Elasticsearch:
sudo yum -y install elasticsearch-oss
为 Graylog 配置 Elasticsearch
您需要修改 Elasticsearch 配置文件,将集群名称设置为graylog,另外,您需要取消注释(去掉 # 作为第一个字符),并action.auto_create_index: false
在配置文件中添加:
要编辑的文件是 /etc/elasticsearch/elasticsearch.yml。
$ sudo vi /etc/elasticsearch/elasticsearch.yml
cluster.name: graylog
action.auto_create_index: false
启动并启用elasticsearch服务:
sudo systemctl daemon-reload
sudo systemctl enable --now elasticsearch
确认服务状态:
$ systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2019-09-13 03:53:34 EDT; 9s ago
Docs: http://www.elastic.co
Main PID: 16862 (java)
Tasks: 40 (limit: 24024)
Memory: 1.1G
CGroup: /system.slice/elasticsearch.service
└─16862 /bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.n>
Sep 13 03:53:34 rhel8.novalocal systemd[1]: Stopped Elasticsearch.
Sep 13 03:53:34 rhel8.novalocal systemd[1]: Started Elasticsearch.
默认的 Elasticsearch 文件位置是:
文件系统路径 | |
---|---|
配置 | /etc/elasticsearch |
JVM 设置 | /etc/default/elasticsearch |
数据文件 | /var/lib/elasticsearch/data |
日志文件 | /var/log/elasticsearch/ |
第 4 步:在 RHEL 8 / CentOS 8 上安装 MongoDB
MongoDB 用于存储 Graylog 相关配置。使用以下文章中共享的步骤将其安装在 CentOS 8 / RHEL 8 上。
如何在 RHEL 8 / CentOS 8 上安装 MongoDB 4
安装后启用并启动mongod服务。
sudo systemctl enable --now mongod
MongoDB 路径:
文件系统路径 | |
---|---|
配置 | /etc/mongod.conf |
数据文件 | /var/lib/mongodb/ |
日志文件 | /var/log/mongodb/ |
服务的状态应该是running。
$ systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2019-09-13 03:57:04 EDT; 6s ago
Docs: https://docs.mongodb.org/manual
Process: 17397 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
Process: 17395 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 17393 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 17391 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
Main PID: 17399 (mongod)
Memory: 44.7M
CGroup: /system.slice/mongod.service
└─17399 /usr/bin/mongod -f /etc/mongod.conf
Sep 13 03:57:03 rhel8.novalocal systemd[1]: Starting MongoDB Database Server...
Sep 13 03:57:03 rhel8.novalocal mongod[17397]: 2019-09-13T03:57:03.538-0400 I STORAGE [main] Max cache overflow file size custom option: 0
Sep 13 03:57:03 rhel8.novalocal mongod[17397]: about to fork child process, waiting until server is ready for connections.
Sep 13 03:57:03 rhel8.novalocal mongod[17397]: forked process: 17399
Sep 13 03:57:04 rhel8.novalocal mongod[17397]: child process started successfully, parent exiting
Sep 13 03:57:04 rhel8.novalocal systemd[1]: Started MongoDB Database Server.
步骤 5:在 RHEL 8 / CentOS 8 上安装 Graylog 4
现在安装 Graylog 存储库配置:
sudo rpm -Uvh https://packages.graylog2.org/repo/packages/graylog-4.1-repository_latest.rpm
Graylog rpm 包在添加的存储库中可用。
sudo yum install graylog-server
我从安装中获得了3.1.2版。
$ rpm -qi graylog-server
Name : graylog-server
Version : 4.1.3
Release : 1
Architecture: noarch
Install Date: Fri 20 Aug 2021 06:49:41 PM UTC
Group : optional
Size : 217679607
License : SSPL
Signature : RSA/SHA1, Wed 04 Aug 2021 04:02:37 PM UTC, Key ID d44c1d8db1606f22
Source RPM : graylog-server-4.1.3-1.src.rpm
Build Date : Wed 04 Aug 2021 04:02:26 PM UTC
Build Host : b8f36c02852a
Relocations : /
Packager : Graylog, Inc. <hello@graylog.org>
Vendor : graylog
URL : https://www.graylog.org/
Summary : Graylog server
Description :
Graylog server
您需要 在/etc/graylog/server/server.conf下设置 add password_secret和root_password_sha2变量。 这些设置是强制性的,没有它们,Graylog 将无法启动!
使用以下命令创建您的root_password_sha2
:
echo -n "Enter Password: " && head -1 </dev/stdin | tr -d '\n' | sha256sum | cut -d" " -f1
设置生成值 root_password_sha2
$ sudo vi /etc/graylog/server/server.conf
root_username = admin
root_password_sha2 = <Sha2Passowrd>
生成password_secret。
$ sudo yum -y install pwgen
$ pwgen -N 1 -s 96
ny5eSSuHe03DWW7hGOGMPaVOlbBeZX48OqvTIO7J56rBwh0r99wB1bQwecjyID9S5XrCkzVcPBG0jLPcWiit1Vz1nPse6yBq
$ sudo vi /etc/graylog/server/server.conf
password_secret = ny5eSSuHe03DWW7hGOGMPaVOlbBeZX48OqvTIO7J56rBwh0r99wB1bQwecjyID9S5XrCkzVcPBG0jLPcWiit1Vz1nPse6yBq
为了能够连接到 Graylog,您应该设置http_bind_address
为您可以连接的机器的公共主机名或公共 IP 地址。
http_bind_address = 0.0.0.0:9000
最后一步是在操作系统启动期间启用 Graylog:
sudo systemctl daemon-reload
sudo systemctl enable --now graylog-server.service
在http://serverip_or_hostname:9000/上访问 Graylog 仪表板
使用在server.conf 中设置的用户名admin和 root 密码登录。