0
0

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 1 year has passed since last update.

定時帰る術-Linux ログ管理(rsyslog)

Posted at

Linux世界のログが大体rsyslogに管理され、/var/log配下に格納されている。
rsyslogを使って、ロカールのログだけではなく、リモートにログ転送することや、リモートからのログ集中管理することもできる。
転送ポート:514

・サービス管理:systemdに管理されているため、systemctl系のコマンドが実行できる。status/start/stop/restart等々
・定義ファイル場所:

[root@mgmt ~]# ll /etc/rsyslog.conf
-rw-r--r-- 1 root root 3489 12月 26  2022 /etc/rsyslog.conf

↓も忘れず

[root@mgmt ~]# grep include /etc/rsyslog.conf
include(file="/etc/rsyslog.d/*.conf" mode="optional")

クライアント側

(Targetのところだけ環境に合わせて設定すれば、普通にいける。以外のはコメントアウトを外すだけ)

action(type="omfwd"
queue.filename="fwdRule1"       # unique name prefix for spool files
queue.saveonshutdown="on"       # save messages to disk on shutdown
queue.type="LinkedList"         # run asynchronously
action.resumeRetryCount="-1"    # infinite retries if host is down
Target="192.168.100.6" Port="514" Protocol="tcp")

修正が終わったら、定義ファイルのチェックしてから、サービスを再起動するようにしよう

[root@mgmt syslog]#  rsyslogd -N 1
rsyslogd: version 8.2102.0-10.el8, config validation run (level 1), master config /etc/rsyslog.conf
rsyslogd: End of config validation run. Bye.
[root@momo ~]# systemctl restart rsyslog

サーバ側

TCPの方がパフォーマンスよく、tcpでいこう
これで、クライアント側にSSHすると、ログがサーバ側の/var/log/syslog/配下にとんでいく。

module(load="imtcp") # needs to be done just once
input(type="imtcp" port="514")
$template RemoteAllLogs,"/var/log/syslog/%HOSTNAME%/%PROGRAMNAME%.log"
$template RemoteSSHLogs,"/var/log/syslog/%HOSTNAME%-ssh.log"
*.warning ?RemoteAllLogs
authpriv.* ?RemoteSSHLogs
$AllowedSender TCP, 192.168.0.0/16

やってみる

クライアント側からテストログを送る

[root@momo ~]# logger -p cron.warning "snow log test"

サーバ側で確認

[root@mgmt momo]# pwd
/var/log/syslog/momo
[root@mgmt momo]#  cat root.log
Oct 31 22:51:30 momo root[319241]: snow log test

設定ファイルの考え方

facilityとpriorityがあり、↓が考え方
facilityのpriorityログを/var/log/snowにはくということ
facility.priority /var/log/snow
例えば、デフォルトの場合、メール、認証、cronログの除いて、全部のwarningログを「/var/log/messages」に出力する。
*.warning;mail.none;authpriv.none;cron.none /var/log/messages

よく使うfacilityの種類

authpriv、cron,、daemon、kern、mail、syslog、user、local0 ~ local7

よく使うpriorityの種類

debug、info、notice、warn、err、crit、alert

テンプレート

↑の例では、HOSTNAMEとPROGRAMNAMEを設定したが、その以外もいろんなモノがあり、詳しくはgoogle先生に聞いてみよう。

最後

ここらへんの種類(facility、priority、テンプレート)が多すぎで、川口も年をとって覚えられなく、基本的にはgoogle先生にききながら、やっていく感じ
だが、ネット上の記事通りにやるだけではなく、ちゃんとloggerコマンドで確認することが重要

トラブルシューティング

↓にはよく問題ある箇所

■サービスの状態
■ディスクの容量
■ディレクトリの権限
■ping疎通
■ポート番号
■tcp/udp
■FW
■selinux

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?