使用Metricbeat、Elasticsearch和Kibana来可视化Ubuntu机器的指标

以下是机器的配置。只需要一台机器即可满足全部需求,供您参考。

    • メインPC

kibanaの画面を確認します

Ubuntu server

集計対象マシンです。metricbeatをインストールします。

elasticsearch & kibana(ベースOSはubuntu)

集計結果を集約するマシンです。
IP: 192.168.11.101

在apt可用的存储库中添加elasticsearch。

使用包管理器来进行管理会更容易进行更新/删除,因此将设置为可以使用apt进行安装。

将用于elasticsearch仓库认证的密钥添加

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

安裝需要後續安裝的組件

sudo apt-get install apt-transport-https

将elastic的存储库添加到apt源列表中。

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

请参考此链接:https://www.elastic.co/guide/en/beats/metricbeat/current/setup-repositories.html

安装 Elasticsearch

sudo apt-get update && sudo apt-get install elasticsearch

使elasticsearch可以从外部访问

如果全部都在一台机器上完成的话就不需要了。
这次因为汇总的机器和elastic运行的机器是不同的,所以我添加了一些设置以便从外部访问。

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
transport.host: localhost
transport.tcp.port: 9300
#

因为设置完成了,所以要启动elasticsearch。

systemctl restart elasticsearch

安装 Kibana

sudo apt-get update && sudo apt-get install kibana

我們也對Kibana進行了設定,以便讓它可以從外部進行訪問。

server.host: "0.0.0.0"

設定已完成,現在啟動Kibana。

systemctl restart elasticsearch

在指定的主机上安装 metricbeat 进行数据统计。

sudo apt-get update && sudo apt-get install metricbeat

设置Elasticsearch主机

由于/etc/metricbeat/metricbeat.yml中存在以下配置项,因此请根据环境进行设置。
如果您正在本地主机上运行elasticsearch,则不需要此配置。
本次为了访问不同机器上的elasticsearch,我们设置了不同主机的IP/端口。

output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["192.168.11.101:9200"]

设置计算目标

根据环境调整需要进行汇总的模块,并激活它们。
由于仅需要获取Ubuntu机器的信息,此次未执行,仅供参考。

metricbeat modules enable apache mysql

您可以在下面确认可用的模块。
默认情况下,System模块已启用,因此无需特别操作。

root@ubuntu ~# metricbeat modules list
Enabled:
system

Disabled:
aerospike
apache
aws
beat
beat-xpack
ceph
cockroachdb
consul
coredns
couchbase
couchdb
docker
dropwizard
elasticsearch
elasticsearch-xpack
envoyproxy
etcd
golang
graphite
haproxy
http
jolokia
kafka
kibana
kibana-xpack
kubernetes
kvm
logstash
logstash-xpack
memcached
mongodb
mssql
munin
mysql
nats
nginx
oracle
php_fpm
postgresql
prometheus
rabbitmq
redis
statsd
traefik
uwsgi
vsphere
windows
zookeeper

启动Metricbeat

systemctl restart metricbeat

通过Kibana查看汇总结果

使用主电脑的浏览器访问192.168.11.101:5601。
点击左侧的基础设施以查看信息。

192.168.11.101_5601_app_kibana.png
192.168.11.101_5601_app_infra (1).png

总结

只需提供有关kibana、metricbeat和elasticsearch连接的信息,就可以轻松地获取信息,这真是太棒了。
只要安装好metricbeat,其他模块似乎也很容易开始聚合,所以如果还有其他信息,我会写一篇文章。

bannerAds