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