在CentOS系统上管理GitLab日志主要包括查看、配置日志记录以及日志的轮转和清理。以下是详细的步骤和信息:
sudo gitlab-ctl tail
sudo gitlab-ctl tail gitlab-rails
sudo cat /var/log/gitlab/gitlab-rails/production.log
或使用 less
命令分页查看:less /var/log/gitlab/gitlab-rails/production.log
tail -f /var/log/gitlab/gitlab-rails/production.log
journalctl -u gitlab
journalctl
journalctl -n 100
Runit日志管理:
/etc/gitlab/gitlab.rb
文件来自定义Runit的配置,例如:logging ['svlogd_size'] 200 * 1024 * 1024 # 切割超过200M的日志文件
logging ['svlogd_num'] 30 # 日志文件保留30天
logging ['svlogd_timeout'] 24 * 60 * 60 # 每24小时生成新一天的日志
logging ['svlogd_filter'] "gzip" # 使用gzip压缩日志
gitlab-ctl reconfigure
命令使配置生效。Logrotate日志管理:
/etc/gitlab/gitlab.rb
文件中的logrotate参数来管理日志文件,例如:logging ['logrotate_frequency'] "daily" # 每天切割一次日志
logging ['logrotate_size'] nil # 不按照默认值的大小切割日志
logging ['logrotate_rotate'] 30 # 日志文件保留30天
logging ['logrotate_compress'] "compress" # 使用'man logrotate'查看详细信息
gitlab-ctl reconfigure
命令重载配置文件。使用logrotate:
/etc/logrotate.d/gitlab
文件,添加或修改以下内容:/var/log/gitlab/gitlab-rails/*.log {
daily rotate 7
compress
missingok
notifempty
create 0644 gitlab gitlab
}
sudo logrotate -f /etc/logrotate.d/gitlab
强制重新旋转日志。日志清理策略:
git log
命令结合 --since
和 --until
参数来清理特定时间范围的日志。git reflog expire
命令清理过期的引用日志。git gc
命令进行垃圾回收,清理无用的对象。通过上述方法,可以有效地管理GitLab在CentOS上的日志,确保系统的稳定运行和安全性。