source: general/sysutils/logrotate.xml@ f14d3acd

12.1 ken/TL2024 ken/tuningfonts lazarus plabs/newcss python3.11 rahul/power-profiles-daemon renodr/vulkan-addition trunk xry111/llvm18
Last change on this file since f14d3acd was 2314cd7, checked in by Thomas Trepl <thomas@…>, 11 months ago

Some tags

  • Property mode set to 100644
File size: 8.9 KB
RevLine 
[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 &amp;&amp;
[e909f17]97make</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 &gt; /etc/logrotate.conf &lt;&lt; EOF
[b4dbcb0]123<literal># Begin /etc/logrotate.conf
[92c4b7a]124
125# Rotate log files weekly
126weekly
127
[3656def]128# Don't mail logs to anybody
[92c4b7a]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
[b4dbcb0]140# set to root, group set to sys, and permissions 664
[92c4b7a]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
[b4dbcb0]162# End /etc/logrotate.conf</literal>
[58720a7b]163EOF
164
165chmod -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 &gt; /etc/logrotate.d/sys.log &lt;&lt; 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]190EOF
191
192chmod -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 &gt; /etc/logrotate.d/example.log &lt;&lt; EOF
[51dfb3e]199<literal>file1
[58720a7b]200file2
201file3 {
202 ...
203 postrotate
204 ...
205 endscript
[51dfb3e]206}</literal>
[58720a7b]207EOF
208
209chmod -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 &gt; /etc/cron.daily/logrotate.sh &lt;&lt; "EOF" &amp;&amp;
[0f7ad57]243<literal>#!/bin/bash
244/usr/sbin/logrotate /etc/logrotate.conf</literal>
245EOF
246chmod 754 /etc/cron.daily/logrotate.sh</userinput></screen>
247
[d0d2c85a]248<screen role="root" revision="systemd"><userinput>cat &gt; /usr/lib/systemd/system/logrotate.service &lt;&lt; "EOF" &amp;&amp;
[0f7ad57]249<literal>[Unit]
250Description=Runs the logrotate command
[7b75894]251Documentation=man:logrotate(8)
[0f7ad57]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
[d0d2c85a]261cat &gt; /usr/lib/systemd/system/logrotate.timer &lt;&lt; "EOF" &amp;&amp;
[0f7ad57]262<literal>[Unit]
263Description=Runs the logrotate command daily at 3:00 AM
[92c4b7a]264
[0f7ad57]265[Timer]
266OnCalendar=*-*-* 3:00:00
267Persistent=true
[92c4b7a]268
[0f7ad57]269[Install]
270WantedBy=timers.target</literal>
271EOF
272systemctl 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>
Note: See TracBrowser for help on using the repository browser.