View | Details | Raw Unified | Return to bug 168305 | Differences between
and this patch

Collapse All | Expand All

(-)head/en_US.ISO8859-1/books/handbook/config/chapter.sgml (-100 / +267 lines)
Lines 1415-1420 Link Here
1415
1415
1416
  </sect1>
1416
  </sect1>
1417
1417
1418
  <sect1 id="configtuning-syslog">
1419
    <sect1info>
1420
      <authorgroup>
1421
	<author>
1422
	  <firstname>Niclas</firstname>
1423
	  <surname>Zeising</surname>
1424
	  <contrib>Contributed by </contrib>
1425
	  <!-- 24 May 2012 -->
1426
	</author>
1427
      </authorgroup>
1428
    </sect1info>
1429
1430
    <title>Configuring the system logger <application>syslogd</application></title>
1431
1432
    <indexterm><primary>system logging</primary></indexterm>
1433
    <indexterm><primary>syslog</primary></indexterm>
1434
    <indexterm><primary>syslogd</primary></indexterm>
1435
1436
    <para>System logging is an important aspect of system administration.
1437
      It is used both to detect hardware and software issues and errors in
1438
      the system, as well as playing a very important role in security
1439
      auditing and incident response.  System daemons without a controlling
1440
      terminal also usually logs information to a system logging facility or
1441
      other log file.</para>
1442
    <para>This section will describe how to configure and use the &os; system
1443
      logger, <application>syslogd</application> as well as discuss log rotation
1444
      and log management using <application>newsyslog</application>.  Focus
1445
      will be on setting up and using <application>syslogd</application> on
1446
      a local machine.  For more advanced setups using a separate loghost, see
1447
      <xref linkend="network-syslogd">.</para>
1448
1449
    <sect2>
1450
      <title>Using <application>syslogd</application></title>
1451
      <para>In the default &os; configuration &man.syslogd.8; is started by
1452
	default on startup.  This is controlled by the variable
1453
	<literal>syslogd_enable</literal> in <filename>/etc/rc.conf</filename>.
1454
	There are numerous application arguments that affect the behavior of
1455
	<application>syslogd</application>.  To change them, use
1456
	<literal>syslogd_flags</literal> in <filename>/etc/rc.conf</filename>.
1457
	Refer to &man.syslogd.8; for more information on the arguments, and
1458
	&man.rc.conf.5;, <xref linkend="configtuning-core-configuration">
1459
	and <xref linkend="configtuning-rcd"> for more information about
1460
	<filename>/etc/rc.conf</filename> and the &man.rc.8; subsystem.</para>
1461
    </sect2>
1462
1463
    <sect2>
1464
      <title>Configuring <application>syslogd</application></title>
1465
1466
      <indexterm><primary>syslog.conf</primary></indexterm>
1467
1468
      <para>The configuration file, by default
1469
	<filename>/etc/syslog.conf</filename>, controls what &man.syslogd.8;
1470
	should do with the log entries once they are received.  There are
1471
	several parameters to control the handling of incoming events, of
1472
	which the most basic are facility and level.  The facility describes
1473
	which subsystem generated the message, such as the kernel or a daemon,
1474
	and the level describes the severity of the event that occurred.  This
1475
	makes it possible to log the message to different log files, or
1476
	discard it, depending on the facility and level.  It is also possible
1477
	to take action depending on the application that sent the message, and
1478
	in the case of remote logging, also the host of the machine generating
1479
	the logging event.</para>
1480
      <para>Configuring <application>syslogd</application> is quite straight
1481
	forward.  The configuration file contains one line per action, and
1482
	the syntax for each line is a selector field followed by an action
1483
	field.  The syntax of the selector field is
1484
	<literal>facility.level</literal> and this will match log messages
1485
	from <literal>facility</literal> at level <literal>level</literal> or
1486
	higher.  It is also possible to add an optional comparison flag
1487
	before the level to be able to specify more exact what is logged.
1488
	Multiple selector fields can be used for the same action, and are
1489
	separated with a semicolon (<literal>;</literal>).  Using
1490
	<literal>*</literal> will match everything.
