在 Linux 上配置 GitLab 日志,通常可以从 GitLab 自身配置(Omnibus)、系统日志(rsyslog/journalctl) 以及 日志切割(logrotate) 三个方面来做。下面按常见场景说明。
如果你是用 Omnibus GitLab(最常见方式),配置文件在:
/etc/gitlab/gitlab.rb
默认日志目录:
/var/log/gitlab/
常见子目录:
gitlab-rails/nginx/postgresql/redis/gitaly/例如修改 Rails 日志级别:
gitlab_rails['log_level'] = 'info' # debug / info / warn / error
修改后执行:
gitlab-ctl reconfigure
# Nginx 日志
nginx['log_directory'] = "/var/log/gitlab/nginx"
# PostgreSQL 日志
postgresql['log_directory'] = "/var/log/gitlab/postgresql"
# Redis 日志
redis['log_directory'] = "/var/log/gitlab/redis"
gitlab_rails['disable_terms_acceptance'] = false
# 关闭 audit 日志(谨慎)
gitlab_rails['audit_log_enabled'] = false
GitLab 默认已配置 logrotate,文件在:
/opt/gitlab/embedded/cookbooks/package/resources/logrotate_config.rb
或:
/etc/logrotate.d/gitlab
示例配置:
/var/log/gitlab/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
copytruncate
}
修改后测试:
logrotate -d /etc/logrotate.d/gitlab
GitLab 服务由 systemd 管理:
# 查看所有 GitLab 服务
gitlab-ctl status
# 查看某个服务日志
journalctl -u gitlab-runsvdir
# 实时查看
journalctl -u gitlab-runsvdir -f
如果你希望集中收集日志:
gitlab_rails['log_to_stdout'] = true
gitlab-ctl reconfigure
# /etc/rsyslog.d/gitlab.conf
if ($programname == "gitlab") then {
action(type="omfile" file="/var/log/central/gitlab.log")
}
重启 rsyslog:
systemctl restart rsyslog
# 查看 GitLab 整体日志
gitlab-ctl tail
# 查看某个组件
gitlab-ctl tail nginx
gitlab-ctl tail postgresql
gitlab_rails['log_level'] = 'warn'
nginx['log_format'] = 'combined'
logging['logrotate_frequency'] = 'daily'
logging['logrotate_rotate'] = 7
如果你能告诉我:
我可以给你更精确的配置方案。