在CentOS上搭建GitLab私有仓库的步骤如下:
首先,确保你的系统是最新的,并安装必要的依赖包。
sudo yum update -y
sudo yum install -y curl policycoreutils-python openssh-server
添加GitLab的官方仓库。
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
安装GitLab社区版。
sudo yum install -y gitlab-ce
编辑GitLab的配置文件 /etc/gitlab/gitlab.rb,根据需要进行配置。例如,你可以更改GitLab的监听端口、外部URL等。
sudo nano /etc/gitlab/gitlab.rb
找到以下行并进行修改:
external_url 'http://your-gitlab-url'
确保 external_url 设置正确,以便外部访问。
保存并退出编辑器后,运行以下命令重新配置并重启GitLab。
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
打开浏览器,访问你在 external_url 中设置的URL,例如 http://your-gitlab-url。你应该会看到GitLab的登录页面。
使用管理员账户登录后,创建一个新的私有仓库。
你可以使用SSH密钥来克隆私有仓库。
生成SSH密钥(如果还没有):
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
将公钥添加到GitLab账户中:
复制公钥内容:
cat ~/.ssh/id_rsa.pub
登录GitLab,进入 “Settings” -> “SSH Keys”。
粘贴公钥并保存。
克隆私有仓库:
git clone git@your-gitlab-url:username/private-repo.git
现在,你已经成功在CentOS上搭建了一个GitLab私有仓库,并可以克隆和使用它。