Observability:使用 Elastic Agent 和 Ingest Manager 简化数据导入 (二)

166 篇文章 30 订阅

在之前的文章 “Observability:使用 Elastic Agent 和 Ingest Manager 简化数据导入 (一)”,我们介绍了 Elastic Agent 及 Ingest Manager。在今天的这篇文章中,我们将集中介绍如何在本地部署中使用 Ingest Manager。在我的讲述中,我将使用如下的配置:

在上面的配置中,我们使用了两台机器,一个是 Mac OS。在里面安装有最新的 Elasticsearch 7.8 版本及 Kibana 7.8 版本。请一定要注意:我们必须安装 7.8 版本及以上,这是因为这个功能只有在7.8版本以上的发行版中才有。在另外一台 Ubuntu OS 的机器中,我们安装 Elastic Agent,Nginx 及 nodejs。这样我们可以展示如何快速地通过 Elastic Agent 把 Nginx 的日志及指标快速地导入到 Elasticsearch 中。

安装

Elasticsarch

如果你还没安装自己的 Elasticsearch 的话,请参阅我之前的文章 “如何在 Linux,MacOS 及 Windows 上进行安装 Elasticsearch”。为了能够保证我们的 Ubuntu 能够正常访问 Mac OS 里安装的 Elasticsearch,我们必须对 Elasticsearch 的配置文件做如下的修改:

network.host: 192.168.0.3
discovery.type: single-node

经过这样的配置后,我们的 Elasticsearch 将会绑定于私有地址 192.168.0.3:9200

Kibana

如果你还没有安装自己的 Kibana,请参阅我之前的文章 “Kibana:如何在 Linux,MacOS 及Windows上安装 Elastic 栈中的 Kibana”。同样地,为了能够使得我们的 Ubuntu 中的 Elastic Agents 能够访问我们的 Kibana,我需要把它的 host 地址进行修改:

server.host: "192.168.0.3"
elasticsearch.hosts: ["http://192.168.0.3:9200"]

通过上面的配置后, Kibana 将绑定于该电脑的私有地址 http://192.168.0.3:5601/

Nginx 及 Nodejs 

我们可以按照我之前的文章 “Beats:使用 Elastic Stack 对 Nginx Web 服务器监控”。在那篇文章中,我们跳过按照 Elasticsearch 及 Kibana。我们直接进入到安装 Nodejs 及 Ngnix 部分。我们需要同时运行那个 samplenodejs 的应用。

等我们安装好后,我们可以在 Mac OS 的浏览器中输入地址 192.168.0.4。

它说明我们的 Nginx 工作是正常的。我们可以仔细查看一下 Ubuntu 机器下如下的位置的 log 文件:

$ pwd
/var/log/nginx
liuxg@liuxgu:/var/log/nginx$ ls *.log
access.log  error.log

上面是在 Ubuntu OS 机器下的 Nginx  的日志文件的位置。记住这个信息。我们在一下的练习中将会用到。

启动 Ingest Manager

我们接下来针对 Ingest Manager 来进行安装及配置。首先,我们可以参阅 Elastic 的官方文档。安装要求,我们需要对之前的 Elasticsearch 及 Kibana 的配置做一些调整。

Elasticsearch

我们需要对 config/elasticsearch.yml 添加如下的配置:

xpack.security.enabled: true
xpack.security.authc.api_key.enabled: true

由于我们启动了安全,我们必须为集群配置可以访问的用户名及密码。我们可以参阅之前的文章 “Elasticsearch:设置 Elastic 账户安全” 来启动安全配置。假定我们为超级用户 elastic 配置的密码为 password。

等我们把安全设置好后,当我们再次访问 Kibana 时,我们需要使用创建的用户名及密码来登录。

最终,Elasticsearch 的 config/elasticsearch.yml 的配置如下:

network.host: "192.168.0.3"
discovery.type: single-node
xpack.security.enabled: true
xpack.security.authc.api_key.enabled: true

Kibana

除了在上面在安全配置中,我们需要修改如下的配置:

