Ubuntu 中 GitLab 项目管理实操指南
一 环境准备与安装
sudo apt update && sudo apt install -y curl openssh-server ca-certificates postfixcurl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bashsudo apt-get install -y gitlab-cesudo vim /etc/gitlab/gitlab.rb,设置外部访问地址,例如:external_url 'http://gitlab.example.com'sudo gitlab-ctl reconfigure && sudo gitlab-ctl start二 组织与权限管理
三 代码托管与协作流程
git config --global user.name "Your Name";git config --global user.email "you@example.com"git clone <repo-url>;cd <repo>;git add .;git commit -m "init";git push -u origin main/mastergit remote rename origin old-origin;git remote add origin <repo-url>;git push -u origin --all;git push -u origin --tags四 CI/CD 与自动化
gitlab_rails['smtp_enable']=true、smtp_address='smtp.example.com'、smtp_port=587、smtp_user_name='you@example.com'、smtp_password='******'、smtp_domain='example.com'、smtp_authentication='login'、smtp_enable_starttls_auto=true;执行 sudo gitlab-ctl reconfiguresudo apt-get install certbot python3-certbot-nginx 获取证书;在 gitlab.rb 设置 nginx['redirect_http_to_https']=true、nginx['ssl_certificate']='/etc/letsencrypt/live/example.com/fullchain.pem'、nginx['ssl_certificate_key']='/etc/letsencrypt/live/example.com/privkey.pem';执行 sudo gitlab-ctl reconfigure && sudo gitlab-ctl restartexternal_url;权限问题:核对目录与服务权限;数据库问题:确认 PostgreSQL/MySQL 正常运行。五 备份恢复与日常运维
sudo gitlab-backup create(默认目录 /var/opt/gitlab/backups)gitlab.rb 设置 gitlab_rails['backup_path'] = "/new/backup/path" 并执行 sudo gitlab-ctl reconfigure0 2 * * * /opt/gitlab/bin/gitlab-backup create STRATEGY=copy CRON=1gitlab_rails['backup_keep_time'] = 7776000(保留 90 天)gitlab-ctl reconfigurebackup_path,确保属主为 git:git;停止连接服务 sudo gitlab-ctl stop puma 与 sudo gitlab-ctl stop sidekiq;执行 sudo gitlab-backup restore BACKUP=<timestamp>(仅填时间戳,不含 _gitlab_backup.tar);重启 sudo gitlab-ctl restart;校验 sudo gitlab-rake gitlab:check SANITIZE=truesudo gitlab-ctl status/start/stop/restart/tail;查看日志定位问题。