您的位置:首页 > 运维架构 > Linux

如何在CentOS 7 / Fedora 31/30/29上安装ELK Stack

2019-12-25 23:13 1866 查看

原文地址:https://computingforgeeks.com/how-to-install-elk-stack-on-centos-fedora/

原作者: Josphat Mutai

译者:高行行

如何在 CentOS 7 / Fedora 31/30/29 上安装 ELK Stack?“ ELK ”是

Elasticsearch, Logstash, and Kibana
的缩写。

  • Elasticsearch:这是一个开源的、基于 REST 和 JSON 的搜索引擎。它具有可扩展性、易用性和灵活性
  • Logstash :这是一个服务器端数据处理管道,它同时从多个来源中采集数据,转换数据,然后将其发送到类似 Elasticsearch 的“存储”中。
  • Kibana 允许用户使用图表可视化 Elasticsearch 中的数据。

对于 RHEL 8,请参阅:

如何在 RHEL / CentOS 8 上安装 ELK Stack

请按照以下步骤在 CentOS 7 / Fedora 31/30/29 Linux 上安装和配置 ELK stack 工具。

步骤 1:安装 Java

由于 Elasticsearch 依赖 Java,因此你需要在 CentOS 7 / Fedora 系统上安装 Java。

sudo yum -y install java-openjdk-devel java-openjdk

步骤 2:添加 ELK 存储库

安装 Java 后,添加提供 ELK 堆栈软件包的 ELK 堆栈存储库。

对于 Elasticsearch 7.x

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/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF

对于 Elasticsearch 6.x

cat <<EOF | sudo tee /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF

添加仓库后,导入 GPG 密钥:

sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

清除并更新你的 YUM 软件包索引。

sudo yum clean all
sudo yum makecache

步骤 3:安装和配置 Elasticsearch

Elasticsearch 存储库已准备就绪,可以使用。你可以使用以下命令安装 Elasticsearch:

sudo yum -y install elasticsearch

确认软件包安装。

$ rpm -qi elasticsearch
Name        : elasticsearch
Epoch       : 0
Version     : 7.0.1
Release     : 1
Architecture: x86_64
Install Date: Mon 06 May 2019 09:59:57 PM EAT
Group       : Application/Internet
Size        : 571521653
License     : Elastic License
Signature   : RSA/SHA512, Mon 29 Apr 2019 05:14:11 PM EAT, Key ID d27d666cd88e42b4
Source RPM  : elasticsearch-7.0.1-1-src.rpm
Build Date  : Mon 29 Apr 2019 04:06:59 PM EAT
Build Host  : packer-virtualbox-iso-1553723689
Relocations : /usr
Packager    : Elasticsearch
Vendor      : Elasticsearch
URL         : https://www.elastic.co/
Summary     : Elasticsearch is a distributed RESTful search engine built for the cloud. Reference documentation can be found at https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html and the 'Elasticsearch: The Definitive Guide' book can be found at https://www.elastic.co/guide/en/elasticsearch/guide/current/index.html
Description :
Elasticsearch subproject :distribution:packages

你可以通过编辑文件来设置 JVM 选项(例如内存限制):

/etc/elasticsearch/jvm.options

下面的示例设置总堆空间的初始/最大大小

-Xms1g
-Xmx1g

如果你的系统内存较少,则可以将其配置为使用较小的内存。

-Xms256m
-Xmx512m

启动并设置为开机时启用 elasticsearch 服务:

$ sudo systemctl enable --now elasticsearch.service
Synchronizing state of elasticsearch.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable elasticsearch
Created symlink /etc/systemd/system/multi-user.target.wants/elasticsearch.service → /usr/lib/systemd/system/elasticsearch.service.

测试以验证其是否正常运行:

$ curl http://127.0.0.1:9200
{
"name" : "localhost.localdomain",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "7fyD4TuqQ7yxog0fCnPXuA",
"version" : {
"number" : "7.5.0",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "e9ccaed468e2fac2275a3761849cbee64b39519f",
"build_date" : "2019-11-26T01:06:52.518245Z",
"build_snapshot" : false,
"lucene_version" : "8.3.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}

创建一个测试的索引:

$ curl -X PUT "http://127.0.0.1:9200/mytest_index"
{"acknowledged":true,"shards_acknowledged":true,"index":"mytest_index"}

步骤 4:安装和配置 Kibana

从添加的 Elasticsearch 存储库下载并安装 Kibana。

sudo yum -y install kibana

成功安装后,配置 Kibana:

$ sudo vim /etc/kibana/kibana.yml
server.host: "0.0.0.0"
server.name: "kibana.example.com"
elasticsearch.url: "http://localhost:9200"

根据需要更改其他设置,然后启动 kibana 服务:

sudo systemctl enable --now kibana

访问 http://ip-address:5601 以打开 Kibana 信息中心:

如果你有活动的防火墙服务,请允许使用 TCP

5601
端口

sudo firewall-cmd --add-port=5601/tcp --permanent
sudo firewall-cmd --reload

步骤 5:安装和配置 Logstash

最后安装的是针对 Logstash 的。它将充当客户端系统的集中式日志服务器,该服务器运行诸如filebeat之类的代理 。

sudo yum -y install logstash

Logstash 自定义配置可以放在

/etc/logstash/conf.d/
目录下。

有关更多详细信息,请[ 参阅 Logstash 配置手册 ](https://www.elastic.co/guide/en/logstash/current/index.html " 参阅Logstash配置手册 ")。

步骤 6:安装其他 ELK 工具-锦上添花

可以安装的其他 ELK 工具包括:

  • Filebeat:用于日志的轻量型采集器。通过提供一种转发和汇总日志与文件的轻量级方法,让简单的事情不再繁杂。
  • Metricbeat:用于从系统和服务收集指标。Metricbeat 能够以一种轻量型的方式,输送各种系统和服务统计数据,从 CPU 到内存,从 Redis 到 Nginx,不一而足。
  • Packetbeat:轻量型网络数据采集器。用于深挖网线上传输的数据,了解应用程序动态。Packetbeat 是一款轻量型网络数据包分析器,能够将数据发送至 Logstash 或 Elasticsearch。
  • Heartbeat:用于正常运行时间监视的轻量型采集器。它通过主动探测帮助你监视服务的可用性
  • Auditbeat:轻量型审计日志采集器,可帮助你审核系统上用户和进程的活动

这些工具可以通过

yum
软件包管理器使用它们各自的名称一起进行安装。下面的示例将安装所有ELK插件工具。

sudo yum install filebeat auditbeat metricbeat packetbeat heartbeat-elastic

有关每种工具的配置和进一步的阅读,请参考官方的 ELK Stack 文档 以及 资源和培训

更多指南:

在 Ubuntu 上使用 Elasticsearch 6 安装 Graylog 3

在 CentOS / RHEL 8 上安装 Graylog 3

在 CentOS 7 上安装 Elasticsearch 7

本文由博客一文多发平台 OpenWrite 发布!
个人公众号《骇客与画家》,欢迎关注

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: