在CentOS上配置GitLab仓库需要以下几个步骤:
首先,你需要安装GitLab。你可以选择使用官方的GitLab包或者通过Docker来安装。
添加GitLab仓库:
sudo curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
安装GitLab CE(社区版):
sudo yum install gitlab-ce
启动并启用GitLab服务:
sudo systemctl start gitlab
sudo systemctl enable gitlab
访问GitLab:
打开浏览器,访问 http://<your_server_ip>,你应该会看到GitLab的登录页面。
安装Docker:
sudo yum install -y docker
sudo systemctl start docker
sudo systemctl enable docker
添加GitLab Docker仓库:
curl https://packages.gitlab.com/install/repositories/docker/gitlab/docker-ce.repo | sudo tee /etc/yum.repos.d/gitlab-docker-ce.repo
安装GitLab Docker镜像:
sudo yum install gitlab-ce-docker-ce
启动GitLab容器:
sudo docker run --detach \
--hostname gitlab.example.com \
--publish 80:80 \
--publish 443:443 \
--publish 22:22 \
--name gitlab \
--restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
生成SSH密钥(如果你还没有):
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
将公钥添加到GitLab:
~/.ssh/id_rsa.pub)粘贴到文本框中,然后点击“Add key”。测试SSH连接:
ssh -T git@gitlab.example.com
确保你的防火墙允许HTTP(80)、HTTPS(443)和SSH(22)流量。
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --permanent --zone=public --add-service=ssh
sudo firewall-cmd --reload
登录到GitLab:
打开浏览器,访问 http://<your_server_ip>,使用你的用户名和密码登录。
创建新仓库:
管理仓库:
通过以上步骤,你应该能够在CentOS上成功配置GitLab仓库。如果有任何问题,请参考GitLab的官方文档或社区支持。