温馨提示×

GitLab在CentOS上的部署流程

小樊
64
2025-04-04 14:17:06
栏目: 智能运维

在CentOS上部署GitLab的流程如下:

系统更新与准备

  1. 确保你的CentOS系统是最新的:

    sudo yum update -y
    
  2. 安装必要的依赖包:

    sudo yum install -y curl policycoreutils-python-utils openssh-server perl
    

添加GitLab仓库

  1. 使用GitLab提供的脚本来添加官方仓库:
    curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
    

安装GitLab

  1. 安装GitLab社区版(gitlab-ce):
    sudo yum install -y gitlab-ce
    

配置并启动GitLab

  1. 编辑 /etc/gitlab/gitlab.rb 文件以进行自定义配置,例如更改外部URL或邮件设置:
    sudo vi /etc/gitlab/gitlab.rb
    
  2. 保存文件后,应用配置更改:
    sudo gitlab-ctl reconfigure
    
  3. 启动GitLab服务:
    sudo gitlab-ctl start
    

防火墙设置

  1. 配置防火墙规则,允许HTTP和HTTPS流量:
    sudo firewall-cmd --permanent --add-service=https
    sudo firewall-cmd --reload
    

访问GitLab

  1. 默认情况下,GitLab将在HTTPS端口443上运行。你可以通过浏览器访问 https://your_server_ip 来访问GitLab界面。
  2. 首次登录时,你需要设置管理员账户的密码。

其他注意事项

  • 关闭防火墙和SELinux(可选但推荐):
    sudo systemctl disable --now firewalld.service
    sudo sed -ri 's/(SELINUX).*/\1disabled/g' /etc/selinux/config
    sudo setenforce 0
    
  • 配置EPEL源(如果需要):
    sudo yum install -y epel-release
    

常见问题解答

  • 如何更改GitLab的默认端口? 编辑 /etc/gitlab/gitlab.rb 文件,找到 external_url 设置项并将其更改为新的URL和端口,然后运行 sudo gitlab-ctl reconfigure 应用更改。
  • 如何在GitLab中添加用户? 登录到GitLab的Web界面,点击页面右上角的用户头像或用户名,选择“Admin Area”,在左侧菜单中选择“Users”,然后点击“Add user”按钮,输入新用户的用户名、邮箱地址和其他必要信息,然后点击“Create user”。

以上步骤应该能够帮助你成功在CentOS上部署GitLab。如果在安装过程中遇到问题,可以参考GitLab的官方文档或相关社区资源。

0