1491
	The action filed is where to send the log message, e.g. a file or
1492
	a remote log host.  As an example, here is the default
1493
	<filename>syslog.conf</filename> from &os;:</para>
1494
      <programlisting># &dollar;&os;&dollar;
1495
#
1496
#       Spaces ARE valid field separators in this file. However,
1497
#       other *nix-like systems still insist on using tabs as field
1498
#       separators. If you are sharing this file between systems, you
1499
#       may want to use only tabs as field separators here.
1500
#       Consult the &man.syslog.conf.5; manpage.
1501
*.err;kern.warning;auth.notice;mail.crit                /dev/console <co id="co-syslog-1">
1502
*.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages
1503
security.*                                      /var/log/security
1504
auth.info;authpriv.info                         /var/log/auth.log
1505
mail.info                                       /var/log/maillog <co id="co-syslog-2">
1506
lpr.info                                        /var/log/lpd-errs
1507
ftp.info                                        /var/log/xferlog
1508
cron.*                                          /var/log/cron
1509
*.=debug                                        /var/log/debug.log <co id="co-syslog-3">
1510
*.emerg                                         *
1511
# uncomment this to log all writes to /dev/console to /var/log/console.log
1512
#console.info                                   /var/log/console.log
1513
# uncomment this to enable logging of all log messages to /var/log/all.log
1514
# touch /var/log/all.log and chmod it to mode 600 before it will work
1515
#*.*                                            /var/log/all.log
1516
# uncomment this to enable logging to a remote loghost named loghost
1517
#*.*                                            @loghost
1518
# uncomment these if you're running inn
1519
# news.crit                                     /var/log/news/news.crit
1520
# news.err                                      /var/log/news/news.err
1521
# news.notice                                   /var/log/news/news.notice
1522
!ppp <co id="co-syslog-4">
1523
*.*                                             /var/log/ppp.log
1524
!*</programlisting>
1525
1526
      <calloutlist>
1527
	<callout arearefs="co-syslog-1">
1528
	  <para>This line matches all messages with a level of
1529
	    <literal>err</literal> or higher, as well as
1530
	    <literal>kern.warning</literal>, <literal>auth.notice</literal>
1531
	    and <literal>mail.crit</literal> and sends these log messages
1532
	    to the console (<filename>/dev/console</filename>).</para>
1533
	</callout>
1534
	<callout arearefs="co-syslog-2">
1535
	  <para>This line matches all messages from the <literal>mail</literal>
1536
	    facility at level <literal>info</literal> or above, and logs the
1537
	    messages to <filename>/var/log/maillog</filename>.</para>
1538
	</callout>
1539
	<callout arearefs="co-syslog-3">
1540
	  <para>This line utilizes a comparison flag, <literal>=</literal>
1541
	    to only match all messages at level <literal>debug</literal>, and
1542
	    logs them in <filename>/var/log/debug.log</filename>.</para>
1543
	</callout>
1544
	<callout arearefs="co-syslog-4">
1545
	  <para>This line uses a so called program specification, which means
1546
	    that the block following that to the next program specification
1547
	    will only match for messages from that program.  In this example
1548
	    this line and the following will make all messages from
1549
	    <application>ppp</application> end up in
1550
	    <filename>/var/log/ppp.log</filename>.</para>
1551
	</callout>
1552
      </calloutlist>
1553
1554
      <para>As can be seen from the configuration file above, there are
1555
	plenty of levels and subsystems.  The levels are, in order from most
1556
	to least critical: <literal>emerg</literal>, <literal>alert</literal>,
1557
	<literal>crit</literal>, <literal>err</literal>,
1558
	<literal>warning</literal>, <literal>notice</literal>,
1559
	<literal>info</literal> and <literal>debug</literal>.</para>
1560
      <para>The facilities are, in no particular order:
1561
	<literal>auth</literal>, <literal>authpriv</literal>,
1562
	<literal>console</literal>, <literal>cron</literal>,
1563
	<literal>daemon</literal>, <literal>ftp</literal>,
1564
	<literal>kern</literal>, <literal>lpr</literal>,
