-2

i use ubuntu 14.04 each 2 day i need manualy remove log files from:

/var/log/apache2/domains

2 files become to big about 5gb, i found solution, edit logrotate.conf found in etc/logrotate.conf this is my logrorate.conf

# see "man logrotate" for details
# rotate log files weekly
weekly

# use the syslog group by default, since this is the owning group
# of /var/log/syslog.
su root syslog

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp, or btmp -- we'll rotate them here
/var/log/wtmp {
missingok
monthly
create 0664 root utmp
rotate 1
}

/var/log/btmp {
missingok
monthly
create 0660 root utmp
rotate 1
}

# system-specific logs may be configured here

this is what i need add for each log file bellow /var/log/btmp

/var/log/apache2/domains/domain.com.error.log {
missingok
daily
create 0660 root root
rotate 1
maxsize 2M
}

this is good ? i need run cron for that or just save this in logrotate.conf ?

nikola99
  • 101
  • 8
  • Just save logrotate.conf, there is cronjob which invoke logrotate, which read this config file. – Ondra Sniper Flidr Nov 11 '15 at 12:36
  • i can there bellow add more command depend how much ''big'' log files i have ? – nikola99 Nov 11 '15 at 12:45
  • nikola99, I'm sorry, but this question is rapidly turning into *please give me a step-by-step guide to solving my particular problem*, which isn't on-topic for ServerFault. You asked a good question, and have had a good answer (+1 from me); may I *strongly* recommend that you now go and do your homework, test out the suggestions that have been given to you, and return with **specific** questions (which show what you've done to try to solve your own problem) if you find that you still can't make it work. – MadHatter Nov 11 '15 at 13:14
  • @MadHatter i choose for best answer, maked edit in logrotate.conf will see if work – nikola99 Nov 11 '15 at 13:39
  • Good for you! Hopefully, Ondra's answer will be enough to get you on the right path. – MadHatter Nov 11 '15 at 13:40
  • file become 5gb in 2 day, this mean in 1 day 2.5gb can we somehow make this run each 1hour or something like this for file not become bigger ? – nikola99 Nov 11 '15 at 13:56

1 Answers1

1

In log file settings use maxsize command, like this

/var/log/foo {
  missingok
  monthly
  create 0660 root root
  rotate 1
  maxsize 2M
}

More information about size limiting here from documentation:

minsize size
          Log  files  are  rotated when they grow bigger than size bytes,
          but not before the additionally specified time interval (daily,
          weekly,  monthly, or yearly).  The related size option is simi-
          lar except that it is mutually exclusive with the time interval
          options,  and  it causes log files to be rotated without regard
          for the last rotation time.  When minsize  is  used,  both  the
          size and timestamp of a log file are considered.

size size
          Log files are rotated only if they grow bigger then size bytes.
          If size is followed by k, the size is assumed to  be  in  kilo-
          bytes.  If the M is used, the size is in megabytes, and if G is
          used, the size is in gigabytes. So size 100,  size  100k,  size
          100M and size 100G are all valid.
maxsize size
          Log files are rotated when they grow bigger than size bytes even before
          the additionally specified time interval (daily, weekly, monthly, 
          or yearly).  The related size option is  similar  except  that  it 
          is mutually exclusive with the time interval options, and it causes
          log files to be rotated without regard for the last rotation time.  
          When maxsize is used, both the size and timestamp of a log file are                  
          considered.
Ondra Sniper Flidr
  • 2,623
  • 11
  • 18
  • 1
    I think you want `maxsize`, not just `size`. The OP wants to rotate when the file reaches 2MB even if it's not time yet, as I understand it. – MadHatter Nov 11 '15 at 12:24
  • please check my update in question – nikola99 Nov 11 '15 at 12:32
  • Yep, @MadHatter is right, you have to use maxsize, not size. I edited my anwser. – Ondra Sniper Flidr Nov 11 '15 at 12:35
  • @OndraSniperFlidr i edit question can you please check if this is what i need to do ? – nikola99 Nov 11 '15 at 12:37
  • 1
    @nikola99: The problem is that if you have 5GB of log files every two days, it will grow beyond the 2MB you want faster than in 24h, which is the standard interval for the `logrotate` cron job. You should create a second config file for logrotate just for Apache and create a cron job that get called more often, e.g. every hour. – Sven Nov 11 '15 at 12:37
  • @Sven how will this look ? – nikola99 Nov 11 '15 at 12:40