Ubuntu环境下搭建GitLab私有仓库完整步骤
sudo apt update && sudo apt upgrade -y)。sudo apt install -y curl openssh-server ca-certificates postfix
example.com,若为内网可随意填写)。curl https://packages.gitlab.com/gpg.key | sudo apt-key add -
jammy为对应代号):echo "deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/gitlab-ce.list
sudo apt update
sudo apt install -y gitlab-ce
/etc/gitlab/gitlab.rb,将your_server_ip替换为服务器实际IP或域名):sudo vim /etc/gitlab/gitlab.rb
external_url行,取消注释并修改为:external_url 'http://your_server_ip'
your_server_ip替换为域名(如example.com)。sudo gitlab-ctl reconfigure  # 应用配置变更(耗时约1-2分钟)
sudo gitlab-ctl start       # 启动GitLab服务
sudo systemctl enable gitlab-runsvdir.service
sudo cat /etc/gitlab/initial_root_password
http://your_server_ip,使用默认管理员账号root和上述密码登录。root用户设置→Password,设置新密码(需包含大小写字母、数字和特殊字符)。Admin Area→Users→New User,填写用户名、邮箱、密码等信息,点击Create user。New project,输入项目名称(如my-private-repo),选择Visibility Level为Private(仅项目成员可访问),点击Create project。ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
~/.ssh/id_rsa(私钥)和~/.ssh/id_rsa.pub(公钥)。cat ~/.ssh/id_rsa.pub),登录GitLab→Profile Settings→SSH Keys,粘贴公钥并点击Add key。git clone git@your_server_ip:root/my-private-repo.git
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d your_domain.com
ufw(Ubuntu防火墙),允许HTTP(80)、HTTPS(443)和SSH(22)端口:sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 22/tcp
sudo ufw enable
通过以上步骤,即可在Ubuntu服务器上搭建GitLab私有仓库,实现团队代码的私有化托管与协作。