1565
	<literal>mail</literal>, <literal>mark</literal>,
1566
	<literal>news</literal>, <literal>security</literal>,
1567
	<literal>syslog</literal>, <literal>user</literal>,
1568
	<literal>uucp</literal> and <literal>local0</literal> through
1569
	<literal>local7</literal>.  Be aware that other operating systems
1570
	might have different facilities.</para>
1571
      <para>With this knowledge it is easy to add a new line to
1572
	<filename>/etc/syslog.conf</filename> to log everything from the
1573
	different daemons on level notice and higher to
1574
	<filename>/var/log/daemon.log</filename>. Just add the following:</para>
1575
      <programlisting>daemon.notice                                        /var/log/daemon.log</programlisting>
1576
      <para>For more information about the different levels and facilities,
1577
	refer to &man.syslog.3; and &man.syslogd.8;.  For more information
1578
	about <filename>syslog.conf</filename>, its syntax and more advanced
1579
	usage examples, refer to &man.syslog.conf.5; and
1580
	<xref linkend="network-syslogd">.</para>
1581
    </sect2>
1582
1583
    <sect2>
1584
      <title>Log management and rotation with 
1585
	<application>newsyslog</application></title>
1586
1587
      <indexterm><primary>newsyslog</primary></indexterm>
1588
      <indexterm><primary>newsyslog.conf</primary></indexterm>
1589
      <indexterm><primary>log rotation</primary></indexterm>
1590
      <indexterm><primary>log management</primary></indexterm>
1591
1592
      <para>Log files tend to grow quickly and accumulate steadily.  This
1593
	leads to the log files being full of less immediately useful,
1594
	information, as well as filling up the hard drive.  To mitigate
1595
	this log management comes into play.  In &os;, &man.newsyslog.8; is
1596
	the tool used to manage log files.  The
1597
	<application>newsyslog</application> application is used to
1598
	periodically rotate and compress log files, as well as optionally
1599
	create missing log files and signal programs when log files are moved.
1600
	The log files does not necessarily have to come from syslog,
1601
	<application>newsyslog</application> works with any logs written from
1602
	any program.  It is important to note that
1603
	<application>newsyslog</application> is normally run from &man.cron.8;
1604
	and is not a system daemon.  In the default configuration it is run
1605
	every hour.</para>
1606
      <sect3>
1607
	<title>Configuring <application>newsyslog</application></title>
1608
	<para>To know what actions to take, &man.newsyslog.8; reads its
1609
	  configuration file, by default
1610
	  <filename>/etc/newsyslog.conf</filename>.  This configuration file
1611
	  contains lines, one per log file <application>newsyslog</application>
1612
	  manages and states the file owner, permissions and when to rotate
1613
	  that file, as well as optional flags that affects the log rotation
1614
	  (such as compression) and programs to signal when the log is rotated.
1615
	  As an example, here is the default configuration in &os;:</para>
1616
	<programlisting># configuration file for newsyslog
