天天看点

安装 Beats (本地及 docker)

完整版电子书: 《Elastic Stack 实战手册》早鸟版首发

3.安装 Beats (本地及 docker)

本章介绍 Beats 的安装和部署,包括以下几个方面:

  • 1.环境准备
  • 2.Beats组件的下载和安装
  • 3.基础配置
  • 4.启动Beats
  • 5.检查收集到的数据
  • 6.docker方式安装

作为ELK Stack的补充,在使用Beats之前,需要已安装好ElasticSearch和kibana,ElasticSearch用来存储和检索数据,Kibana作为可视化和管理端。Logstash则根据实际场景不强依赖。接下来将基于Elastic Stack 7.1.0版本为基础,以Metricbeat组件为例,其他Beats组件使用方法类似。

根据不同操作系统,选择合适的安装包:

deb:

curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.10.0-amd64.deb
sudo dpkg -i metricbeat-7.10.0-amd64.deb           

rpm:

curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.10.0-x86_64.rpm
sudo rpm -vi metricbeat-7.10.0-x86_64.rpm           

mac:

curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.10.0-darwin-x86_64.tar.gz
tar xzvf metricbeat-7.10.0-darwin-x86_64.tar.gz           

brew:

brew tap elastic/tap
brew install elastic/tap/metricbeat-full           

linux:

curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.10.0-linux-x86_64.tar.gz
tar xzvf metricbeat-7.10.0-linux-x86_64.tar.gz           

win:

# 1.进入目录
> cd C:\Program Files\Metricbeat
# 2.安装Metricbeat为Windows服务
> .\install-service-metricbeat.ps1           

更多Beats组件可以前往下载页面

Beats Download

进入解压后的Metricbeat目录可以看到安装目录的根目录下如下文件及文件夹:

$ ls -l
fields.yml
kibana
LICENSE.txt
metricbeat
# 完整的配置文件模板
metricbeat.reference.yml
# 默认的配置文件
metricbeat.yml
module
modules.d
NOTICE.txt
README.md           

我们只修改使用 metricbeat.yml

如果你的ElasticSearch和Kibana都安装在同一台主机上,并配置了默认的端口,可以跳过此步骤不修改配置,Metricbeat默认指定了localhost。

output.elasticsearch:
  hosts: ["localhost:9200"]
  # 如果ElasticSearch启用了认证需要配置账号密码
  username: "YOUR_ACCOUNT"
  password: "YOUR_PASSWORD"
setup.kibana:
  host: "localhost:5601"
  # 如果kibana启用了认证需要配置账号密码
  username: "YOUR_ACCOUNT"
  password: "YOUR_PASSWORD"           

配置Metricbeat,指定运行的模块。

# 查看所有支持的模块
./metricbeat modules list
# 打开system模块
./metricbeat modules enable system           

设置初始化环境,在此之前确保ElasticSearch和Kibana已经正常运行

./metricbeat setup -e           

Metricbeat启动后会发送 system metrics数据到ElasticSearch。

./metricbeat -e           

打开Kibana的仪表板地址:

http://localhost:5601/app/kibana#/dashboard/Metricbeat-system-overview-ecs

。正常情况下可以看到如下界面。

安装 Beats (本地及 docker)

点击 Host Overview 可以查看metrics的详情。

安装 Beats (本地及 docker)

拉取镜像

docker pull docker.elastic.co/beats/metricbeat:7.10.0           

启动docker版Metricbeat

通过-E设置ElasticSearch和Kibana的地址及其他参数(如果有必要)。注意:如果是本机安装的服务,docker是无法通过localhost连接到ElasticSearch和Kibana的,可以通过增加参数docker run --net=host,让docker可以访问到宿主机的hostname,或者可以通过 ip addr show docker0 查看docker的网关地址来访问宿主机。

docker run --net=host \
docker.elastic.co/beats/metricbeat:7.10.0 \
setup -E setup.kibana.host=elastichost:5601 \
-E output.elasticsearch.hosts=["elastichost:9200"]