syslog はログを取るツールです。起動はユーザーが指定することなく/etc/defaults/rc.conf によって自動稼動されます。
syslog で何のログを取るかを決めるのは /etc/syslog.conf の設定によります。
ログは取れるものは全て取っておくべきなので、デフォルトから不要なものを削除したりはしません。
ここでは、console.log と all.log を有効化します。console.log は /dev/console に出力されるものを、all.log は syslog でロギングできるものを全て書き込んでいきます。
*.err;kern.debug;auth.notice;mail.crit /dev/console *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err /var/log/messages security.* /var/log/security auth.info;authpriv.info /var/log/auth.log mail.info /var/log/maillog lpr.info /var/log/lpd-errs ftp.info /var/log/xferlog cron.* /var/log/cron *.=debug /var/log/debug.log *.emerg * # uncomment this to log all writes to /dev/console to /var/log/console.log console.info /var/log/console.log # uncomment this to enable logging of all log messages to /var/log/all.log # touch /var/log/all.log and chmod it to mode 600 before it will work *.* /var/log/all.log # uncomment this to enable logging to a remote loghost named loghost #*.* @loghost # uncomment these if you're running inn # news.crit /var/log/news/news.crit # news.err /var/log/news/news.err # news.notice /var/log/news/news.notice !startslip *.* /var/log/slip.log !ppp *.* /var/log/ppp.log
newsyslog は古いログを圧縮して新しく作り直すツールです。ログは syslog で作成されたもの以外でも問題ありません。
newsyslog の起動は、/etc/crontab によって毎時0分に実行されるので、ログを切り替えるタイミングも0分となります。
/etc/newsyslog.conf でログを切り替えるタイミングを決めます。タイミングは特定のサイズ、若しくは時間を選択できます。
count | 7 | 古いログを最大7つまで保存 |
size | 100 | 100KB |
when | @T00 | 毎日午前0時 |
when | $M1D0 | 毎月1日午前0時 |
when | $W6D0 | 毎週土曜日午前0時 |
flags | j | bzip2 で圧縮 |
# configuration file for newsyslog # # logfilename [owner:group] mode count size when flags [/pid_file] [sig_num] /var/log/all.log 600 7 * @T00 J /var/log/amd.log 644 7 100 * J /var/log/auth.log 600 7 100 * J /var/log/console.log 600 5 100 * J /var/log/cron 600 3 100 * J /var/log/daily.log 640 7 * @T00 JN /var/log/debug.log 600 7 100 * J /var/log/kerberos.log 600 7 100 * J /var/log/lpd-errs 644 7 100 * J /var/log/maillog 640 7 * @T00 J /var/log/messages 644 5 100 * J /var/log/monthly.log 640 12 * JN /var/log/ppp.log root:network 640 3 100 * J /var/log/security 600 10 100 * J /var/log/sendmail.st 640 10 * 168 B /var/log/slip.log root:network 640 3 100 * J /var/log/weekly.log 640 5 1 JN /var/log/wtmp 644 3 * @01T05 B /var/log/xferlog 600 7 100 * J
# bzip2 -d maillog.0.bz2
とすると maillog.0 が作成され、maillog.0.bz2 は削除されます。
# bzip2 -z maillog.0
cron は定期的にコマンドを実行するプログラムです。root の他、ユーザー権限でも動作させることが出来ます。
起動はユーザーが指定することなく /etc/defaults/rc.conf によって自動稼動されます。
root 権限で定期的に実行するコマンドは /etc/crontab に設定します。デフォルトでは次のようになっています。
# /etc/crontab - root's crontab for FreeBSD # # : src/etc/crontab,v 1.32 2002/11/22 16:13:39 tom Exp $ # SHELL=/bin/sh PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin HOME=/var/log # #minute hour mday month wday who command # */5 * * * * root /usr/libexec/atrun # # Save some entropy so that /dev/random can re-seed on boot. */11 * * * * operator /usr/libexec/save-entropy # # Rotate log files every hour, if necessary. 0 * * * * root newsyslog # # Perform daily/weekly/monthly maintenance. 1 3 * * * root periodic daily 15 4 * * 6 root periodic weekly 30 5 1 * * root periodic monthly # # Adjust the time zone if the CMOS clock keeps local time, as opposed to # UTC time. See adjkerntz(8) for details. 1,31 0-5 * * * root adjkerntz -a
/etc/aliases ではシステムが自動発行するメールを誰に渡すかを決めます。
# : src/etc/mail/aliases,v 1.18 2003/04/27 05:49:53 imp Exp $ # @(#)aliases 5.3 (Berkeley) 5/24/90 # # Aliases in this file will NOT be expanded in the header from # Mail, but WILL be visible over networks. # # >>>>>>>>>> The program "newaliases" must be run after # >> NOTE >> this file is updated for any changes to # >>>>>>>>>> show through to sendmail. # # # See also RFC 2142, `MAILBOX NAMES FOR COMMON SERVICES, ROLES # AND FUNCTIONS', May 1997 # Pretty much everything else in this file points to "root", so # you would do well in either reading root's mailbox or forwarding # root's email from here. root: username # Basic system aliases -- these MUST be present MAILER-DAEMON: postmaster postmaster: root # General redirections for pseudo accounts bin: root bind: root daemon: root games: root kmem: root mailnull: postmaster man: root news: root nobody: root operator: root pop: root smmsp: postmaster sshd: root system: root toor: root tty: root usenet: news uucp: root # Well-known aliases -- these should be filled in! # manager: # dumper: # BUSINESS-RELATED MAILBOX NAMES # info: # marketing: # sales: # support: # NETWORK OPERATIONS MAILBOX NAMES abuse: root # noc: root security: root # SUPPORT MAILBOX NAMES FOR SPECIFIC INTERNET SERVICES ftp: root ftp-bugs: ftp # hostmaster: root webmaster: root www: webmaster # NOTE: /var/msgs and /var/msgs/bounds must be owned by sendmail's # DefaultUser (defaults to mailnull) for the msgs alias to work. # # msgs: "| /usr/bin/msgs -s" # bit-bucket: /dev/null # dev-null: bit-bucket