[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 |
|
---|
[1fd59b5] | 7 | <!ENTITY logrotate-download-http "https://github.com/logrotate/logrotate/releases/download/&logrotate-version;/logrotate-&logrotate-version;.tar.xz">
|
---|
[92c4b7a] | 8 | <!ENTITY logrotate-download-ftp " ">
|
---|
[5311527a] | 9 | <!ENTITY logrotate-md5sum "1cee3e80df6856435aeb751b98065f9c">
|
---|
| 10 | <!ENTITY logrotate-size "164 KB">
|
---|
| 11 | <!ENTITY logrotate-buildsize "40 MB (with tests)">
|
---|
[6ca1d4e6] | 12 | <!ENTITY logrotate-time "0.1 SBU (with tests)">
|
---|
[92c4b7a] | 13 | ]>
|
---|
| 14 |
|
---|
| 15 | <sect1 id="logrotate" xreflabel="logrotate-&logrotate-version;">
|
---|
| 16 | <?dbhtml filename="logrotate.html"?>
|
---|
| 17 |
|
---|
| 18 | <sect1info>
|
---|
[bc5778f] | 19 | <date>$Date$</date>
|
---|
[92c4b7a] | 20 | </sect1info>
|
---|
| 21 |
|
---|
| 22 | <title>Logrotate-&logrotate-version;</title>
|
---|
| 23 |
|
---|
| 24 | <indexterm zone="logrotate">
|
---|
| 25 | <primary sortas="a-logrotate">logrotate</primary>
|
---|
| 26 | </indexterm>
|
---|
| 27 |
|
---|
| 28 | <sect2 role="package">
|
---|
| 29 | <title>Introduction to Logrotate</title>
|
---|
| 30 |
|
---|
| 31 | <para>
|
---|
[b1532549] | 32 | The <application>logrotate</application> package allows automatic
|
---|
| 33 | rotation, compression, removal, and mailing of log files.
|
---|
[92c4b7a] | 34 | </para>
|
---|
| 35 |
|
---|
[3f4dc82] | 36 | &lfs111_checked;
|
---|
[92c4b7a] | 37 |
|
---|
| 38 | <bridgehead renderas="sect3">Package Information</bridgehead>
|
---|
| 39 | <itemizedlist spacing="compact">
|
---|
| 40 | <listitem>
|
---|
| 41 | <para>
|
---|
| 42 | Download (HTTP): <ulink url="&logrotate-download-http;"/>
|
---|
| 43 | </para>
|
---|
| 44 | </listitem>
|
---|
| 45 | <listitem>
|
---|
| 46 | <para>
|
---|
| 47 | Download (FTP): <ulink url="&logrotate-download-ftp;"/>
|
---|
| 48 | </para>
|
---|
| 49 | </listitem>
|
---|
| 50 | <listitem>
|
---|
| 51 | <para>
|
---|
| 52 | Download MD5 sum: &logrotate-md5sum;
|
---|
| 53 | </para>
|
---|
| 54 | </listitem>
|
---|
| 55 | <listitem>
|
---|
| 56 | <para>
|
---|
| 57 | Download size: &logrotate-size;
|
---|
| 58 | </para>
|
---|
| 59 | </listitem>
|
---|
| 60 | <listitem>
|
---|
| 61 | <para>
|
---|
| 62 | Estimated disk space required: &logrotate-buildsize;
|
---|
| 63 | </para>
|
---|
| 64 | </listitem>
|
---|
| 65 | <listitem>
|
---|
| 66 | <para>
|
---|
| 67 | Estimated build time: &logrotate-time;
|
---|
| 68 | </para>
|
---|
| 69 | </listitem>
|
---|
| 70 | </itemizedlist>
|
---|
| 71 |
|
---|
| 72 | <bridgehead renderas="sect3">Logrotate Dependencies</bridgehead>
|
---|
| 73 |
|
---|
| 74 | <bridgehead renderas="sect4">Required</bridgehead>
|
---|
| 75 | <para role="required">
|
---|
| 76 | <xref linkend="popt"/>
|
---|
| 77 | </para>
|
---|
| 78 |
|
---|
[0f7ad57] | 79 | <bridgehead renderas="sect4" revision="sysv">Recommended</bridgehead>
|
---|
| 80 | <para role="recommended" revision="sysv">
|
---|
[572553b] | 81 | <xref role="runtime" linkend="fcron"/> (runtime)
|
---|
[92c4b7a] | 82 | </para>
|
---|
| 83 |
|
---|
| 84 | <bridgehead renderas="sect4">Optional</bridgehead>
|
---|
| 85 | <para role="optional">
|
---|
[572553b] | 86 | An <xref role="runtime" linkend="server-mail"/> (runtime)
|
---|
[92c4b7a] | 87 | </para>
|
---|
| 88 |
|
---|
| 89 | <para condition="html" role="usernotes">User Notes:
|
---|
| 90 | <ulink url="&blfs-wiki;/logrotate"/>
|
---|
| 91 | </para>
|
---|
| 92 | </sect2>
|
---|
| 93 |
|
---|
| 94 | <sect2 role="installation">
|
---|
| 95 | <title>Installation of Logrotate</title>
|
---|
| 96 |
|
---|
| 97 | <para>
|
---|
| 98 | Install <application>logrotate</application> by running the following
|
---|
| 99 | command:
|
---|
| 100 | </para>
|
---|
| 101 |
|
---|
[b4dbcb0] | 102 | <screen><userinput>./configure --prefix=/usr &&
|
---|
[e909f17] | 103 | make</userinput></screen>
|
---|
[92c4b7a] | 104 |
|
---|
| 105 | <para>
|
---|
[8558044] | 106 | To test the results, issue: <command>make test</command>. One test
|
---|
| 107 | fails because the very old <command>compress</command> is not
|
---|
[43b1dad3] | 108 | present and two tests fail if an MTA is not installed.
|
---|
[92c4b7a] | 109 | </para>
|
---|
| 110 |
|
---|
| 111 | <para>
|
---|
| 112 | Now, as the <systemitem class="username">root</systemitem> user:
|
---|
| 113 | </para>
|
---|
| 114 |
|
---|
[e909f17] | 115 | <screen role="root"><userinput>make install</userinput></screen>
|
---|
[92c4b7a] | 116 |
|
---|
| 117 | </sect2>
|
---|
[1dd7b0ae] | 118 |
|
---|
[92c4b7a] | 119 | <sect2 role="configuration">
|
---|
[b1532549] | 120 | <title>Configuring Logrotate</title>
|
---|
[92c4b7a] | 121 |
|
---|
[b1532549] | 122 | <para>
|
---|
| 123 | <application>Logrotate</application> needs a configuration file,
|
---|
| 124 | which must be passed as an argument to the command when executed. Create
|
---|
| 125 | the file as the <systemitem class="username">root</systemitem> user:
|
---|
| 126 | </para>
|
---|
[92c4b7a] | 127 |
|
---|
| 128 | <screen role="root"><userinput>cat > /etc/logrotate.conf << EOF
|
---|
[b4dbcb0] | 129 | <literal># Begin /etc/logrotate.conf
|
---|
[92c4b7a] | 130 |
|
---|
| 131 | # Rotate log files weekly
|
---|
| 132 | weekly
|
---|
| 133 |
|
---|
[3656def] | 134 | # Don't mail logs to anybody
|
---|
[92c4b7a] | 135 | nomail
|
---|
| 136 |
|
---|
| 137 | # If the log file is empty, it will not be rotated
|
---|
| 138 | notifempty
|
---|
| 139 |
|
---|
| 140 | # Number of backups that will be kept
|
---|
| 141 | # This will keep the 2 newest backups only
|
---|
| 142 | rotate 2
|
---|
| 143 |
|
---|
| 144 | # Create new empty files after rotating old ones
|
---|
| 145 | # This will create empty log files, with owner
|
---|
[b4dbcb0] | 146 | # set to root, group set to sys, and permissions 664
|
---|
[92c4b7a] | 147 | create 0664 root sys
|
---|
| 148 |
|
---|
| 149 | # Compress the backups with gzip
|
---|
| 150 | compress
|
---|
| 151 |
|
---|
| 152 | # No packages own lastlog or wtmp -- rotate them here
|
---|
| 153 | /var/log/wtmp {
|
---|
| 154 | monthly
|
---|
| 155 | create 0664 root utmp
|
---|
| 156 | rotate 1
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | /var/log/lastlog {
|
---|
| 160 | monthly
|
---|
| 161 | rotate 1
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | # Some packages drop log rotation info in this directory
|
---|
| 165 | # so we include any file in it.
|
---|
| 166 | include /etc/logrotate.d
|
---|
| 167 |
|
---|
[b4dbcb0] | 168 | # End /etc/logrotate.conf</literal>
|
---|
[58720a7b] | 169 | EOF
|
---|
| 170 |
|
---|
| 171 | chmod -v 0644 /etc/logrotate.conf</userinput></screen>
|
---|
[92c4b7a] | 172 |
|
---|
[b1532549] | 173 | <para>
|
---|
| 174 | Now create the <filename class='directory'>/etc/logrotate.d</filename>
|
---|
| 175 | directory as the <systemitem class="username">root</systemitem> user:
|
---|
| 176 | </para>
|
---|
[92c4b7a] | 177 |
|
---|
[b4dbcb0] | 178 | <screen role="root"><userinput>mkdir -p /etc/logrotate.d</userinput></screen>
|
---|
[92c4b7a] | 179 |
|
---|
[b1532549] | 180 | <para>
|
---|
| 181 | At this point additional log rotation commands can be entered, typically
|
---|
| 182 | in the <filename class='directory'>/etc/logrotate.d</filename> directory.
|
---|
| 183 | For example:
|
---|
| 184 | </para>
|
---|
[92c4b7a] | 185 |
|
---|
[a09f080] | 186 | <screen role="nodump"><userinput>cat > /etc/logrotate.d/sys.log << EOF
|
---|
[51dfb3e] | 187 | <literal>/var/log/sys.log {
|
---|
[92c4b7a] | 188 | # If the log file is larger than 100kb, rotate it
|
---|
| 189 | size 100k
|
---|
| 190 | rotate 5
|
---|
| 191 | weekly
|
---|
| 192 | postrotate
|
---|
| 193 | /bin/killall -HUP syslogd
|
---|
| 194 | endscript
|
---|
[51dfb3e] | 195 | }</literal>
|
---|
[58720a7b] | 196 | EOF
|
---|
| 197 |
|
---|
| 198 | chmod -v 0644 /etc/logrotate.d/sys.log</userinput></screen>
|
---|
| 199 |
|
---|
[b1532549] | 200 | <para>
|
---|
| 201 | You can designate multiple files in one entry:
|
---|
| 202 | </para>
|
---|
[58720a7b] | 203 |
|
---|
[f67554b0] | 204 | <screen role="nodump"><userinput>cat > /etc/logrotate.d/example.log << EOF
|
---|
[51dfb3e] | 205 | <literal>file1
|
---|
[58720a7b] | 206 | file2
|
---|
| 207 | file3 {
|
---|
| 208 | ...
|
---|
| 209 | postrotate
|
---|
| 210 | ...
|
---|
| 211 | endscript
|
---|
[51dfb3e] | 212 | }</literal>
|
---|
[58720a7b] | 213 | EOF
|
---|
| 214 |
|
---|
| 215 | chmod -v 0644 /etc/logrotate.d/example.log</userinput></screen>
|
---|
[92c4b7a] | 216 |
|
---|
[b1532549] | 217 | <para>
|
---|
| 218 | You can use in the same line the list of files: file1 file2 file3.
|
---|
| 219 | See the logrotate man page or <ulink
|
---|
| 220 | url='http://www.techrepublic.com/article/manage-linux-log-files-with-logrotate/'/>
|
---|
| 221 | for more examples.
|
---|
| 222 | </para>
|
---|
| 223 |
|
---|
| 224 | <para>
|
---|
| 225 | The command <command>logrotate /etc/logrotate.conf</command> can be
|
---|
| 226 | run manually, however, the command should be run daily.
|
---|
| 227 | Other useful commands are <command>logrotate -d
|
---|
| 228 | /etc/logrotate.conf</command> for debugging purposes and
|
---|
| 229 | <command>logrotate -f /etc/logrotate.conf</command> forcing the
|
---|
| 230 | logrotate commands to be run immediately. Combining the previous options
|
---|
| 231 | <option>-df</option>, you can debug the effect of the force command.
|
---|
[75cf6e3] | 232 | When debugging, the commands are only simulated and are not actually run.
|
---|
| 233 | As a result, errors about files not existing will eventually appear because
|
---|
| 234 | the files are not actually created.
|
---|
[b1532549] | 235 | </para>
|
---|
[58720a7b] | 236 |
|
---|
[0f7ad57] | 237 | <para>
|
---|
[b4dbcb0] | 238 | To run the <command>logrotate</command> command daily,
|
---|
[0f7ad57] | 239 | <phrase revision="sysv">if you've installed
|
---|
| 240 | <xref linkend="fcron"/> and completed the section on periodic jobs,
|
---|
| 241 | execute</phrase><phrase revision="systemd">execute</phrase> the following
|
---|
| 242 | commands, as the <systemitem class="username">root</systemitem> user,
|
---|
| 243 | to create a <phrase revision="sysv">daily cron job:</phrase>
|
---|
| 244 | <phrase revision="systemd">systemd timer to run daily at 3:00 A.M.
|
---|
| 245 | (local time):</phrase>
|
---|
| 246 | </para>
|
---|
| 247 |
|
---|
[914dd13] | 248 | <screen role="root" revision="sysv"><userinput>cat > /etc/cron.daily/logrotate.sh << "EOF" &&
|
---|
[0f7ad57] | 249 | <literal>#!/bin/bash
|
---|
| 250 | /usr/sbin/logrotate /etc/logrotate.conf</literal>
|
---|
| 251 | EOF
|
---|
| 252 | chmod 754 /etc/cron.daily/logrotate.sh</userinput></screen>
|
---|
| 253 |
|
---|
[d0d2c85a] | 254 | <screen role="root" revision="systemd"><userinput>cat > /usr/lib/systemd/system/logrotate.service << "EOF" &&
|
---|
[0f7ad57] | 255 | <literal>[Unit]
|
---|
| 256 | Description=Runs the logrotate command
|
---|
[7b75894] | 257 | Documentation=man:logrotate(8)
|
---|
[0f7ad57] | 258 | DefaultDependencies=no
|
---|
| 259 | After=local-fs.target
|
---|
| 260 | Before=shutdown.target
|
---|
| 261 |
|
---|
| 262 | [Service]
|
---|
| 263 | Type=oneshot
|
---|
| 264 | RemainAfterExit=yes
|
---|
| 265 | ExecStart=/usr/sbin/logrotate /etc/logrotate.conf</literal>
|
---|
| 266 | EOF
|
---|
[d0d2c85a] | 267 | cat > /usr/lib/systemd/system/logrotate.timer << "EOF" &&
|
---|
[0f7ad57] | 268 | <literal>[Unit]
|
---|
| 269 | Description=Runs the logrotate command daily at 3:00 AM
|
---|
[92c4b7a] | 270 |
|
---|
[0f7ad57] | 271 | [Timer]
|
---|
| 272 | OnCalendar=*-*-* 3:00:00
|
---|
| 273 | Persistent=true
|
---|
[92c4b7a] | 274 |
|
---|
[0f7ad57] | 275 | [Install]
|
---|
| 276 | WantedBy=timers.target</literal>
|
---|
| 277 | EOF
|
---|
| 278 | systemctl enable logrotate.timer</userinput></screen>
|
---|
[92c4b7a] | 279 |
|
---|
| 280 | </sect2>
|
---|
| 281 |
|
---|
| 282 | <sect2 role="content">
|
---|
| 283 | <title>Contents</title>
|
---|
| 284 |
|
---|
| 285 | <segmentedlist>
|
---|
| 286 | <segtitle>Installed Programs</segtitle>
|
---|
| 287 | <segtitle>Installed Library</segtitle>
|
---|
| 288 | <segtitle>Installed Directories</segtitle>
|
---|
| 289 |
|
---|
| 290 | <seglistitem>
|
---|
| 291 | <seg> logrotate </seg>
|
---|
| 292 | <seg> None </seg>
|
---|
| 293 | <seg> None </seg>
|
---|
| 294 | </seglistitem>
|
---|
| 295 | </segmentedlist>
|
---|
| 296 |
|
---|
| 297 | <variablelist>
|
---|
| 298 | <bridgehead renderas="sect3">Short Descriptions</bridgehead>
|
---|
| 299 | <?dbfo list-presentation="list"?>
|
---|
| 300 | <?dbhtml list-presentation="table"?>
|
---|
| 301 |
|
---|
| 302 | <varlistentry id="logrotate-prog">
|
---|
| 303 | <term><command>logrotate</command></term>
|
---|
| 304 | <listitem>
|
---|
| 305 | <para>
|
---|
[f3429309] | 306 | performs the log maintenance functions defined in the
|
---|
[4c24eb0a] | 307 | configuration files
|
---|
[92c4b7a] | 308 | </para>
|
---|
| 309 | <indexterm zone="logrotate logrotate-prog">
|
---|
| 310 | <primary sortas="b-logrotate-prog">logrotate</primary>
|
---|
| 311 | </indexterm>
|
---|
| 312 | </listitem>
|
---|
| 313 | </varlistentry>
|
---|
| 314 |
|
---|
| 315 | </variablelist>
|
---|
| 316 |
|
---|
| 317 | </sect2>
|
---|
| 318 |
|
---|
| 319 | </sect1>
|
---|