elasticsearch.username: "kibana_system"
elasticsearch.password: "password"

按照文档的要求,我们还必须配置 TLS。关于 TLS 的配置,你可以参阅我之前的文章 “ Elastic:为 Elasticsearch 启动 https访 问”。在今天的测试中,我们暂且不管。我们在 config/kibana.yml 中添加如下的配置:

xpack.security.enabled
xpack.ingestManager.fleet.tlsCheckDisabled: true
xpack.security.encryptionKey: "something_at_least_32_characters"
xpack.ingestManager.enabled: true

在上面,我们禁止检查 TLS。等添加完上面的配置后,我们重新启动 Kibana,并用用户名及密码进行登录。

Hooray,我们终于看到了一个新增加的 Ingest Manager 菜单了。

最终的 Kibana 的配置文件 config/kibana.yml 的配置如下:

config/kibana.yml

elasticsearch.hosts: ["http://192.168.0.3:9200"]
elasticsearch.username: "kibana_system"
elasticsearch.password: "password"
server.host: "192.168.0.3"
xpack.security.enabled: true
xpack.ingestManager.fleet.tlsCheckDisabled: true
xpack.security.encryptionKey: "something_at_least_32_characters"
xpack.ingestManager.enabled: true

更多关于 Kibana 的设置,请参阅链接。点击上面的 Ingest Manager 菜单。在  Overview 的页面,点击 Settings:

由于上面的 Elasticsearch 的地址是不对的。在默认的情况下是 localhost。我们需要对它进行修改成为我们的 Elasticsearch 的地址:

点击 Save Settings:

我们可以在默认的 Configuration 里进行查看是否已经修改为我们设定的地址。

使用 Ingest Manager

点击上面的 Ingest Manager:

在上面的 Overview 界面中,我们可以看到整个 Ingest  Manager 的概况。就像上面展示的那样。目前这仅是一个测试版本。点击上面的 Enroll new agent 按钮:

点击上面的 Go to Fleet 链接:

点击上面的 Create user and enable Fleet 按钮:

上面显示,目前我们还没有注册任何的 agent。点击上面的 Enroll new agent 按钮:

点击上面的 download page,我们就可以下载我们所需要的 Elastic Agent:

针对我的情况,我们选择 LINUX 64-BIT 按照包。我们把这个文件下载到我们的 Ubuntu 系统中。我们可以使用如下的命令:

wet https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-7.8.0-linux-x86_64.tar.gz

 等下载完后,我们可以使用如下的命令,把文件解压到 home 目录中:

tar xzf elastic-agent-7.8.0-linux-x86_64.tar.gz -C ~/

我们进入到 Elastic agent 的解压目录中:

$ pwd
/home/liuxg/elastic-agent-7.8.0-linux-x86_64
liuxg@liuxgu:~/elastic-agent-7.8.0-linux-x86_64$ ls 
LICENSE.txt  data           elastic-agent.reference.yml
README.md    elastic-agent  elastic-agent.yml

我们进而查看一下解压后的文件架构:

$ tree -L 2
.
├── LICENSE.txt
├── README.md
├── data
│   └── downloads
├── elastic-agent
├── elastic-agent.reference.yml
└── elastic-agent.yml

2 directories, 5 files
liuxg@liuxgu:~/elastic-agent-7.8.0-linux-x86_64$ ls ./data/downloads/
filebeat-7.8.0-linux-x86_64.tar.gz  metricbeat-7.8.0-linux-x86_64.tar.gz

从上面,我们可以看出来,在 Elastic agent 的 data/downloads 目录中含有 filebeat 及 metricbeat 的压缩文件。从某种意义上讲 Elastic Agent 是对这些 Beats 的重新包装,从而简化我们的配置。为了能够让 Elastic Agent 能够正确地访问 Elasticsearch (在另外一台电脑上),我们必须修改 elastic-agent.yml 这个配置文件:

outputs:
  default:
    type: elasticsearch
    hosts: [192.168.0.3.1:9200]
    username: elastic
    password: password

在上面,我们把 Mac OS 的 IP 地址输入进来,并把相应的 username 及 password 进行修改。

