glfs/general/sysutils/logrotate.xml
Xi Ruoyao 45ab6c70c2
more SVN prop clean up
Remove "$LastChanged$" everywhere, and also some unused $Date$
2021-04-20 19:12:02 +08:00

320 lines
9.0 KiB
XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % general-entities SYSTEM "../../general.ent">
%general-entities;
<!ENTITY logrotate-download-http "https://github.com/logrotate/logrotate/releases/download/&logrotate-version;/logrotate-&logrotate-version;.tar.xz">
<!ENTITY logrotate-download-ftp " ">
<!ENTITY logrotate-md5sum "c21e586457db80e70606b45a9d84dfe8">
<!ENTITY logrotate-size "160 KB">
<!ENTITY logrotate-buildsize "5.6 MB">
<!ENTITY logrotate-time "0.2 SBU (with tests)">
]>
<sect1 id="logrotate" xreflabel="logrotate-&logrotate-version;">
<?dbhtml filename="logrotate.html"?>
<sect1info>
<date>$Date$</date>
</sect1info>
<title>Logrotate-&logrotate-version;</title>
<indexterm zone="logrotate">
<primary sortas="a-logrotate">logrotate</primary>
</indexterm>
<sect2 role="package">
<title>Introduction to Logrotate</title>
<para>
The <application>logrotate</application> package allows automatic
rotation, compression, removal, and mailing of log files.
</para>
&lfs101_checked;
<bridgehead renderas="sect3">Package Information</bridgehead>
<itemizedlist spacing="compact">
<listitem>
<para>
Download (HTTP): <ulink url="&logrotate-download-http;"/>
</para>
</listitem>
<listitem>
<para>
Download (FTP): <ulink url="&logrotate-download-ftp;"/>
</para>
</listitem>
<listitem>
<para>
Download MD5 sum: &logrotate-md5sum;
</para>
</listitem>
<listitem>
<para>
Download size: &logrotate-size;
</para>
</listitem>
<listitem>
<para>
Estimated disk space required: &logrotate-buildsize;
</para>
</listitem>
<listitem>
<para>
Estimated build time: &logrotate-time;
</para>
</listitem>
</itemizedlist>
<bridgehead renderas="sect3">Logrotate Dependencies</bridgehead>
<bridgehead renderas="sect4">Required</bridgehead>
<para role="required">
<xref linkend="popt"/>
</para>
<bridgehead renderas="sect4" revision="sysv">Recommended</bridgehead>
<para role="recommended" revision="sysv">
<xref role="runtime" linkend="fcron"/> (runtime)
</para>
<bridgehead renderas="sect4">Optional</bridgehead>
<para role="optional">
An <xref role="runtime" linkend="server-mail"/> (runtime)
</para>
<para condition="html" role="usernotes">User Notes:
<ulink url="&blfs-wiki;/logrotate"/>
</para>
</sect2>
<sect2 role="installation">
<title>Installation of Logrotate</title>
<para>
Install <application>logrotate</application> by running the following
command:
</para>
<screen><userinput>./configure --prefix=/usr &amp;&amp;
make</userinput></screen>
<para>
To test the results, issue: <command>make test</command>. One test
fails because the very old <command>compress</command> is not
present and two tests fail if an MTA is not installed.
</para>
<para>
Now, as the <systemitem class="username">root</systemitem> user:
</para>
<screen role="root"><userinput>make install</userinput></screen>
</sect2>
<sect2 role="configuration">
<title>Configuring Logrotate</title>
<para>
<application>Logrotate</application> needs a configuration file,
which must be passed as an argument to the command when executed. Create
the file as the <systemitem class="username">root</systemitem> user:
</para>
<screen role="root"><userinput>cat &gt; /etc/logrotate.conf &lt;&lt; EOF
<literal># Begin /etc/logrotate.conf
# Rotate log files weekly
weekly
# Don't mail logs to anybody
nomail
# If the log file is empty, it will not be rotated
notifempty
# Number of backups that will be kept
# This will keep the 2 newest backups only
rotate 2
# Create new empty files after rotating old ones
# This will create empty log files, with owner
# set to root, group set to sys, and permissions 664
create 0664 root sys
# Compress the backups with gzip
compress
# No packages own lastlog or wtmp -- rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
rotate 1
}
/var/log/lastlog {
monthly
rotate 1
}
# Some packages drop log rotation info in this directory
# so we include any file in it.
include /etc/logrotate.d
# End /etc/logrotate.conf</literal>
EOF
chmod -v 0644 /etc/logrotate.conf</userinput></screen>
<para>
Now create the <filename class='directory'>/etc/logrotate.d</filename>
directory as the <systemitem class="username">root</systemitem> user:
</para>
<screen role="root"><userinput>mkdir -p /etc/logrotate.d</userinput></screen>
<para>
At this point additional log rotation commands can be entered, typically
in the <filename class='directory'>/etc/logrotate.d</filename> directory.
For example:
</para>
<screen role="nodump"><userinput>cat &gt; /etc/logrotate.d/sys.log &lt;&lt; EOF
<literal>/var/log/sys.log {
# If the log file is larger than 100kb, rotate it
size 100k
rotate 5
weekly
postrotate
/bin/killall -HUP syslogd
endscript
}</literal>
EOF
chmod -v 0644 /etc/logrotate.d/sys.log</userinput></screen>
<para>
You can designate multiple files in one entry:
</para>
<screen role="nodump"><userinput>cat &gt; /etc/logrotate.d/example.log &lt;&lt; EOF
<literal>file1
file2
file3 {
...
postrotate
...
endscript
}</literal>
EOF
chmod -v 0644 /etc/logrotate.d/example.log</userinput></screen>
<para>
You can use in the same line the list of files: file1 file2 file3.
See the logrotate man page or <ulink
url='http://www.techrepublic.com/article/manage-linux-log-files-with-logrotate/'/>
for more examples.
</para>
<para>
The command <command>logrotate /etc/logrotate.conf</command> can be
run manually, however, the command should be run daily.
Other useful commands are <command>logrotate -d
/etc/logrotate.conf</command> for debugging purposes and
<command>logrotate -f /etc/logrotate.conf</command> forcing the
logrotate commands to be run immediately. Combining the previous options
<option>-df</option>, you can debug the effect of the force command.
When debugging, the commands are only simulated and are not actually run.
As a result, errors about files not existing will eventually appear because
the files are not actually created.
</para>
<para>
To run the <command>logrotate</command> command daily,
<phrase revision="sysv">if you've installed
<xref linkend="fcron"/> and completed the section on periodic jobs,
execute</phrase><phrase revision="systemd">execute</phrase> the following
commands, as the <systemitem class="username">root</systemitem> user,
to create a <phrase revision="sysv">daily cron job:</phrase>
<phrase revision="systemd">systemd timer to run daily at 3:00 A.M.
(local time):</phrase>
</para>
<screen role="root" revision="sysv"><userinput>cat &gt; /etc/cron.daily/logrotate.sh &lt;&lt; "EOF" &amp;&amp;
<literal>#!/bin/bash
/usr/sbin/logrotate /etc/logrotate.conf</literal>
EOF
chmod 754 /etc/cron.daily/logrotate.sh</userinput></screen>
<screen role="root" revision="systemd"><userinput>cat &gt; /lib/systemd/system/logrotate.service &lt;&lt; "EOF" &amp;&amp;
<literal>[Unit]
Description=Runs the logrotate command
Documentation=man:logrotate(8)
DefaultDependencies=no
After=local-fs.target
Before=shutdown.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/logrotate /etc/logrotate.conf</literal>
EOF
cat &gt; /lib/systemd/system/logrotate.timer &lt;&lt; "EOF" &amp;&amp;
<literal>[Unit]
Description=Runs the logrotate command daily at 3:00 AM
[Timer]
OnCalendar=*-*-* 3:00:00
Persistent=true
[Install]
WantedBy=timers.target</literal>
EOF
systemctl enable logrotate.timer</userinput></screen>
</sect2>
<sect2 role="content">
<title>Contents</title>
<segmentedlist>
<segtitle>Installed Programs</segtitle>
<segtitle>Installed Library</segtitle>
<segtitle>Installed Directories</segtitle>
<seglistitem>
<seg> logrotate </seg>
<seg> None </seg>
<seg> None </seg>
</seglistitem>
</segmentedlist>
<variablelist>
<bridgehead renderas="sect3">Short Descriptions</bridgehead>
<?dbfo list-presentation="list"?>
<?dbhtml list-presentation="table"?>
<varlistentry id="logrotate-prog">
<term><command>logrotate</command></term>
<listitem>
<para>
performs the log maintenance functions defined in the
configuration files
</para>
<indexterm zone="logrotate logrotate-prog">
<primary sortas="b-logrotate-prog">logrotate</primary>
</indexterm>
</listitem>
</varlistentry>
</variablelist>
</sect2>
</sect1>