以下是一个CentOS上GitLab性能调优的典型案例,结合硬件、系统、配置等多方面优化:
调整内核参数:
# 增加网络连接队列和缓冲区
sysctl -w net.core.somaxconn=65535
sysctl -w net.ipv4.tcp_max_syn_backlog=65535
sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.wmem_max=16777216
# 优化TCP连接复用
sysctl -w net.ipv4.tcp_tw_reuse=1
sysctl -w net.ipv4.tcp_fin_timeout=30
# 启用大页内存(需根据服务器内存调整)
sysctl -w vm.nr_hugepages=512
执行sysctl -p
使配置生效。
调整文件描述符限制:
编辑/etc/security/limits.conf
,添加:
* soft nofile 65535
* hard nofile 65535
确保高并发时不会因文件句柄不足报错。
调整Unicorn参数:
编辑/etc/gitlab/gitlab.rb
:
unicorn['worker_processes'] = 4 # 根据CPU核心数调整(建议为CPU核心数的1-2倍)
unicorn['timeout'] = 300
unicorn['keepalive'] = true
执行sudo gitlab-ctl reconfigure
生效。
优化Sidekiq并发:
sidekiq['concurrency'] = 20 # 根据服务器负载调整,避免过高导致内存不足
sidekiq['queues'] = ["default", "gitlab"]
重启GitLab使配置生效。
启用缓存:
gitlab_rails['cache_store'] = :memory_store, { size: 128.megabytes } # 使用内存缓存加速访问
nginx['enable'] = true
nginx['listen_port'] = 80
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.example.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.example.com.key"
重启Nginx和GitLab。
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --permanent --add-port=22/tcp
firewall-cmd --reload
ssl_protocols TLSv1.2 TLSv1.3
和ssl_ciphers
参数,提升加密传输效率。gitlab-rake cache:clear
命令定期清理缓存,避免磁盘空间占用过高。ab
(Apache Benchmark)工具模拟多用户并发访问,对比优化前后的响应时间(如从5秒缩短至1.5秒)。/var/log/gitlab/nginx/
下的访问日志,确认请求处理时间是否缩短,错误率是否降低。参考来源: