Debian上GitLab性能优化指南
sudo apt update && sudo apt upgrade,确保Debian系统及内核为最新稳定版本,修复已知性能bug并提升系统稳定性。curl openssh-server ca-certificates tzdata perl),确保GitLab正常运行。/etc/gitlab/gitlab.rb中禁用GitLab自带Nginx:nginx['enable'] = false,避免重复代理带来的资源消耗。puma['threads_min'](建议4)、puma['threads_max'](建议16)及puma['worker_processes'](建议等于CPU核心数),平衡并发处理能力与内存占用。postgresql['shared_buffers'] = "25% of total RAM"(如16GB内存设置为4GB),提升数据库缓存命中率。postgresql['work_mem'] = "4MB"(复杂查询可适当增加至8MB-16MB),提升排序、聚合等操作性能。postgresql['max_connections']设置为并发用户数的2倍(如100并发用户设置为200),避免连接过多导致数据库崩溃。redis['enable'] = true),并设置合理内存限制(如redis['maxmemory'] = '2GB'),加速数据访问(如用户会话、查询结果)。/var/opt/gitlab)迁移至SSD,提升仓库读写速度。迁移步骤:停止GitLab服务(sudo gitlab-ctl stop),修改/etc/fstab挂载SSD,再移动数据并重启服务(sudo gitlab-ctl start)。/etc/gitlab/gitlab.rb中设置gitlab_rails['git_data_compression'] = true,压缩Git对象(如提交、树、blob),减少存储空间占用(约节省20%-30%),但对性能影响较小(现代CPU可忽略不计)。sudo gitlab-rake gitlab:backup:cleanup(保留最近7天备份,可根据需求调整);sudo gitlab-rake gitlab:ci:cleanup(保留最近30天作业日志);sudo journalctl --vacuum-time=2weeks(清理2周前系统日志);sudo gitlab-rake tmp:clean(清理/tmp目录下临时文件)。/etc/gitlab/gitlab.rb中配置对象存储路径:gitlab_rails['object_store']['enabled'] = true,并设置访问密钥、存储桶名称等参数。/etc/sysctl.conf中的参数,如net.ipv4.tcp_syn_retries = 3(减少SYN重传次数)、net.ipv4.tcp_window_scaling = 1(启用窗口扩大因子,提升大流量传输效率),提升网络吞吐量。gitlab_rails['log_rotate_frequency'] = 'daily'、gitlab_rails['log_max_size'] = '200MB'),定期清理过期日志(如sudo gitlab-rake log:rotate),避免日志文件过大占用磁盘空间。.gitlab-ci.yml文件中设置parallel关键字(如parallel: 4),将单个任务拆分为多个并行任务,缩短构建时间(如测试任务可同时运行在4个节点上)。resources: limits: ncpus: 2, memory: 4GiB),避免单个任务占用过多资源导致其他任务排队等待。cache: key: ${CI_COMMIT_REF_SLUG} paths: - vendor/bundle),缓存第三方依赖(如Ruby gems、Node.js modules),避免每次构建都重新下载,提升构建速度。