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