[Elasticsearch 8.5 版]、Kibana、以及 Elastic Agent 的快速安装步骤(适用于试用环境)
首先
在这里我将介绍使用最新版本8.5.3的Elasticsearch、Kibana和Elastic Agent在您的计算机上安装的步骤,以便您可以快速尝试它们。我们将安装Elastic Agent并配置日志文件收集。
以下是本文参考了Elastic的安装文档,并且在此基础上使用了最简单的步骤来实践。
[重要]这次为了试用环境和学习环境的目的,我们让步骤在一台机器上完成。在实际使用系统时,请正确设计为多台配置等。以下文档可供参考: https://www.elastic.co/guide/en/elasticsearch/reference/current/high-availability.html
另外,实际引入系统时,建议使用云端版的Elastic Cloud,这样设计会更加轻松,上述提到的。
关于本次试用环境的构建



本次使用的计算机环境
我使用了AWS的EC2,并使用了Amazon Linux 2 Kernel 5.10的AMI。然而,Centos和RHEL也应该可以按照类似的步骤完成。
我选择了t2.medium规格(2个vCPU,4GB内存)。
在操作步骤中,事先安装工具:
sudo yum install perl-Digest-SHA -y
sudo yum install wget -y
安装Elasticsearch
请使用以下命令在RPM中安装Elasticsearch。
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.5.3-x86_64.rpm
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.5.3-x86_64.rpm.sha512
shasum -a 512 -c elasticsearch-8.5.3-x86_64.rpm.sha512
sudo rpm --install elasticsearch-8.5.3-x86_64.rpm
上述命令的输出会显示各种信息,但作为本次步骤的最少必须关注以下两个地方。
请记下生成的密码,以后登录Kibana时会用到。
The generated password for the elastic built-in superuser is : <password>
使用以下命令将Elasticsearch注册到systemd,并启动它。
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
在启动后,执行以下命令在Elasticsearch安装基础上,为Kibana发行与Elasticsearch通信所需的令牌。请记下输出的令牌字符串,以备后用。
sudo /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana
Kibana安装
请下载并安装Kibana的RPM包。
wget https://artifacts.elastic.co/downloads/kibana/kibana-8.5.3-x86_64.rpm
shasum -a 512 kibana-8.5.3-x86_64.rpm
sudo rpm --install kibana-8.5.3-x86_64.rpm
请按照以下步骤进行系统登记并启动Kibana。
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable kibana.service
在启动Kibana之前,需要对要绑定的网络接口进行配置更改。
# =================== System: Kibana Server ===================
# Kibana is served by a back end server. This setting specifies the port to use.
#server.port: 5601
# Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
# The default is 'localhost', which usually means remote machines will not be able to connect.
# To allow connections from remote users, set this parameter to a non-loopback address.
#server.host: "localhost"
请将上述 #server.host: “localhost” 修改为 server.host: “0.0.0.0” ,以便从远程访问Kibana。
然后,使用下面的命令启动Kibana。
sudo systemctl start kibana.service


sudo /usr/share/kibana/bin/kibana-verification-code


Fleet Server的安装




请在服务器上粘贴并执行命令。将下载Elastic Agent,并在其中启动Fleet Server。
curl -L -O https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-8.5.3-linux-x86_64.tar.gz
tar xzvf elastic-agent-8.5.3-linux-x86_64.tar.gz
cd elastic-agent-8.5.3-linux-x86_64
sudo ./elastic-agent install \
--fleet-server-es=https://172.31.6.148:9200 \
--fleet-server-service-token=AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyL3Rva2VuLTE2NzIyMDQyOTc3NzQ6QkFKUDhoLWRSemVxT0hhQ2dVSlpMZw \
--fleet-server-policy=fleet-server-policy \
--fleet-server-es-ca-trusted-fingerprint=ec2529ac3379673f4c5c964ae69c37fa27fbf2a7f594c357915882ed88154d79
Successfully enrolled the Elastic Agent.
Elastic Agent has been successfully installed.
提示:根据上述内容可以看出,Fleet Server本身作为Elastic Agent的一部分进行安装。

添加集成以收集日志






尝试进行日志收集
在机器的终端上,按照以下方式将日志输出到先前指定的日志文件路径中。每隔5秒记录一次日期。
while true
do
date >> mylog.log
sleep 5
done
Wed Dec 28 06:36:56 AM UTC 2022
Wed Dec 28 06:37:01 AM UTC 2022
...


由于日志消息存储在message字段中,因此请在左侧按下message字段旁的加号按钮,以仅显示该消息。

参考文件
以下是我参考的产品文档。
Elasticsearch安装 https://www.elastic.co/guide/en/elasticsearch/reference/8.5/rpm.html#install-rpm
在中文中,对以下句子进行同义转述:
Kibana 的安装
https://www.elastic.co/guide/en/kibana/8.5/rpm.html#install-rpm
请注意:以下是一个可能的翻译,实际表述可能因语境等因素而有所不同。
Kibana的安装指南可参考以下链接:https://www.elastic.co/guide/en/kibana/8.5/rpm.html#install-rpm
结束了吗?只要准备了类似操作系统的设备,应该能够按照步骤轻松地试用。对于Elastic Agent部分,需要一些熟悉的时间,所以请参考这个环境,尽量多尝试一些操作。