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