ふと、sambaで共有しているファイルへの操作ログを記録できないかと調べてみたところ、VFSモジュールを使うことで設定ができるようなのでやってみることにした。追記する設定例配下。
ちなみに以下の例だと、「test」という共有ディレクトリでの操作ログについて取得するようになっている。全部取得するには”full_audit:success”の値を”vfs_full_audit”に設定してやれば良いのだが、それだと不要なログで溢れてしまうので、必要になるログだけを出力させている(また、failureログについても出力させないようにしている。)。
●/etc/samba/smb.conf
[test] vfs objects = full_audit full_audit:prefix = %u|%I|%m|%S full_audit:success = mkdir rename unlink rmdir pread pwrite full_audit:failure = none full_audit:facility = LOCAL7 full_audit:priority = NOTICE
設定を追記したら、後はサービスを再起動するだけだ。
systemctl restart smb nmb
これで、Sambaからのファイル操作がログに記録されるようになった。実際のログ出力は以下のような感じ。
Apr 1 23:51:35 BS-PUB-MEDIA-02 smbd_audit: nobody|172.xxx.xxx.xxx|main-desktop|test|pread|ok|test_dir/memo.txt Apr 1 23:51:40 BS-PUB-MEDIA-02 smbd_audit: nobody|172.xxx.xxx.xxx|main-desktop|test|pwrite|ok|test_dir/memo.txt Apr 1 23:51:40 BS-PUB-MEDIA-02 smbd_audit: nobody|172.xxx.xxx.xxx|main-desktop|test|pwrite|ok|test_dir/memo.txt
ちゃんとログを記録しておけば、利用頻度の高いファイルやディレクトリについても後から調査できるようになる。
ログに記録する操作内容についてはこちらを、ログのフォーマットについてはこちらを参考にすると良いだろう。
![【改訂新版】サーバ構築の実例がわかるSamba[実践]入門 (Software Design plus)](http://images-fe.ssl-images-amazon.com/images/I/51pL0I%2B7qnL._SL160_.jpg)