Changeset 1075

Show
Ignore:
Timestamp:
08/09/07 03:27:15 (1 year ago)
Author:
robert
Message:

Updated logrotate hint

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/logrorate.txt

    r1073 r1075  
    11AUTHOR:         Hugo S. Cardozo <hugoa_c2004@yahoo.com> 
    2 DATE:   2007-03-24 
    3 LICENSE:  GNU Free Documentation License Version 1.2 
    4 SYNOPSIS:  Logrotate: Keep your log files tidy 
    5 DESCRIPTION:  This hint will help you to install and configure 
    6   logrotate for your (B)LFS system 
    7 ATTACHMENTS:  * popt-1.6.3 
    8     ftp://slackware.cs.utah.edu/pub/slackware/slackware-10.1/source/l/popt/popt-1.7.tar.gz 
    9   * logrotate-3.6.8 
    10   ftp://slackware.mirrors.tds.net/pub/slackware/slackware-10.1/source/a/logrotate/logrotate-3.6.8.tar.gz 
     2 
     3DATE:           2007-03-31 
     4 
     5LICENSE:        GNU Free Documentation License Version 1.2 
     6 
     7SYNOPSIS:       Logrotate: Keep your log files tidy 
     8 
     9DESCRIPTION:    This hint will help you to install and 
     10configure 
     11                logrotate for your (B)LFS system 
     12 
     13ATTACHMENTS:    * logrotate-3.6.8 
     14                  <mirrordeslackware>/logrotate-3.6.8.tar.gz 
     15 
    1116PREREQUISITES:  LFS installed and running. 
    12   Optionally, (F)cron. 
     17                Popt-1.10.4 
     18                Optionally, (F)cron. 
     19 
    1320HINT: 
     21 
    1422Introduction 
    1523============ 
     24 
    1625Logrotate is an utility to take care of the log files of your system. It keeps 
    17 track of the size of the log files, and "rotates" them when needed. That minds, 
    18 the utility check the size of the files, an if one of them is larger than a 
    19 certain size, the program performs some actions. That actione can be: backup 
     26track of the size of the log files, and "rotates" them when needed. That means 
     27the utility checks the size of the files, and if one of them is larger than a 
     28certain size, the program performs some actions. That action can be: backup 
    2029and compress the file, remove it or mail it to an user, create a new empty 
    2130log file, and others. 
     31 
    2232Installation 
    2333============ 
    24 First, you need to compile and install popt-1.6.3. This is a library to 
    25 manage command-line arguments. 
    26 Unpack the tarball and cd into the popt sources: 
    27  tar xzf popt-1.6.3.tar.gz 
    28  cd popt-1.6.3 
    29 Compile and install: 
    30  ./configure --prefix=/usr && \ 
    31  make && make install 
    32 Now you can compile logrotate. Unpack the tarball and cd: 
    33  tar xzf logrotate-3.6.8.tar.gz 
    34  cd logrotate-3.6.8 
     34 
     35First, you need to compile and install popt-1.10.4. The BLFS book includes 
     36the instructions for this. But, if for some (strange) reason you can`t get 
     37the popt-1.10.4 tarball, you can use popt-1.6.3 either, or (maybe) any later 
     38version. 
     39 
     40Now you can compile logrotate. Unpack the tarball and 
     41cd: 
     42        tar xzf logrotate-3.6.8.tar.gz 
     43        cd logrotate-3.6.8 
    3544Compile: 
    36  make 
     45        make  
    3746Optionally, run the test suite: 
    38  make test 
     47        make test 
    3948Install: 
    40  make install 
     49        make install 
     50 
    4151Configuration 
    4252============= 
     53 
    4354The command "logrotate" needs a config file, which must be passed as an 
    4455argument to the command when executed. We will put that file in "/etc", 
    4556and name it "logrotate.conf". 
     57 
    4658Create the file with this command: 
    47  cat >> /etc/logrotate.conf << EOF 
    48  # Begin of /etc/logrotate.conf 
    49  # Rotate log files weekly 
    50  weekly 
    51   
    52  # No send mail to anybody 
    53  nomail 
    54  # If the log file is empty, it does not will be rotated 
    55  notifempty 
    56  # Number of backups that will be kept 
    57  # This will keep the 2 newest backups only 
    58  rotate 2 
    59   
    60  # Create new empty files after rotate old ones 
    61  # This will create empty log files, with owner 
    62  # set to root, group set to sys, and permissions 644 
    63  create 0664 root sys 
    64  # Compress the backups with gzip 
    65  compress 
    66  # RPM packages drop log rotation info in this directory, 
    67  # so we include any file in it. 
    68  include /etc/logrotate.d 
    69  # End of /etc/logrotate.conf 
    70  EOF 
     59        cat >> /etc/logrotate.conf << EOF 
     60        # Begin of /etc/logrotate.conf 
     61 
     62        # Rotate log files weekly 
     63        weekly 
     64         
     65        # Don't send mail to anybody 
     66        nomail 
     67 
     68        # If the log file is empty, it will not be rotated 
     69        notifempty 
     70 
     71        # Number of backups that will be kept 
     72        # This will keep the 2 newest backups only 
     73        rotate 2 
     74         
     75        # Create new empty files after rotate old ones 
     76        # This will create empty log files, with owner 
     77        # set to root, group set to sys, and permissions 644 
     78        create 0664 root sys 
     79 
     80        # Compress the backups with gzip 
     81        compress 
     82 
     83        # RPM packages drop log rotation info in this directory 
     84        # so we include any file in it. 
     85        include /etc/logrotate.d 
     86 
     87        # End of /etc/logrotate.conf 
     88        EOF 
     89 
    7190Also, you can use the file "logrotate-default", which is in the logrotate 
    7291sources, in the "examples" directory. I use some of the lines of that file 
    7392in my example above. 
     93 
    7494When installing sysklogd, the LFS book defines some predefined log files in 
    7595"/etc/syslog.conf". We can rotate those files by adding their definitions to 
    7696logrotate.conf. So, to add them, run this command: 
    77  for logfile in $(find /var/log/* -type f); do 
    78   echo "$logfile {" >> /etc/logrotate.conf 
    79   echo "# If the log file is larger" \ 
    80     "than 100kb, rotate it" >> /etc/logrotate.conf" 
    81   echo "  size=100k" >> /etc/logrotate.conf 
    82   echo "}" >> /etc/logrotate.conf 
    83   echo "" >> /etc/logrotate.conf 
    84  done 
    85 For details on configuring this file, see logrotate(8). 
     97        for logfile in $(find /var/log/* -type f); do 
     98                echo "$logfile {" >> /etc/logrotate.conf 
     99                echo "# If the log file is larger" \ 
     100                  "than 100kb, rotate it" >> /etc/logrotate.conf" 
     101                echo "  size=100k" >> /etc/logrotate.conf 
     102                echo "}" >> /etc/logrotate.conf 
     103                echo "" >> /etc/logrotate.conf 
     104        done 
     105 
     106For details on editing this file, see logrotate(8). 
     107 
    86108 
    87109Logrotate as a Cron job 
    88110======================= 
     111 
    89112You can run logrotate just issuing "/usr/sbin/logrotate /etc/logrotate.conf" 
    90113but in this case, you should run that command by yourself, every day (or 
    91114week, or month...), if you want the program to work properly. This can be 
    92115very annoying :-). 
     116 
    93117Instead, you can run it as a cron job. For the further configuration, 
    94118I will assume that you have installed Fcron from the BLFS book. 
     119 
    95120Create a /etc/fcrontab file by issuing this command: 
    96  cat >> /etc/fcrontab << EOF 
    97  0 12 * * * 0  /usr/sbin/logrotate /etc/logrotate.conf 
    98  EOF 
    99 This will make fcron execute logrotate once a week, in Sunday, at noon. 
    100 For details on configuring fcrontab, refer to fcrontab(1). 
    101 You will need the "check_system_crontabs" from the fcron sources. If you 
    102 haven't installed it, do it by issuing: 
    103  tar xzf fcron-3.0.1.tar.gz 
    104  cp -v fcron-3.0.1/scripts/check_system_crontabs /usr/sbin 
     121        cat >> /etc/fcrontab << EOF 
     122        0 12 * * * 0    /usr/sbin/logrotate /etc/logrotate.conf 
     123        EOF 
     124This will make fcron execute logrotate once a week, on Sunday, at noon. 
     125For details on editing fcrontab, refer to fcrontab(1). 
     126 
     127You will need the "check_system_crontabs" script from the fcron sources. If 
     128you haven't installed it, do it by issuing: 
     129        tar xzf fcron-3.0.1.tar.gz 
     130        cp -v fcron-3.0.1/scripts/check_system_crontabs /usr/sbin 
     131 
    105132Then run the script: 
    106  check_system_crontabs -v 
     133        check_system_crontabs -v 
    107134For help, type this: 
    108  check_system_crontabs -h 
    109   
     135        check_system_crontabs -h 
    110136 
    111 VERSION:        1.00 
     137 
     138ACKNOWLEDGEMENTS: 
     139        * Alexander E. Patrakov, for pointing me for the BLFS 
     140version of 
     141          popt (Before I used the popt included in Slackware 10.1) 
     142 
     143 
     144VERSION:        1.1 
     145 
    112146CHANGELOG:      1.00 First release 
     147                1.1 Corrected popt section, fixed typos.