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

Return to bug 168305