source: general/sysutils/logrotate.xml

trunk
Last change on this file was dd8803c, checked in by Bruce Dubbs <bdubbs@…>, 9 days ago

Update to logrotate-3.22.0.

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