Contents
Ansible Tower(AWX)のシステムログ及びジョブ実行ログを一先ずElasticsearchに取り込んで可視化する手順(備忘録)です。
目的
Elasticsearch + Logstash + Kibanaを構築してAnsible Towerのログを転送し一先ず可視化するところまでやります。
設定も最低限にしかしません。
環境
項目 | バージョン |
---|---|
OS | RHEL7.5 |
Elasticsearch | 6.3 |
Kibana | 6.3 |
logstash | 6.3 |
Ansbile Tower | 3.2.5 |
ログ可視化手順
ELKセットアップ
OpenJDKインストール
(1) ELKはJavaで動くためOpenJDKをインストールします。
1 2 |
[root@localhost ~]# yum -y install java-1.8.0-openjdk |
ELKインストール準備
(1) ここではyumでインストールするのでGPG Keyをインポートします。
1 2 |
[root@localhost ~]# rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch |
(2) リポジトリファイルを作成します。
1 2 3 4 5 6 7 8 9 10 |
[root@localhost ~]# vi /etc/yum.repos.d/elastic.repo [elasticsearch-6.x] name=Elasticsearch repository for 6.x packages baseurl=https://artifacts.elastic.co/packages/6.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md |
Elasticsearchインストール・起動
(1) Elasticsearchをインストールします。
1 2 |
[root@localhost ~]# yum -y install elasticsearch |
(2) Elasticsearchの設定をします。
1 2 3 4 5 6 7 |
(snip) cluster.name: cluster01 (snip) node.name: node01 (snip) network.host: 192.168.0.221 |
(3) Elasticsearchを起動します。
1 2 3 |
[root@localhost ~]# systemctl enable elasticsearch [root@localhost ~]# systemctl start elasticsearc |
(4) elasticsearchが起動したことを確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
[root@localhost ~]# systemctl status elasticsearch ● elasticsearch.service - Elasticsearch Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled) Active: active (running) since 金 2018-08-03 23:24:19 JST; 1min 27s ago (snip) [root@localhost ~]# curl -X GET http://192.168.0.221:9200 { "name" : "node01", "cluster_name" : "cluster01", "cluster_uuid" : "wVG8RU9tR_C7mtlr4VETWg", "version" : { "number" : "6.3.2", "build_flavor" : "default", "build_type" : "rpm", "build_hash" : "053779d", "build_date" : "2018-07-20T05:20:23.451332Z", "build_snapshot" : false, "lucene_version" : "7.3.1", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" } |
Kibanaインストール・起動
(1) Kibanaをインストールします。
1 2 |
[root@localhost ~]# yum -y install kibana |
(2) Kibanaの設定をします。
1 2 3 4 5 6 7 8 |
(snip) server.host: "192.168.0.221" (snip) server.name: "localhost" (snip) elasticsearch.url: "http://192.168.0.221:9200" (snip) |
(3) Kibanaを起動します。
1 2 3 |
[root@localhost ~]# systemctl enable kibana [root@localhost ~]# systemctl start kibana |
(4) Kibanaが起動したことを確認します。
1 2 3 4 5 6 |
[root@localhost ~]# systemctl status kibana ● kibana.service - Kibana Loaded: loaded (/etc/systemd/system/kibana.service; enabled; vendor preset: disabled) Active: active (running) since 金 2018-08-03 23:31:27 JST; 22s ago (snip) |
以下のURLへアクセスしてKibanaの画面が表示されることを確認します。
URL |
---|
http://ip or fqdn:5601 |
Logstashインストール・起動
(1) Logstashをインストールします。
1 2 |
[root@localhost ~]# yum -y install logstash |
(2) Logstashの設定をします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@localhost ~]# vi /etc/logstash/conf.d/ansible_tower.conf input { http { port => 5140 } } filter { json { source => "message" } } output { elasticsearch { hosts => ["192.168.0.221"] index => "ansible_tower" } } |
(3) Logstashを起動します。
1 2 3 |
[root@localhost ~]# systemctl enable logstash [root@localhost ~]# systemctl start logstash |
(4) Logstashが起動したことを確認します。
1 2 3 4 5 6 7 8 |
[root@localhost ~]# systemctl status logstash ● logstash.service - logstash Loaded: loaded (/etc/systemd/system/logstash.service; enabled; vendor preset: disabled) Active: active (running) since 金 2018-08-03 23:49:22 JST; 16s ago (snip) [root@localhost ~]# ss -anplt | grep 5140 LISTEN 0 128 :::5140 :::* users:(("java",pid=1736,fd=87)) |
Ansible Tower設定
(1) Ansible Towerに管理者でログインします。
(2) settings
の TOWERの設定
をクリックします。
(3) システム
をクリックし SUB CATEGORY
を ロギング
にして以下のパラメーターを設定後に テスト
をクリックして動作確認をします。
項目 | パラメーター |
---|---|
ログアグリゲーター | LogstashのIP or Hostname |
ログアグリゲーターポート | Logstashの待ち受けポート |
ログアグリゲーターのタイプ | logstash |
ログアグリゲーターのプロトコル | HTTPS |
ログアグリゲーターのプロトコルでTCPを選ぶとJSONのパースエラーが出ました。ログを見る限りPOSTしてる感じだったので現状はHTTPSでしか受け取れないっぽいです。AWXはTCPでも受け取れました
(4) 成功したことが表示されれば 保存
をクリックします。
(5) ENABLE EXTERNAL LOGGING
を ON
にして 保存
をクリックします。
Kibanaで確認
(1) Management
をクリックして Index Patterns
をクリックします。
(2) Index pattern
に ansible_tower*
を入力してindexに表示されたら Next step
をクリックします。
(3) Time Filter field name
に @timestamp
を選択して Create index pattern
をクリックします。
(4) テストで送信したログが確認できれば完了です。
参考文献
https://www.elastic.co/guide/index.html
https://docs.ansible.com/ansible-tower/latest/html/administration/logging.html