1617
# &dollar;&os;&dollar;
1618
#
1619
# Entries which do not specify the '/pid_file' field will cause the
1620
# syslogd process to be signalled when that log file is rotated.  This
1621
# action is only appropriate for log files which are written to by the
1622
# syslogd process (ie, files listed in /etc/syslog.conf).  If there
1623
# is no process which needs to be signalled when a given log file is
1624
# rotated, then the entry for that file should include the 'N' flag.
1625
#
1626
# The 'flags' field is one or more of the letters: BCDGJNUXZ or a '-'.
1627
#
1628
# Note: some sites will want to select more restrictive protections than the
1629
# defaults.  In particular, it may be desirable to switch many of the 644
1630
# entries to 640 or 600.  For example, some sites will consider the
1631
# contents of maillog, messages, and lpd-errs to be confidential.  In the
1632
# future, these defaults may change to more conservative ones.
1633
#
1634
# logfilename          [owner:group]    mode count size when  flags [/pid_file] [sig_num]
1635
/var/log/all.log                        600  7     *    @T00  J
1636
/var/log/amd.log                        644  7     100  *     J
1637
/var/log/auth.log                       600  7     100  @0101T JC
1638
/var/log/console.log                    600  5     100  *     J
1639
/var/log/cron                           600  3     100  *     JC
1640
/var/log/daily.log                      640  7     *    @T00  JN
1641
/var/log/debug.log                      600  7     100  *     JC
1642
/var/log/init.log                       644  3     100  *     J
1643
/var/log/kerberos.log                   600  7     100  *     J
1644
/var/log/lpd-errs                       644  7     100  *     JC
1645
/var/log/maillog                        640  7     *    @T00  JC
1646
/var/log/messages                       644  5     100  @0101T JC
1647
/var/log/monthly.log                    640  12    *    $M1D0 JN
1648
/var/log/pflog                          600  3     100  *     JB    /var/run/pflogd.pid
1649
/var/log/ppp.log        root:network    640  3     100  *     JC
1650
/var/log/security                       600  10    100  *     JC
1651
/var/log/sendmail.st                    640  10    *    168   B
1652
/var/log/utx.log                        644  3     *    @01T05 B
1653
/var/log/weekly.log                     640  5     1    $W6D0 JN
1654
/var/log/xferlog                        600  7     100  *     JC</programlisting>
1655
1656
	<para>As seen above, each line starts with the name of the
1657
	  log file to be rotated.  This is followed by an optional owner
1658
	  and group specification of both rotated and newly created files.
1659
	  The next field, <literal>mode</literal> is the mode of the files
1660
	  and <literal>count</literal> is how many rotated log files that
1661
	  should be kept.  The <literal>size</literal> and
1662
	  <literal>when</literal> fields tells
1663
	  <application>newsyslog</application> when to rotate the log file.
1664
	  A log file is rotated once either its size is larger than the
1665
	  <literal>size</literal> field specification, or when the time in the
1666
	  <literal>when</literal> filed has passed. An asterisk,
1667
	  <literal>*</literal> means that this field is ignored.  The
1668
	  <literal>flags</literal> field gives
1669
	  <application>newsyslog</application> further instructions, such as
1670
	  how to compress the rotated file, or to create the log file if
1671
	  it is missing.  The last two fields are optional, and specifies
1672
	  a <acronym role="Process Identifier">PID</acronym>-file of a process
1673
	  as well as a signal number to signal that process with when the log
1674
	  file is rotated.  For more information on all fields, valid flags
1675
	  and how to specify the rotation time, refer to
1676
	  &man.newsyslog.conf.5;.  Remember also that
1677
	  <application>newsyslog</application> is run from
1678
	  <application>cron</application> and can not rotate files more often
1679
	  than when it is run from &man.cron.8;.</para>
1680
      </sect3>
1681
    </sect2>
1682
  </sect1>
1683
1684
1418
  <sect1 id="configtuning-configfiles">
1685
  <sect1 id="configtuning-configfiles">
1419
    <title>Configuration Files</title>
1686
    <title>Configuration Files</title>
1420
1687
Lines 1618-1723 Link Here
1618
      </sect3>
1885
      </sect3>
1619
    </sect2>
1886
    </sect2>
1620
1887
1621
    <sect2>
1622
      <title>Log File Configuration</title>
1623
1624
      <indexterm><primary>log files</primary></indexterm>
1625
1626
      <sect3>
1627
	<title><filename>syslog.conf</filename></title>
1628
1629
	<indexterm><primary>syslog.conf</primary></indexterm>
1630
1631
	<para><filename>syslog.conf</filename> is the configuration
1632
	  file for the &man.syslogd.8; program.  It indicates which
1633
	  types of <command>syslog</command> messages are logged to
1634
	  particular log files.</para>
1635
1636
	<programlisting># &dollar;&os;&dollar;
