sudo apt update && sudo apt upgrade -y
GitLab依赖以下服务,需提前安装:
curl:用于下载安装脚本;openssh-server:支持SSH克隆/推送代码;ca-certificates:确保HTTPS连接安全;postfix:处理邮件通知(如密码重置)。sudo apt install -y curl openssh-server ca-certificates postfix
安装postfix时,选择Internet Site类型,设置mail name为你的域名(如gitlab.example.com),后续可调整邮件配置。GitLab官方仓库提供最新版本,需先导入GPG密钥并添加仓库源:
curl https://packages.gitlab.com/gpg.key | sudo apt-key add -
buster):echo "deb https://packages.gitlab.com/gitlab/gitlab-ce/debian bullseye main" | sudo tee /etc/apt/sources.list.d/gitlab-ce.list
sudo apt update
通过APT安装GitLab CE(免费社区版):
sudo apt install -y gitlab-ce
external_url为你的服务器IP或域名(如http://192.168.1.100或https://gitlab.example.com)。sudo nano /etc/gitlab/gitlab.rb
找到external_url行,取消注释并修改(若使用HTTPS,需开启Let’s Encrypt自动证书,设置letsencrypt['enable'] = true)。sudo gitlab-ctl reconfigure
sudo gitlab-ctl start
sudo systemctl enable gitlab
external_url对应的地址(如http://192.168.1.100),首次访问需设置root管理员密码(默认管理员账号为root)。root账号和新密码登录GitLab Web界面。sudo ufw allow http
sudo ufw allow https
sudo ufw enable
gitlab.rb中的数据库配置,如gitlab_rails['db_adapter'] = "postgresql")。gitlab.rb中的Redis配置(如gitlab_rails['redis_cache_instance'] = "redis://127.0.0.1:6379")。gitlab-backup命令实现。sudo apt update && sudo apt upgrade gitlab-ce)。