Why would logrotate delete the file instead of rotating it?
Here's the config:
/var/log/httpd/*log {
size 1G
missingok
notifempty
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
endscript
}
Your config looks ok, there is likely some default in your /etc/logrotate.conf that is deleting files.
If you have rotate 0 in your config file, old files will be deleted rather than rotated.
It may be that the files are being rotated but you are looking in the wrong place.
Check the logrotate logs with cat /var/lib/logrotate/status to verify that logrotate is running as expected.
And of course, familiarize yourself with logrotate by reading the man page
Related
I've configured it to run hourly, it rotates logs hourly but not sending it to s3, what could be the reason?
/var/log/newlog
{
rotate 5
hourly
missingok
notifempty
compress
dateext
dateformat -%Y-%m-%d-%H%M%S
postrotate
/usr/lib/newlog/new
endscript
/usr/lib/newlog/new is a script, using s3cmd to sync .gz files to s3
From the above code it is seen that, there is no mention of S3 bucket to which the log files should be compressed.
Your script should add the following lines:
/var/log/newlog {
postrotate
/usr/lib/newlog/new > /dev/null 2>&1 || true
BUCKET=logging-bucket
INSTANCE_ID=`curl --silent http://169.254.169.254/latest/meta-data/instance-id | sed -e "s/i-//"`
/usr/bin/s3cmd -m text/plain sync /var/log/messages-* s3://${BUCKET}/${INSTANCE_ID}/var/log/
endscript
}
where logging-bucket is name of the bucket in which the compressed files will be stored.
Also make sure the user has permissions to the S3.
Thanks
How do I enable log rotation for log files e.g. access.log.
Is this built in ?
Docs only say "This allows the logs to be rotated and processed by an external program, such as logrotate"
If you are running Traefik in a Docker container then you can do something like this:
Check that logrotate is installed on the Docker host:
logrotate --version
Create file in /etc/logrotate.d/:
vi /etc/logrotate.d/traefik
Put the following script, do not forget to fill with the container name.
/var/log/traefik/*.log {
size 10M
rotate 5
missingok
notifempty
postrotate
docker kill --signal="USR1" <container-name>
endscript
}
Run!
logrotate /etc/logrotate.conf --debug
logrotate /etc/logrotate.conf
It seems like there's no logrotation built-in so i enabled logrotation on the Host that traefik_access.log is mounted to.
In order for this to work when traefik is running in a docker container, you must volume mount the directory containing the log file (/opt/traefik/logs), not the log file itself (/traefik_access.log).
volumes:
- /opt/traefik/logs:/logs
My logrotate-config for traefik 1.7.4 running in a container with volume mount to "/opt/traefik/logs":
/opt/traefik/logs/*.log {
daily
rotate 30
missingok
notifempty
compress
dateext
dateformat .%Y-%m-%d
create 0644 root root
postrotate
docker kill --signal="USR1" $(docker ps | grep traefik | awk '{print $1}')
endscript
}
Log Rotation
Traefik will close and reopen its log files, assuming they're configured, on receipt of a USR1 signal. This allows the logs to be rotated and processed by an external program, such as logrotate.
https://docs.traefik.io/v1.6/configuration/logs/#log-rotation
Someone before me setup a redis instance (version 2.6).
But for some reason, whoever set this, had
Placed the config file etc like this /etc/redis.conf
The dir config has ./ set, like this dir ./
The instance is being run as non-root.
Like this:
$ ps aux | grep "redis"`
user /home/user/redis-stable/src/redis-server /etc/redis.conf
Logging is going to /dev/null, because daemonize yes && logfile stdout
So it is unable to create backups in /etc/ because it doesn't have permissions (I'm guessing), and I can't even see what is going on because the logs are going to /dev/null.
I want to make a backup so I can turn redis off to fix all these things, without losing any data. Any ideas?
I've tried:
touch /etc/dump.rdb
chown user:users /etc/dump.rdb
But it is still not able to write. I'm guessing it might have a temp file it tries to write to before it moves it to /etc/dump.rdb
After looking at Redis source code, it does seem like there is a temp file: https://github.com/antirez/redis/blob/04542cff92147b9b686a2071c4c53574771f4f88/src/rdb.c#L986
snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid());
Also tried
redis 127.0.0.1:6379> config set logfile /home/user/redis.log
(error) ERR Unsupported CONFIG parameter: logfile
Run:
config get dir
and you would see the directory where redis is saving rdb.
Run:
config set dir /home/user/
to change the rdb dump directory to /home/user.
then run:
redis-cli -p <port> bgsave
This would initiate a rdb dump.
Hope this helps.
My ubuntu server, few days ago the access.log and error.log files created under /var/log/apache2, but they still empty,
Currently apache is logging into access.log.1 and error.log.1, this issue is happening for all the virtual hosts on my server.
all permision are normally "rw-r--r--" and owner root:adm under the /var/log/apache2
here is my /etc/logrotate.d/apache2 "we didn't change it"
/var/log/apache2/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 644 root adm
sharedscripts
postrotate
if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
/etc/init.d/apache2 reload > /dev/null
fi
endscript
Did you check permission on the /var/log/apache2 directory?
$ ls -l /var/log/
drwxr-x--- 2 root adm 4096 Apr 12 06:55 apache2
I Found the issue was because the apache2 daemon file under /etc/init.d was "some how" erased!!,
I replaced that file from backup and it is logging normally now.
Does anyone have a sample logrotate config for redis? This is what I have so far
/var/log/redis/*.log {
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
...
endscript
}
But I'm not sure what to do on the postrotate step. This is on Ubuntu 10.04 LTS.
This will probably suffice:
/var/log/redis/*.log {
weekly
rotate 10
copytruncate
delaycompress
compress
notifempty
missingok
}
I went with
/var/log/redis/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 0660 redis redis
}
because I don't want copytruncate.
I'm not sure the create line is necessary. It matches the file mode and ownership of the log files typically created by redis-server on Ubuntu (or Debian).