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