Debian系统中GitLab存储管理指南
在Debian系统上管理GitLab存储的第一步是正确安装GitLab。首先更新系统并安装依赖包(curl、openssh-server、ca-certificates、postfix);然后添加GitLab官方软件包仓库(通过GPG密钥和源列表文件);最后安装GitLab CE(社区版)并完成初始配置。安装过程中需设置external_url(如http://your-gitlab-server-ip),这是GitLab服务的访问入口。
若需更改GitLab数据的默认存储位置(如仓库、数据库、日志等),可通过编辑配置文件/etc/gitlab/gitlab.rb实现。关键配置项包括:
git_data_dirs({"default" => {"path" => "/new/path/to/git-data"}}),用于存储Git仓库文件;gitlab_rails['backup_path'] = "/new/path/to/backups",指定备份文件的存储路径;gitlab_rails['backup_keep_time'] = 172800(单位:秒,默认保留2天)。sudo gitlab-ctl reconfigure应用配置,再重启GitLab服务(sudo gitlab-ctl restart)。ftype=1选项(mount -o ftype=1 /dev/sdX /path/to/git-data),确保GitLab兼容性。shared_buffers设置为物理内存的25%、max_worker_processes根据CPU核心数调整),提升数据库查询效率;gitlab_rails['redis_host'] = 'localhost'),加速常用数据的读取;unicorn['worker_processes'] = 4),避免资源竞争。Settings > General),取消不再需要的备份计划,或手动删除/var/opt/gitlab/backups目录中的旧备份文件(保留最近7天的备份即可);Settings > General > Maintenance and cleanup),设置Cleanup job定期清理缓存、临时文件,开启Log rotation压缩并删除旧日志(默认保留30天);Project Settings > Repository),当项目存储空间超过限制时,禁止用户继续推送代码。Settings > General > Advanced中启用Repository compression,减少Git对象占用的存储空间(可能轻微影响性能,适合存储空间紧张的场景)。sudo apt update && sudo apt upgrade gitlab-ce),获取性能优化补丁和安全修复;