我在CentOS 7上安装了Elasticsearch + Kibana + Logstash
首先
因为最近很少接触到Elastic Stack,并且它已经更新和改进了,所以我决定在CentOS7上安装最新版本的7.8。
我打算安装它的目的是为了进行Kibana的Stack Monitoring。
环境
CentOS 7.8
※ 在安装的初始状态下准备完毕
# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
提前准备
使用Elasticsearch和logstash需要OpenJDK。
为了使用Elasticsearch,需要事先安装好JAVA。根据官方文档,Elasticsearch已经捆绑了OpenJDK,所以不需要额外安装。但是对于Logstash来说,它没有捆绑OpenJDK,所以安装是必需的。
Elasticsearchには 、JDKメンテナ(GPLv2 + CE)からのOpenJDKのバンドルバージョンが含まれています。
独自のバージョンのJavaを使用するには、JVMバージョンの要件を参照してください。
顺便说一句,什么是OpenJDK?
OpenJDK是Java编程语言的开源实现,Oracle JDK(Java SE)是其闭源官方实现。
让我们安装OpenJDK。
# yum install java-1.8.0-openjdk-devel
# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
让我们安装ElasticStack。
1. 安装Elasticsearch PGP密钥
# rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
2. 注册存储库
在这里我们故意不启用存储库。
在使用yum进行安装时,请指定存储库。
为了避免自动升级!
# vi /etc/yum.repos.d/elasticsearch.repo
[elasticsearch]
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=0
autorefresh=1
type=rpm-md
3. 安装
请确保正确指定代码库。
# yum install --enablerepo=elasticsearch elasticsearch kibana logstash
4. 最低限度的设置 (Zuì de
· Elasticsearch内存设置
由于它是在JAVA上运行的,因此会稍微调整可用的内存。
如果内存有余,则应充分分配。
# vi /etc/elasticsearch/jvm.options
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms2g
-Xmx2g
将IP地址配置为用于Elasticsearch的,同时将其设置为单节点运行的配置。
首先,我们将配置使得可以访问分配给服务器的IP地址。
另外,在单节点情况下,需要设置discovery.type。
# vi /etc/elasticsearch/elasticsearch.yml
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
network.host: 0.0.0.0 ← 追加
discovery.type: single-node ← 追加
设置要用于Kibana的IP地址配置。
设置使得可以访问到与Elasticsearch类似分配给服务器的IP地址。
# vi /etc/kibana/kibana.yml
#server.host: "localhost"
server.host: "0.0.0.0" ← 追加
# The URL of the Elasticsearch instance to use for all your queries.
#elasticsearch.url: "http://localhost:9200"
※サーバIPを固定する場合はここも変更してください。
5. 防火墙的设置 de
我们将分别打开每个应用程序所使用的端口。
Kibana:5601
elasticsearch:9200
logstash:9600
# firewall-cmd --add-port=5601/tcp --zone=public --permanent
# firewall-cmd --add-port=9200/tcp --zone=public --permanent
# firewall-cmd --add-port=9600/tcp --zone=public --permanent
# firewall-cmd --reload
6. 启动和自动启动的设置
systemctl daemon-reload
systemctl restart elasticsearch kibana logstash
systemctl enable elasticsearch kibana logstash
7. 确认访问
・确认Elasticsearch访问
# curl http://localhost:9200
{
"name" : "localhost.localdomain",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "iWGd48WKTMSKHG2Bq-tVSQ",
"version" : {
"number" : "7.8.0",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65",
"build_date" : "2020-06-14T19:35:50.234439Z",
"build_snapshot" : false,
"lucene_version" : "8.5.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}

8. 我们想在Kibana的仪表盘上进行堆栈监控!(使用Metricbeat)
根据公式文档,最新的 Monitoring 使用 Metricbeat,因此我们将使用 Metricbeat 进行 Monitoring。
8-1. 安装
我们也会启用Elasticsearch的存储库并进行安装。
# yum install --enablerepo=elasticsearch metricbeat
8-2. 模块的启用
由于Metricbeat模块中存在各个xpack模块,因此我们将逐个启用它们。
metricbeat modules enable elasticsearch-xpack
metricbeat modules enable kibana-xpack
metricbeat modules enable logstash-xpack
8-3. 模块的设置
以下是各个设置的详细说明:
如果已指定服务器的IP地址,则无法通过localhost访问,因此请在各个设置中的hosts中设置IP地址。
此外,如果实施了安全功能的身份验证,则还需要进行用户和密码的设置。
顺便提一下,官方文档中似乎有很多选项可供选择。
# cat /etc/metricbeat/modules.d/elasticsearch-xpack.yml
========================================
# Module: elasticsearch
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/7.8/metricbeat-module-elasticsearch.html
- module: elasticsearch
xpack.enabled: true
period: 10s
hosts: ["http://localhost:9200"]
#username: "user"
#password: "secret"
========================================
# cat /etc/metricbeat/modules.d/kibana-xpack.yml
========================================
# Module: kibana
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/7.8/metricbeat-module-kibana.html
- module: kibana
xpack.enabled: true
period: 10s
hosts: ["localhost:5601"]
#basepath: ""
#username: "user"
#password: "secret"
========================================
# cat /etc/metricbeat/modules.d/logstash-xpack.yml
========================================
# Module: logstash
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/7.8/metricbeat-module-logstash.html
- module: logstash
xpack.enabled: true
period: 10s
hosts: ["localhost:9600"]
#username: "user"
#password: "secret"
========================================
8月4日,重新启动Metricbeat并进行确认!
准备工作已经完成。
然而,似乎只有当Logstash执行了某个模块才会显示出来。
# systemctl restart metricbeat
# systemctl enable metricbeat

希望可以显示Elasticsearch的日志(Filebeat)。
我在监控中看到了一个想法,
好像可以显示Elasticsearch的日志。我也想看看它!
我去看了官方文档然后试了一下。
9-1. 安装
首先必须进行安装才能开始!同样地, 我们会启用Elasticsearch的存储库并进行安装。
# yum install --enablerepo=elasticsearch filebeat
9-2. 设置filebeat的配置
这次由于可以通过本地主机访问,所以似乎不需要进行配置,但是需要进行主机等设置。
# vi /etc/filebeat/filebeat.yml
========================================
# =================================== Kibana ===================================
# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.
setup.kibana:
# Kibana Host
# Scheme and port can be left out and will be set to the default (http and 5601)
# In case you specify and additional path, the scheme is required: http://localhost:5601/path
# IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
#host: "localhost:5601"
# ---------------------------- Elasticsearch Output ----------------------------
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["localhost:9200"]
========================================
9-3. 激活模块
Filebeat也有模块,所以我们要激活Elasticsearch的模块。
设置可能需要一些时间,当显示”加载配置文件完成。”时就可以了。
# filebeat modules enable elasticsearch
# filebeat setup -e
9-4. 重新启动Filebeat并进行确认!
应该就可以了。重新启动并检查仪表板。
# systemctl restart filebeat
# systemctl enable filebeat

这个调整变得更容易和方便了。
总之,初始设置已经完成了,就是这个感觉。
现在你可以充分享受Elasticstack啦!!!!!