在CentOS系統下管理GitLab日志主要包括查看、配置和監控日志。以下是一些具體的方法:
gitlab-ctl
命令實時查看日志:sudo gitlab-ctl tail
可以指定查看特定服務的日志,例如:sudo gitlab-ctl tail nginx/gitlab_access.log
sudo gitlab-ctl tail nginx/gitlab_error.log
cat
命令查看特定日志文件:sudo cat /var/log/gitlab/gitlab-rails/production.log
Runit日志管理:
Runit是GitLab默認的日志管理系統??梢酝ㄟ^修改 /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日志管理:
Omnibus-gitlab從7.4版本開始內置了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
命令使配置生效。
curl --header "PRIVATE-TOKEN: your_private_token" "https://gitlab.example.com/api/v4/projects/project_id/jobs/job_id/trace"
其中 your_private_token
是你的GitLab私人訪問令牌。通過上述方法,可以有效地管理GitLab在CentOS上的日志,確保系統的穩定運行和安全性。