在CentOS上实现GitLab的版本控制,可以按照以下步骤进行:
添加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>,默认用户名和密码是 root。
安装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 EXTERNAL_URL="http://<your_server_ip>" yum install gitlab-ce-docker 启动GitLab容器:
sudo gitlab-ctl reconfigure 访问GitLab: 打开浏览器,访问 http://<your_server_ip>。
登录GitLab: 使用默认的用户名和密码登录。
配置SSH密钥:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" cat ~/.ssh/id_rsa.pub Settings -> SSH Keys,粘贴公钥并保存。登录GitLab: 使用浏览器登录GitLab。
创建新项目:
New project。Create project。克隆项目:
git clone http://<your_server_ip>/<username>/<project_name>.git cd <project_name> 添加文件并提交:
git add . git commit -m "Initial commit" 推送代码到GitLab:
git push origin master 拉取最新代码:
git pull origin master 创建 .gitlab-ci.yml 文件: 在项目根目录下创建一个 .gitlab-ci.yml 文件,定义CI/CD流程。
提交并推送 .gitlab-ci.yml 文件:
git add .gitlab-ci.yml git commit -m "Add CI/CD configuration" git push origin master 通过以上步骤,你可以在CentOS上成功安装和配置GitLab,并使用Git进行版本控制。