source: general/sysutils/logrotate.xml@ 3f2db3a6

11.3 12.0 12.1 12.2 gimp3 kea ken/TL2024 ken/inkscape-core-mods ken/tuningfonts lazarus lxqt plabs/newcss plabs/python-mods python3.11 qt5new rahul/power-profiles-daemon renodr/vulkan-addition trunk xry111/for-12.3 xry111/llvm18 xry111/spidermonkey128 xry111/xf86-video-removal
Last change on this file since 3f2db3a6 was 3f2db3a6, checked in by Pierre Labastie <pierre.labastie@…>, 23 months ago

Remove sect1info tags

They only contain a date tag that is nowhere used.

  • Property mode set to 100644
File size: 9.0 KB
Line 
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
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 "24704642e1e6c7889edbe2b639636caf">
10 <!ENTITY logrotate-size "163 KB">
11 <!ENTITY logrotate-buildsize "2.8 MB (add 38 MB for tests)">
12 <!ENTITY logrotate-time "less than 0.1 SBU (add 0.2 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 &lfs112_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 <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
99<screen><userinput>./configure --prefix=/usr &amp;&amp;
100make</userinput></screen>
101
102 <para>
103 To test the results, issue: <command>make test</command>. One test
104 fails because the very old <command>compress</command> is not
105 present and two tests fail if an MTA is not installed.
106 </para>
107
108 <para>
109 Now, as the <systemitem class="username">root</systemitem> user:
110 </para>
111
112<screen role="root"><userinput>make install</userinput></screen>
113
114 </sect2>
115
116 <sect2 role="configuration">
117 <title>Configuring Logrotate</title>
118
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>
124
125<screen role="root"><userinput>cat &gt; /etc/logrotate.conf &lt;&lt; EOF
126<literal># Begin /etc/logrotate.conf
127
128# Rotate log files weekly
129weekly
130
131# Don't mail logs to anybody
132nomail
133
134# If the log file is empty, it will not be rotated
135notifempty
136
137# Number of backups that will be kept
138# This will keep the 2 newest backups only
139rotate 2
140
141# Create new empty files after rotating old ones
142# This will create empty log files, with owner
143# set to root, group set to sys, and permissions 664
144create 0664 root sys
145
146# Compress the backups with gzip
147compress
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.
163include /etc/logrotate.d
164
165# End /etc/logrotate.conf</literal>
166EOF
167
168chmod -v 0644 /etc/logrotate.conf</userinput></screen>
169
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>
174
175<screen role="root"><userinput>mkdir -p /etc/logrotate.d</userinput></screen>
176
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>
182
183<screen role="nodump"><userinput>cat &gt; /etc/logrotate.d/sys.log &lt;&lt; EOF
184<literal>/var/log/sys.log {
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
192}</literal>
193EOF
194
195chmod -v 0644 /etc/logrotate.d/sys.log</userinput></screen>
196
197 <para>
198 You can designate multiple files in one entry:
199 </para>
200
201<screen role="nodump"><userinput>cat &gt; /etc/logrotate.d/example.log &lt;&lt; EOF
202<literal>file1
203file2
204file3 {
205 ...
206 postrotate
207 ...
208 endscript
209}</literal>
210EOF
211
212chmod -v 0644 /etc/logrotate.d/example.log</userinput></screen>
213
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
217 url='https://www.techrepublic.com/article/manage-linux-log-files-with-logrotate/'/>
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.
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.
232 </para>
233
234 <para>
235 To run the <command>logrotate</command> command daily,
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
245<screen role="root" revision="sysv"><userinput>cat &gt; /etc/cron.daily/logrotate.sh &lt;&lt; "EOF" &amp;&amp;
246<literal>#!/bin/bash
247/usr/sbin/logrotate /etc/logrotate.conf</literal>
248EOF
249chmod 754 /etc/cron.daily/logrotate.sh</userinput></screen>
250
251<screen role="root" revision="systemd"><userinput>cat &gt; /usr/lib/systemd/system/logrotate.service &lt;&lt; "EOF" &amp;&amp;
252<literal>[Unit]
253Description=Runs the logrotate command
254Documentation=man:logrotate(8)
255DefaultDependencies=no
256After=local-fs.target
257Before=shutdown.target
258
259[Service]
260Type=oneshot
261RemainAfterExit=yes
262ExecStart=/usr/sbin/logrotate /etc/logrotate.conf</literal>
263EOF
264cat &gt; /usr/lib/systemd/system/logrotate.timer &lt;&lt; "EOF" &amp;&amp;
265<literal>[Unit]
266Description=Runs the logrotate command daily at 3:00 AM
267
268[Timer]
269OnCalendar=*-*-* 3:00:00
270Persistent=true
271
272[Install]
273WantedBy=timers.target</literal>
274EOF
275systemctl enable logrotate.timer</userinput></screen>
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>
303 performs the log maintenance functions defined in the
304 configuration files
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>
Note: See TracBrowser for help on using the repository browser.