Recently I found Gitlab Logs taking too many storage at my Gitlab CE Server. Is it safe for me to truncate the files and manually delete specific archived logs?
Can you share the best config for Logs Management, assuming I only have 500GB allocation for storage. Currently I haven’t change anything within my gitlab.rb files.
################################################################################
## GitLab Logging
##! Docs: https://docs.gitlab.com/omnibus/settings/logs.html
################################################################################
# logging['svlogd_size'] = 200 * 1024 * 1024 # rotate after 200 MB of log data
# logging['svlogd_num'] = 30 # keep 30 rotated log files
# logging['svlogd_timeout'] = 24 * 60 * 60 # rotate after 24 hours
# logging['svlogd_filter'] = "gzip" # compress logs with gzip
# logging['svlogd_udp'] = nil # transmit log messages via UDP
# logging['svlogd_prefix'] = nil # custom prefix for log messages
# logging['logrotate_frequency'] = "daily" # rotate logs daily
# logging['logrotate_maxsize'] = nil # rotate logs when they grow bigger than size ...
# logging['logrotate_size'] = nil # do not rotate by size by default
# logging['logrotate_rotate'] = 30 # keep 30 rotated logs
# logging['logrotate_compress'] = "compress" # see 'man logrotate'
# logging['logrotate_method'] = "copytruncate" # see 'man logrotate'
# logging['logrotate_postrotate'] = nil # no postrotate command by default
# logging['logrotate_dateformat'] = nil # use date extensions for rotated files rather than numbers ...
Log files should not take up any significant amount of your 500Gb storage allocation. If logs are taking up more than ~3% of available storage, I suspect something happened to prevent the logs from successfully rotating.
If you run du -h --threshold=50M /var/log/gitlab/* | sort -hr, do you see log directories consuming an abnormally large amount of storage?
If so, can you share the output from
# return 10 largest files in <large-log-directory>
ls -lhS /var/log/gitlab/<large-directory>/* | head -n 10
# run logrotate in debug mode
/opt/gitlab/embedded/sbin/logrotate -d -v -s /var/opt/gitlab/logrotate/logrotate.status /var/opt/gitlab/logrotate/logrotate.conf
Yay, solved the problem. You were right, logrotate doesn’t work properly due to permission problem at /var/opt/gitlab/logrotate/logrotate.d/xxx files.
Found it with script you gave earlier: /opt/gitlab/embedded/sbin/logrotate -d -v -s /var/opt/gitlab/logrotate/logrotate.status /var/opt/gitlab/logrotate/logrotate.conf
I have changed the permission to 600, then run logrotate manually. It drastically reduce the disk usage.