3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

apacheなどのファイル形式のログをsyslogとしてリモートに転送する

Posted at

はじめに

いろんなサーバから吐き出されるファイル形式のログをリモートのsyslogに集約しています。
ログを吐くサーバ側での設定は、必要最低限の設定として、加工やらなんやらはリモートで実施するようにします。

apacheのsyslogを別ホストに転送したかった。ので、メモ。

設定したいもの

今回の事例では、トラフィック収集ツールの cacti が稼働しているサーバから
apacheのアクセスログとcactiログをリモートのsyslogサーバへ転送します。

syslog転送先ホストの設定

  • syslog(同じdocker networkにいるsyslogサーバ)
  • 10.10.254.10.112

これらにログを送付するために、rsyslogの設定ファイルに追加します。

/etc/rsyslog.conf
--------8<----(snip)----8<--------
module(load="imfile")

input(type="imfile"
      file="/var/log/httpd/access_log"
      tag="pseudolog_httpd_access_log"
      facility="local0"
      severity="notice")
:syslogtag, isequal, "pseudolog_httpd_access_log" @syslog:514
& @10.254.10.112:514

input(type="imfile"
      file="/usr/share/cacti/log/cacti.log"
      tag="pseudolog_cacti_log"
      facility="local0"
      severity="notice")
:syslogtag, isequal, "pseudolog_cacti_log" @syslog:514
& @10.254.10.112:514
--------8<----(snip)----8<--------

この例では、514/udpで送信してますが、 @@address:port と(@を2つ並べる)すると、TCPの転送になります。
同一のdockerネットワークに所属させているため、ホスト名syslogで転送可能な状態となっています。
ほかのファイルに吐かれているログも上記同様に指定すると、転送できます。

rsyslog.conf(設定ファイル)の書き方
# モジュールを読み込む。これは最初に1回記載すればよいです。
module(load="imfile")

# input() の箇所でsyslogへ入力するソース(今回はimfile)を指定します。
#  type:ソースの種別です。今回はimfileモジュール経由
#  file:imfileで検知させる対象ファイル名
#  tag:転送する際のsyslogタグを指定
#  facility:転送する際のfacilityを指定
#  severity:転送する際のseverityを指定
input(type="imfile" file="/var/log/httpd/access_log" tag="pseudolog_httpd_access_log" facility="local0" severity="notice")

# どのような条件に場合に、どのような処理をするか、を記載していきます
# 下記の場合は、
#   条件:syslogtagがpseudolog_httpd_access_logの場合
#   処理:syslogというホスト名に対して、UDP:514ポートで転送
# 条件に対して、複数の処理を行いたい場合には、直後の行に & で処理を記載します。
:syslogtag, isequal, "pseudolog_httpd_access_log" @syslog:514
& @10.254.10.112:514

設定したら、サービスの再起動

systemctl rsyslog restart

syslog転送先ホストで確認

Feb 11 21:58:22,Feb 11 21:58:22,VMinfraserv05,pseudolog_httpd_access_log,5,16, 10.254.10.11 - - [11/Feb/2020:21:58:19 +0900] "GET /cacti/graph_json.php?rra_id=0&local_graph_id=36&graph_start=1581339497&graph_end=1581425897&graph_height=200&graph_width=700 HTTP/1.1" 200 35392 "http://cacti/cacti/graph_view.php?action=tree&node=tbranch-5&host_id=3&site_id=-1&host_template_id=-1&hgd=&hyper=true" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
Feb 11 21:58:22,Feb 11 21:58:22,VMinfraserv05,pseudolog_httpd_access_log,5,16, 10.254.10.11 - - [11/Feb/2020:21:58:19 +0900] "GET /cacti/graph_json.php?rra_id=0&local_graph_id=151&graph_start=1581339497&graph_end=1581425897&graph_height=200&graph_width=700 HTTP/1.1" 200 53103 "http://cacti/cacti/graph_view.php?action=tree&node=tbranch-5&host_id=3&site_id=-1&host_template_id=-1&hgd=&hyper=true" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
Feb 11 21:58:32,Feb 11 21:58:32,VMinfraserv05,pseudolog_httpd_access_log,5,16, ::1 - - [11/Feb/2020:21:58:28 +0900] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.6 (CentOS) PHP/5.4.16 (internal dummy connection)"
Feb 11 22:00:12,Feb 11 22:00:12,VMinfraserv05,pseudolog_cacti_log,5,16, 2020/02/11 22:00:08 - SYSTEM STATS: Time:6.4693 Method:spine Processes:1 Threads:1 Hosts:15 HostsPerProcess:15 DataSources:271 RRDsProcessed:143
Feb 11 22:00:12,Feb 11 22:00:12,VMinfraserv05,pseudolog_cacti_log,5,16, 2020/02/11 22:00:08 - SNMPAGENT WARNING: No notification receivers configured for event: cactiNotifyDeviceFailedPoll (CACTI-MIB), severity: medium
Feb 11 22:00:12,Feb 11 22:00:12,VMinfraserv05,pseudolog_cacti_log,5,16, 2020/02/11 22:00:08 - POLLER: Poller[1] WARNING: You have 4 Devices with bad SNMP Indexes.  Devices: Device[1], Device[4], Device[15], Device[17] totalling 17 Data Sources.  Please Either Re-Index, Delete or Disable these Data Sources.

出典

https://knowledge.sakura.ad.jp/8969/
https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/system_administrators_guide/s1-basic_configuration_of_rsyslog
https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/system_administrators_guide/s1-using_rsyslog_modules

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?