目的
内部ネットワークからInternet(Webサイト)への接続性をHeartbeatのモニタリング機能とkibanaの可視化を用いて簡易的な監視を実現させる。
多様なルートからInternet接続性の監視を行うことによりProxyサーバの正常性や通信経路、直接インターネット接続可否などの外形監視を行う。
前回記事のZabbixでのWebモニタリングとの操作性やグラフ表示などを比較材料とする。
構成/監視イメージ
環境
heartbeat(CentOS7.8/ Ver.7.9) / IP : 172.16.100.200
elasticserach/kibana(CentOS7.8/ Ver.7.9) / IP : 172.16.200.100
Proxy1(squid 4.4) / IP;172.16.200.61
Proxy2(squid 3.5.2) / IP:172.16.200.62
AD / Windows Server 2016
domain : my.home
(NTLM認証ユーザ) User : test01 . pass : Passw0rd
設定概要
heartbeatでWebモニタリングを使用するには、heartbeat.ymlのheartbeat.monitorsの定義を行いモニタリング対象を登録します。
・heartbeat.ymlは基本設定のみ記載してモニタリング対象(kibanaのアクセス)のみを記載する。
・その他のモニタリング対象の設定は、monitors.dディレクトリ配下に設定ファイルを作成する。
・モニタリング対象パターン
- 直接インターネット接続(Proxyを経由しない)
- Proxyサーバ経由①:ユーザ認証が無でインターネット接続
- Proxyサーバ経由②:ユーザ認証が有でインターネット接続
heartbeatディレクトリ構成
/etc/heartbeat
├─ fields.yml :デフォルト
├─ heartbeat.reference.yml :デフォルト
├─ heartbeat.yml :修正
└─ monitors.d :デフォルト
├─ sample.http.yml.disabled :デフォルト
├─ sample.icmp.yml.disabled :デフォルト
├─ sample.tcp.yml.disabled :デフォルト
└─ http_ResponseCheck.yml :新規作成
参考URL
Set up and run Heartbeat -> Repositories for APT and YUM
https://www.elastic.co/guide/en/beats/heartbeat/current/setup-repositories.html
実施方法
heartbeatインストール
Elasticsearch リポジトリ設定
# rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
# vi /etc/yum.repos.d/elastic.repo
----
[elastic-7.x]
name=Elastic 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=1
autorefresh=1
type=rpm-md
-----
インストール
# yum install -y heartbeat-elastic
基本設定(heartbeat.yml)修正
reload.enabledのステータスを true とすると、periodで設定した間隔で module.d配下のファイルを読み込む。
# vi /etc/heartbeat/heartbeat.yml
heartbeat.config.monitors:
path: ${path.config}/monitors.d/*.yml
reload.enabled: false
reload.period: 5s
heartbeat.monitors:
- type: http
id: kibana-monitor
name: 172.16.200.100_elasticsearch_Monitor
urls: ["http://172.16.200.100:5601"]
schedule: '@every 60s'
setup.template.settings:
index.number_of_shards: 1
index.codec: best_compression
setup.kibana:
output.elasticsearch:
hosts: ["172.16.200.100:9200"]
processors:
- add_observer_metadata:
モニタリング設定
タイプ1(Proxy無):Check01_Example.com_NoProxy
タイプ2(Proxy有.認証無):Check02_Example.com_NoAuthProxy
タイプ3(Proxy有,認証有):Check03_Example.com_AuthProxy
# vi /etc/heartbeat/monitors.d/http_ResponseCheck.yml
- name: 'Check01_Example.com_NoProxy'
type: http
schedule: '@every 10s'
urls: ["https://example.com/"]
proxy_url: 'http://172.16.200.61:8080'
check.request.method: GET
check.response.status: 200
tags: ["NoProxy", "NoAuth", "example"]
- name: 'Check02_Example.com_NoAuthProxy'
type: http
schedule: '@every 10s'
urls: ["https://example.com/"]
proxy_url: 'http://172.16.200.61:8080'
check.request.method: GET
check.response.status: 200
tags: ["Proxy", "NoAuth", "example"]
- name: 'Check03_Example.com_AuthProxy'
type: http
schedule: '@every 10s'
urls: ["https://example.com/"]
proxy_url: 'http://test02@my.home:Passw0rd@172.16.200.62:8080'
check.request.method: GET
check.response.status: 200
tags: ["Proxy", "Auth", "example"]
※認証用ユーザ名とパスワードは、ドメイン\ユーザ名:パスワードの表記では接続できなかったため、ユーザ名@ドメイン名としている。
service起動
# systemctl enable heartbeat-elastic
# systemctl start heartbeat-elastic
# systemctl status heartbeat-elastic
kibana index作成
まず、elasticsearchでindexが作成されたことを確認するため、
kibanaにアクセスしサイドメニューのStack Management を選択して表示されたメニューからindexManagementを選択する。
検索欄に heartbeat を入力して indexが表示されることを確認する。
※表示されなかったら、設定が間違えている可能性が高い。
kibanaのindexパターン作成を行うため、 kibana -> indexPatternから
右上のCreate index pattern をクリックする。
作成するindex名「heartbeat*」と入力して次のステップで time field に 「@timestamp」を選択して、Create index patternをクリックして作成する。
kibanaのDiscoverから取得データを確認する。
※多数のデータが取得されていることが分かる。
取得データ確認
kibanaにアクセスして、サイドメニューのUptime から状態を確認し、
以下の表示からは全てUpで正常に接続できていることが分かる。
該当の名前をクリックすると詳細な情報が分かる
ADサーバでTest02ユーザを無効とした場合、Proxy(認証有)のモニタリングがDownしたことが分かる。
※個々のデータの比較はあまり出来ないような感じので、取得データから項目をグラフ化などする必要がありそう。ZabbixのWeb監視のような速度は現状の取得データからは取得できないようだ
※有償サポートを入るとアラート機能や機械学習なども使用することが可能。
![Elastic Stack実践ガイド[Elasticsearch/Kibana編] (Impress Top Gear) Elastic Stack実践ガイド[Elasticsearch/Kibana編] (Impress Top Gear)](https://m.media-amazon.com/images/I/51oCFy2NMJL._SL160_.jpg)
Elastic Stack実践ガイド[Elasticsearch/Kibana編] (Impress Top Gear)
- 作者:惣道 哲也
- 発売日: 2020/08/07
- メディア: 単行本(ソフトカバー)