同时为了能够访问在另外一台电脑上的 Kibana,我们也需要对如下的部分进行修改:

  management:
#   # Mode of management, the Elastic Agent support two modes of operation:
#   #
#   # local: The Elastic Agent will expect to find the inputs configuration in the local file.
#   #
#   # Default is local.
#   mode: "local"

   fleet:
#     access_token: ""
#     kibana:
#       # kibana minimal configuration
       host: "192.168.0.3:5601"
#       ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]

#       # optional values
#       #protocol: "https"
        username: "elastic"
        password: "password"

在这里,我们需要启动 management 及 fleet,并对 host 进行配置。同时也需要配置相应的 username 及 password。修改完后,记得保存这个文件。

我们再回到 Kibana 的界面:

我们点击上面的 Copy command 按钮。运行上面的指令:

$ ./elastic-agent enroll http://192.168.0.3:5601 Nk5kMVVITUJRbDBNUDR6Vy0weFA6eEdPZGNObVlTZWl5WThncUFiSkdVUQ==
The Elastic Agent is currently in Experimental and should not be used in production
This will replace your current settings. Do you want to continue? [Y/n]:y
Please write 'y' or 'n'
This will replace your current settings. Do you want to continue? [Y/n]:y
2020-07-15T11:14:46+08:00 DEBUG	client.go:178	Request method: POST, path: /api/ingest_manager/fleet/agents/enroll
Successfully enrolled the Agent.

上面显示运行是成功的。我们接着运行如下的命令:

./elastic-agent run

运行完上面的命令后,我们点击如下的 Continue 按钮:

从上面的界面中,我们可以看到有一个 host 叫做 liuxgu 的出现在列表中。这是我的 Ubuntu OS 机器。我们可以看到有一个叫做 Default config 的 Configuration。点击这个超链接:

我们可以看到一个叫做 system-1 的 Data source。针对每个 Configuration 这是一个默认的配置,它包含内存,CPU 等等信息。我们点击上面的 Data streams:

点击上面的 View dashboard:

选择上面的 [Metrics System] Overview ECS:

在默认的情况下,Metricbeat 的 system 模块是启动的,所以我们可以查看到它的信息。其实我们可以看到这个和我们之前的单独使用 Metricbeat 的情况是完全一致的。

细心的开发者现在可以到运行 Elastic-Agent 的机器上进行查看一下当前安装目录下的情况:

我们可以看到 Elastic-Agent 其实已经帮我们把 filebeat 及 metricbeat 已经安装好了。

Elastic Integrations

接下来,我们来探讨一下 Elastic 集成。点击 Integrations:

这个是目前已经集成到 Kibana 中的一些 packages。它是从 Elastic 的一个网址上下载下来并展示的。从上面的列表中可以看出来目前已经集成的一些 packages。在今天的练习中,我们将使用 Nginx 来作为我们的练习。在上面的安装中,我们已经成功地把  Nginx 及 Nodejs 在 Ubuntu OS 上已经运行起来了。点击上面的 Nginx:

点击上面的 Create data source:

选中上面的 Default config:

我们在仔细地查看一下上面的信息和我们之前的配置 Nginx 的位置都是一致的。我们确认后,点击 Save data source 按钮:

点击 Save and deplot changes 按钮:

我们可以看到在 Configurations 中已经有一个新增加的 nginx-1 的 Data source。点击 Fleet:

上面显示我们的最新的活动时间是 26 秒以前,也就是我们的配置已经得到更新。点击 Data streams:

选择 nginx:

和之前一样,点击 View dashboard:

点击 [Logs Nginx] Overview ECS:

我们可以看到我的 Nodejs 的服务器的使用情况。

总结

使用 Kibana 中的 Ingest Manager,你可以很方便地添加和管理常用的服务和平台的集成。Elastic-Agent 除了在今天展示的 Fleet 模式下工作之外,它也可以在 standalone 模式下工作来管理 Elastic Agent 的安装。在未来的文章中,我将来介绍 standalone 模式下的工作情况。敬请关注!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值