温馨提示×

centos gitlab使用教程

小樊
36
2025-02-24 19:27:41
栏目: 智能运维
Centos服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在CentOS系统上安装和使用GitLab的步骤如下:

安装GitLab

  1. 安装依赖
sudo yum install -y curl policycoreutils-python openssh-server
  1. 启动并启用SSH服务
sudo systemctl enable sshd
sudo systemctl start sshd
  1. 配置防火墙
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld
  1. 添加GitLab的包仓库
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
  1. 安装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

  1. 登录GitLab

在浏览器中输入你的GitLab服务器IP地址,使用安装过程中设置的root密码登录。

  1. 创建新项目

登录后,点击顶部导航栏中的“New project”按钮,填写项目名称、描述等信息,选择可见性和初始化选项,然后点击“Create project”按钮。

  1. 上传代码

在项目页面中,点击“Upload file”按钮,选择要上传的文件,上传完成后点击“Commit changes”按钮。

  1. 克隆项目到本地

使用以下命令将远程仓库克隆到本地:

git clone http://your-gitlab-server-ip/username/project.git
  1. 基本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的官方文档以获取更详细的指导。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:centos gitlab备份恢复

0