source: general/sysutils/logrotate.xml@ 42ddc30

12.0 12.1 kea ken/TL2024 ken/tuningfonts lazarus lxqt plabs/newcss python3.11 rahul/power-profiles-daemon renodr/vulkan-addition trunk xry111/llvm18 xry111/xf86-video-removal
Last change on this file since 42ddc30 was cb594b6c, checked in by Xi Ruoyao <xry111@…>, 11 months ago

general: Remove non-exist User Notes link

Part of User Notes removal by
https://www.linuxfromscratch.org/~xry111/remove-nonexist-usernote.sh

  • Property mode set to 100644
File size: 8.9 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 "6c15f45efc3475a576c4f7e6cc481b2c">
10 <!ENTITY logrotate-size "164.5 KB">
11 <!ENTITY logrotate-buildsize "2.9 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 &lfs113_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>. One test
101 fails because the very old <command>compress</command> is not
102 present and two tests fail if an MTA is not installed.
103 </para>
104
105 <para>
106 Now, as the <systemitem class="username">root</systemitem> user:
107 </para>
108
109<screen role="root"><userinput>make install</userinput></screen>
110
111 </sect2>
112
113 <sect2 role="configuration">
114 <title>Configuring Logrotate</title>
115
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>
121
122<screen role="root"><userinput>cat &gt; /etc/logrotate.conf &lt;&lt; EOF
123<literal># Begin /etc/logrotate.conf
124
125# Rotate log files weekly
126weekly
127
128# Don't mail logs to anybody
129nomail
130
131# If the log file is empty, it will not be rotated
132notifempty
133
134# Number of backups that will be kept
135# This will keep the 2 newest backups only
136rotate 2
137
138# Create new empty files after rotating old ones
139# This will create empty log files, with owner
140# set to root, group set to sys, and permissions 664
141create 0664 root sys
142
143# Compress the backups with gzip
144compress
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.
160include /etc/logrotate.d
161
162# End /etc/logrotate.conf</literal>
163EOF
164
165chmod -v 0644 /etc/logrotate.conf</userinput></screen>
166
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>
171
172<screen role="root"><userinput>mkdir -p /etc/logrotate.d</userinput></screen>
173
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>
179
180<screen role="nodump"><userinput>cat &gt; /etc/logrotate.d/sys.log &lt;&lt; EOF
181<literal>/var/log/sys.log {
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
189}</literal>
190EOF
191
192chmod -v 0644 /etc/logrotate.d/sys.log</userinput></screen>
193
194 <para>
195 You can designate multiple files in one entry:
196 </para>
197
198<screen role="nodump"><userinput>cat &gt; /etc/logrotate.d/example.log &lt;&lt; EOF
199<literal>file1
200file2
201file3 {
202 ...
203 postrotate
204 ...
205 endscript
206}</literal>
207EOF
208
209chmod -v 0644 /etc/logrotate.d/example.log</userinput></screen>
210
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
214 url='https://www.techrepublic.com/article/manage-linux-log-files-with-logrotate/'/>
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.
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.
229 </para>
230
231 <para>
232 To run the <command>logrotate</command> command daily,
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
242<screen role="root" revision="sysv"><userinput>cat &gt; /etc/cron.daily/logrotate.sh &lt;&lt; "EOF" &amp;&amp;
243<literal>#!/bin/bash
244/usr/sbin/logrotate /etc/logrotate.conf</literal>
245EOF
246chmod 754 /etc/cron.daily/logrotate.sh</userinput></screen>
247
248<screen role="root" revision="systemd"><userinput>cat &gt; /usr/lib/systemd/system/logrotate.service &lt;&lt; "EOF" &amp;&amp;
249<literal>[Unit]
250Description=Runs the logrotate command
251Documentation=man:logrotate(8)
252DefaultDependencies=no
253After=local-fs.target
254Before=shutdown.target
255
256[Service]
257Type=oneshot
258RemainAfterExit=yes
259ExecStart=/usr/sbin/logrotate /etc/logrotate.conf</literal>
260EOF
261cat &gt; /usr/lib/systemd/system/logrotate.timer &lt;&lt; "EOF" &amp;&amp;
262<literal>[Unit]
263Description=Runs the logrotate command daily at 3:00 AM
264
265[Timer]
266OnCalendar=*-*-* 3:00:00
267Persistent=true
268
269[Install]
270WantedBy=timers.target</literal>
271EOF
272systemctl enable logrotate.timer</userinput></screen>
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>
300 performs the log maintenance functions defined in the
301 configuration files
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>
Note: See TracBrowser for help on using the repository browser.