在CentOS系统上安装和使用GitLab的步骤如下:
安装GitLab
- 安装依赖:
sudo yum install -y curl policycoreutils-python openssh-server
- 启动并启用SSH服务:
sudo systemctl enable sshd sudo systemctl start sshd
- 配置防火墙:
sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --permanent --add-service=http sudo systemctl reload firewalld
- 添加GitLab的包仓库:
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
- 安装GitLab:
- 企业版:
sudo EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ee
- 社区版:
sudo EXTERNAL_URL="http://10.20.0.116" yum install -y gitlab-ce
配置GitLab
- 修改外部URL:
vi /etc/gitlab/gitlab.rb external_url 'http://your-gitlab-server-ip'
- 配置邮件服务(可选):
gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.example.com" gitlab_rails['smtp_port'] = 587 gitlab_rails['smtp_user_name'] = "your-email@example.com" gitlab_rails['smtp_password'] = "your-password" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true gitlab_rails['gitlab_email_from'] = 'your-email@example.com'
- 重新配置并重启GitLab:
gitlab-ctl reconfigure gitlab-ctl restart
使用GitLab
- 登录GitLab:
在浏览器中输入你的GitLab服务器IP地址,使用安装过程中设置的root密码登录。
- 创建新项目:
登录后,点击顶部导航栏中的“New project”按钮,填写项目名称、描述等信息,选择可见性和初始化选项,然后点击“Create project”按钮。
- 上传代码:
在项目页面中,点击“Upload file”按钮,选择要上传的文件,上传完成后点击“Commit changes”按钮。
- 克隆项目到本地:
使用以下命令将远程仓库克隆到本地:
git clone http://your-gitlab-server-ip/username/project.git
- 基本Git命令:
- 克隆:
git clone http://your-gitlab-server-ip/username/project.git
- 提交:
git add . git commit -m "Commit message"
- 推送:
git push origin master
- 拉取:
git pull origin master
- 创建分支:
git checkout -b new-branch
- 合并分支:
git checkout master git merge new-branch
以上步骤涵盖了在CentOS系统上安装、配置和使用GitLab的基本流程。请注意,具体步骤可能会因GitLab版本和服务器配置的不同而有所差异。建议参考GitLab的官方文档以获取更详细的指导。