1637
#
1638
#       Spaces ARE valid field separators in this file. However,
1639
#       other *nix-like systems still insist on using tabs as field
1640
#       separators. If you are sharing this file between systems, you
1641
#       may want to use only tabs as field separators here.
1642
#       Consult the syslog.conf(5) manual page.
1643
*.err;kern.debug;auth.notice;mail.crit          /dev/console
1644
*.notice;kern.debug;lpr.info;mail.crit;news.err /var/log/messages
1645
security.*                                      /var/log/security
1646
mail.info                                       /var/log/maillog
1647
lpr.info                                        /var/log/lpd-errs
1648
cron.*                                          /var/log/cron
1649
*.err                                           root
1650
*.notice;news.err                               root
1651
*.alert                                         root
1652
*.emerg                                         *
1653
# uncomment this to log all writes to /dev/console to /var/log/console.log
1654
#console.info                                   /var/log/console.log
1655
# uncomment this to enable logging of all log messages to /var/log/all.log
1656
#*.*                                            /var/log/all.log
1657
# uncomment this to enable logging to a remote log host named loghost
1658
#*.*                                            @loghost
1659
# uncomment these if you're running inn
1660
# news.crit                                     /var/log/news/news.crit
1661
# news.err                                      /var/log/news/news.err
1662
# news.notice                                   /var/log/news/news.notice
1663
!startslip
1664
*.*                                             /var/log/slip.log
1665
!ppp
1666
*.*                                             /var/log/ppp.log</programlisting>
1667
1668
	<para>Consult the &man.syslog.conf.5; manual page for more
1669
	  information.</para>
1670
      </sect3>
1671
1672
      <sect3>
1673
	<title><filename>newsyslog.conf</filename></title>
1674
1675
	<indexterm><primary>newsyslog.conf</primary></indexterm>
1676
1677
	<para><filename>newsyslog.conf</filename> is the configuration
1678
	  file for &man.newsyslog.8;, a program that is normally
1679
	  scheduled to run by &man.cron.8;.  &man.newsyslog.8;
1680
	  determines when log files require archiving or rearranging.
1681
	  <filename>logfile</filename> is moved to
1682
	  <filename>logfile.0</filename>,
1683
	  <filename>logfile.0</filename> is moved to
1684
	  <filename>logfile.1</filename>, and so on.  Alternatively,
1685
	  the log files may be archived in &man.gzip.1; format causing
1686
	  them to be named: <filename>logfile.0.gz</filename>,
1687
	  <filename>logfile.1.gz</filename>, and so on.</para>
1688
1689
	<para><filename>newsyslog.conf</filename> indicates which log
1690
	  files are to be managed, how many are to be kept, and when
1691
	  they are to be touched.  Log files can be rearranged and/or
1692
	  archived when they have either reached a certain size, or at
1693
	  a certain periodic time/date.</para>
1694
1695
	<programlisting># configuration file for newsyslog
1696
# &dollar;&os;&dollar;
1697
#
1698
# filename          [owner:group]    mode count size when [ZB] [/pid_file] [sig_num]
1699
/var/log/cron                           600  3     100  *     Z
1700
/var/log/amd.log                        644  7     100  *     Z
1701
/var/log/kerberos.log                   644  7     100  *     Z
1702
/var/log/lpd-errs                       644  7     100  *     Z
1703
/var/log/maillog                        644  7     *    @T00  Z
1704
/var/log/sendmail.st                    644  10    *    168   B
1705
/var/log/messages                       644  5     100  *     Z
1706
/var/log/all.log                        600  7     *    @T00  Z
1707
/var/log/slip.log                       600  3     100  *     Z
1708
/var/log/ppp.log                        600  3     100  *     Z
1709
/var/log/security                       600  10    100  *     Z
1710
/var/log/wtmp                           644  3     *    @01T05 B
1711
/var/log/daily.log                      640  7     *    @T00  Z
1712
/var/log/weekly.log                     640  5     1    $W6D0 Z
1713
/var/log/monthly.log                    640  12    *    $M1D0 Z
1714
/var/log/console.log                    640  5     100  *     Z</programlisting>
1715
1716
	<para>Consult the &man.newsyslog.8; manual page for more
1717
	  information.</para>
1718
      </sect3>
1719
    </sect2>
1720
1721
    <sect2 id="configtuning-sysctlconf">
1888
    <sect2 id="configtuning-sysctlconf">
1722
      <title><filename>sysctl.conf</filename></title>
1889
      <title><filename>sysctl.conf</filename></title>

Return to bug 168305