mutao.net

いわゆる雑記。

td-agentを入れてapacheのログ監視をしてみる

td-agentインストール

docs.fluentd.org

curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent4.sh | sh
systemctl start td-agent.service
systemctl status td-agent.service

apacheインストール

# apche起動用ユーザの作成
useradd -s /sbin/nologin www
passwd www

# httpd install
dnf list | grep httpd
dnf -y install httpd httpd-tools httpd-devel httpd-manual

systemctl start httpd
systemctl status httpd
systemctl enable httpd

# firewall設定
firewall-cmd --add-service=http --permanent
firewall-cmd --reload

td-agentの設定

<source>
  @type tail
  path /var/log/httpd/access_log
  format apache2
  pos_file /var/log/td-agent/httpd.access.log.pos
  tag apache2.access
</source>
<match apache2.access>
  @type elasticsearch
  host 127.0.0.1
  port 9200
  type_name apache_access
  logstash_format true
</match>

td-agentを再起動する。

以下のコマンドでtd-agentでapacheのログを監視しているか動作確認が可能。

# curl -XGET localhost:9200/_alias?pretty
{
{省略}
  "logstash-2021.05.30" : {
    "aliases" : { }
  }
}

f:id:mutaonet:20210530215117p:plain

次回はDBからデータを読み取り全文検索エンジンとしての運用を試みる。