[92c4b7a] | 1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
| 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
| 3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
| 4 | <!ENTITY % general-entities SYSTEM "../../general.ent">
|
---|
| 5 | %general-entities;
|
---|
| 6 |
|
---|
| 7 | <!ENTITY logrotate-download-http "http://fedorahosted.org/releases/l/o/logrotate/logrotate-&logrotate-version;.tar.gz">
|
---|
| 8 | <!ENTITY logrotate-download-ftp " ">
|
---|
| 9 | <!ENTITY logrotate-md5sum "99e08503ef24c3e2e3ff74cc5f3be213">
|
---|
| 10 | <!ENTITY logrotate-size "64 KB">
|
---|
| 11 | <!ENTITY logrotate-buildsize "1.3 MB">
|
---|
| 12 | <!ENTITY logrotate-time "less than 0.1 SBU">
|
---|
| 13 | ]>
|
---|
| 14 |
|
---|
| 15 | <sect1 id="logrotate" xreflabel="logrotate-&logrotate-version;">
|
---|
| 16 | <?dbhtml filename="logrotate.html"?>
|
---|
| 17 |
|
---|
| 18 | <sect1info>
|
---|
[bc5778f] | 19 | <othername>$LastChangedBy$</othername>
|
---|
| 20 | <date>$Date$</date>
|
---|
[92c4b7a] | 21 | </sect1info>
|
---|
| 22 |
|
---|
| 23 | <title>Logrotate-&logrotate-version;</title>
|
---|
| 24 |
|
---|
| 25 | <indexterm zone="logrotate">
|
---|
| 26 | <primary sortas="a-logrotate">logrotate</primary>
|
---|
| 27 | </indexterm>
|
---|
| 28 |
|
---|
| 29 | <sect2 role="package">
|
---|
| 30 | <title>Introduction to Logrotate</title>
|
---|
| 31 |
|
---|
| 32 | <para>
|
---|
| 33 | The <application>logrotate</application> package allows automatic rotation,
|
---|
| 34 | compression, removal, and mailing of log files.
|
---|
| 35 | </para>
|
---|
| 36 |
|
---|
| 37 | &lfs75_checked;
|
---|
| 38 |
|
---|
| 39 | <bridgehead renderas="sect3">Package Information</bridgehead>
|
---|
| 40 | <itemizedlist spacing="compact">
|
---|
| 41 | <listitem>
|
---|
| 42 | <para>
|
---|
| 43 | Download (HTTP): <ulink url="&logrotate-download-http;"/>
|
---|
| 44 | </para>
|
---|
| 45 | </listitem>
|
---|
| 46 | <listitem>
|
---|
| 47 | <para>
|
---|
| 48 | Download (FTP): <ulink url="&logrotate-download-ftp;"/>
|
---|
| 49 | </para>
|
---|
| 50 | </listitem>
|
---|
| 51 | <listitem>
|
---|
| 52 | <para>
|
---|
| 53 | Download MD5 sum: &logrotate-md5sum;
|
---|
| 54 | </para>
|
---|
| 55 | </listitem>
|
---|
| 56 | <listitem>
|
---|
| 57 | <para>
|
---|
| 58 | Download size: &logrotate-size;
|
---|
| 59 | </para>
|
---|
| 60 | </listitem>
|
---|
| 61 | <listitem>
|
---|
| 62 | <para>
|
---|
| 63 | Estimated disk space required: &logrotate-buildsize;
|
---|
| 64 | </para>
|
---|
| 65 | </listitem>
|
---|
| 66 | <listitem>
|
---|
| 67 | <para>
|
---|
| 68 | Estimated build time: &logrotate-time;
|
---|
| 69 | </para>
|
---|
| 70 | </listitem>
|
---|
| 71 | </itemizedlist>
|
---|
| 72 |
|
---|
| 73 | <bridgehead renderas="sect3">Logrotate Dependencies</bridgehead>
|
---|
| 74 |
|
---|
| 75 | <bridgehead renderas="sect4">Required</bridgehead>
|
---|
| 76 | <para role="required">
|
---|
| 77 | <xref linkend="popt"/>
|
---|
| 78 | </para>
|
---|
| 79 |
|
---|
| 80 | <bridgehead renderas="sect4">Recommended</bridgehead>
|
---|
| 81 | <para role="recommended">
|
---|
| 82 | <xref linkend="fcron"/> (runtime)
|
---|
| 83 | </para>
|
---|
| 84 |
|
---|
| 85 | <bridgehead renderas="sect4">Optional</bridgehead>
|
---|
| 86 | <para role="optional">
|
---|
| 87 | An <xref linkend="server-mail"/> (runtime)
|
---|
| 88 | </para>
|
---|
| 89 |
|
---|
| 90 | <para condition="html" role="usernotes">User Notes:
|
---|
| 91 | <ulink url="&blfs-wiki;/logrotate"/>
|
---|
| 92 | </para>
|
---|
| 93 | </sect2>
|
---|
| 94 |
|
---|
| 95 | <sect2 role="installation">
|
---|
| 96 | <title>Installation of Logrotate</title>
|
---|
| 97 |
|
---|
| 98 | <para>
|
---|
| 99 | Install <application>logrotate</application> by running the following
|
---|
| 100 | command:
|
---|
| 101 | </para>
|
---|
| 102 |
|
---|
| 103 | <screen><userinput>make</userinput></screen>
|
---|
| 104 |
|
---|
| 105 | <para>
|
---|
| 106 | To test the results, issue: <command>make test</command>.
|
---|
| 107 | </para>
|
---|
| 108 |
|
---|
| 109 | <para>
|
---|
| 110 | Now, as the <systemitem class="username">root</systemitem> user:
|
---|
| 111 | </para>
|
---|
| 112 |
|
---|
| 113 | <screen role="root"><userinput>make MANDIR=/usr/share/man install</userinput></screen>
|
---|
| 114 |
|
---|
| 115 | </sect2>
|
---|
| 116 |
|
---|
| 117 | <sect2 role="commands">
|
---|
| 118 | <title>Command Explanations</title>
|
---|
| 119 |
|
---|
| 120 | <para>
|
---|
| 121 | <envar>MANDIR=/usr/share/man</envar>: Ensure the man pages are installed in
|
---|
| 122 | the correct location.
|
---|
| 123 | </para>
|
---|
| 124 |
|
---|
| 125 | </sect2>
|
---|
| 126 |
|
---|
| 127 | <sect2 role="configuration">
|
---|
| 128 | <title>Configuring Logrotate</title>
|
---|
| 129 |
|
---|
| 130 | <para><application>Logrotate</application> needs a configuration file,
|
---|
| 131 | which must be passed as an argument to the command when executed. Create
|
---|
| 132 | the file as the <systemitem class="username">root</systemitem> user:</para>
|
---|
| 133 |
|
---|
| 134 | <screen role="root"><userinput>cat > /etc/logrotate.conf << EOF
|
---|
| 135 | # Begin of /etc/logrotate.conf
|
---|
| 136 |
|
---|
| 137 | # Rotate log files weekly
|
---|
| 138 | weekly
|
---|
| 139 |
|
---|
| 140 | # Don't send mail to anybody
|
---|
| 141 | nomail
|
---|
| 142 |
|
---|
| 143 | # If the log file is empty, it will not be rotated
|
---|
| 144 | notifempty
|
---|
| 145 |
|
---|
| 146 | # Number of backups that will be kept
|
---|
| 147 | # This will keep the 2 newest backups only
|
---|
| 148 | rotate 2
|
---|
| 149 |
|
---|
| 150 | # Create new empty files after rotating old ones
|
---|
| 151 | # This will create empty log files, with owner
|
---|
| 152 | # set to root, group set to sys, and permissions 644
|
---|
| 153 | create 0664 root sys
|
---|
| 154 |
|
---|
| 155 | # Compress the backups with gzip
|
---|
| 156 | compress
|
---|
| 157 |
|
---|
| 158 | # No packages own lastlog or wtmp -- rotate them here
|
---|
| 159 | /var/log/wtmp {
|
---|
| 160 | monthly
|
---|
| 161 | create 0664 root utmp
|
---|
| 162 | rotate 1
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | /var/log/lastlog {
|
---|
| 166 | monthly
|
---|
| 167 | rotate 1
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | # Some packages drop log rotation info in this directory
|
---|
| 171 | # so we include any file in it.
|
---|
| 172 | include /etc/logrotate.d
|
---|
| 173 |
|
---|
| 174 | # End of /etc/logrotate.conf
|
---|
[58720a7b] | 175 | EOF
|
---|
| 176 |
|
---|
| 177 | chmod -v 0644 /etc/logrotate.conf</userinput></screen>
|
---|
[92c4b7a] | 178 |
|
---|
| 179 | <para>Now create the <filename class='directory'>/etc/logrotate.d</filename>
|
---|
| 180 | directory as the <systemitem class="username">root</systemitem> user:</para>
|
---|
| 181 |
|
---|
| 182 | <screen role="root"><userinput> mkdir -p /etc/logrotate.d</userinput></screen>
|
---|
| 183 |
|
---|
| 184 | <para>At this point additional log rotation commands can be entered, typically
|
---|
| 185 | in the <filename class='directory'>/etc/logrotate.d</filename> directory.
|
---|
| 186 | For example:</para>
|
---|
| 187 |
|
---|
| 188 | <screen role="root"><userinput>cat > /etc/logrotate.d/sys.log << EOF
|
---|
[58720a7b] | 189 | /var/log/sys.log {
|
---|
[92c4b7a] | 190 | # If the log file is larger than 100kb, rotate it
|
---|
| 191 | size 100k
|
---|
| 192 | rotate 5
|
---|
| 193 | weekly
|
---|
| 194 | postrotate
|
---|
| 195 | /bin/killall -HUP syslogd
|
---|
| 196 | endscript
|
---|
| 197 | }
|
---|
[58720a7b] | 198 | EOF
|
---|
| 199 |
|
---|
| 200 | chmod -v 0644 /etc/logrotate.d/sys.log</userinput></screen>
|
---|
| 201 |
|
---|
| 202 | <para>You can designate multiple files in one entry:</para>
|
---|
| 203 |
|
---|
| 204 | <screen role="root"><userinput>cat > /etc/logrotate.d/example.log << EOF
|
---|
| 205 | file1
|
---|
| 206 | file2
|
---|
| 207 | file3 {
|
---|
| 208 | ...
|
---|
| 209 | postrotate
|
---|
| 210 | ...
|
---|
| 211 | endscript
|
---|
| 212 | }
|
---|
| 213 | EOF
|
---|
| 214 |
|
---|
| 215 | chmod -v 0644 /etc/logrotate.d/example.log</userinput></screen>
|
---|
[92c4b7a] | 216 |
|
---|
[58720a7b] | 217 | <para>You can use in the same line the list of files: file1 file2 file3.
|
---|
| 218 | See the logrotate man page or
|
---|
[92c4b7a] | 219 | <ulink url='http://www.techrepublic.com/article/manage-linux-log-files-with-logrotate/'/>
|
---|
| 220 | for more examples.</para>
|
---|
| 221 |
|
---|
| 222 | <para>The command <command>logrotate /etc/logrotate.conf</command> can be
|
---|
[58720a7b] | 223 | run manually, however, the command should be run daily.
|
---|
| 224 | Other useful commands are <command>logrotate -d /etc/logrotate.conf</command>
|
---|
| 225 | for debugging purposes and <command>logrotate -f /etc/logrotate.conf</command>
|
---|
| 226 | forcing the logrotate commands to be run immediately. Combining the previous
|
---|
| 227 | options <option>-df</option>, you can debug the effect of the force command.
|
---|
| 228 | When debugging, the command is only simulated, not really run, thus, eventual
|
---|
| 229 | non-existing errors appear, when some intermediate files are expected,
|
---|
| 230 | because they are not actually created.</para>
|
---|
| 231 |
|
---|
| 232 | <para>To set up <xref linkend='fcron'/> to run
|
---|
| 233 | <command>logrotate ...</command> at 3AM daily, root's crontab should be
|
---|
| 234 | edited to add:</para>
|
---|
[92c4b7a] | 235 |
|
---|
| 236 | <screen><literal>0 3 * * * /usr/sbin/logrotate /etc/logrotate.conf</literal></screen>
|
---|
| 237 |
|
---|
| 238 |
|
---|
| 239 | </sect2>
|
---|
| 240 |
|
---|
| 241 | <sect2 role="content">
|
---|
| 242 | <title>Contents</title>
|
---|
| 243 |
|
---|
| 244 | <segmentedlist>
|
---|
| 245 | <segtitle>Installed Programs</segtitle>
|
---|
| 246 | <segtitle>Installed Library</segtitle>
|
---|
| 247 | <segtitle>Installed Directories</segtitle>
|
---|
| 248 |
|
---|
| 249 | <seglistitem>
|
---|
| 250 | <seg> logrotate </seg>
|
---|
| 251 | <seg> None </seg>
|
---|
| 252 | <seg> None </seg>
|
---|
| 253 | </seglistitem>
|
---|
| 254 | </segmentedlist>
|
---|
| 255 |
|
---|
| 256 | <variablelist>
|
---|
| 257 | <bridgehead renderas="sect3">Short Descriptions</bridgehead>
|
---|
| 258 | <?dbfo list-presentation="list"?>
|
---|
| 259 | <?dbhtml list-presentation="table"?>
|
---|
| 260 |
|
---|
| 261 | <varlistentry id="logrotate-prog">
|
---|
| 262 | <term><command>logrotate</command></term>
|
---|
| 263 | <listitem>
|
---|
| 264 | <para>
|
---|
[cc2e0075] | 265 | performs the log maintenance functions defined in the
|
---|
[92c4b7a] | 266 | configuration files.
|
---|
| 267 | </para>
|
---|
| 268 | <indexterm zone="logrotate logrotate-prog">
|
---|
| 269 | <primary sortas="b-logrotate-prog">logrotate</primary>
|
---|
| 270 | </indexterm>
|
---|
| 271 | </listitem>
|
---|
| 272 | </varlistentry>
|
---|
| 273 |
|
---|
| 274 | </variablelist>
|
---|
| 275 |
|
---|
| 276 | </sect2>
|
---|
| 277 |
|
---|
| 278 | </sect1>
|
---|