centos

利用CentOS搭建GitLab服务器的步骤

小樊
53
2025-04-06 14:43:06
栏目: 云计算

在CentOS上搭建GitLab服务器的步骤如下:

准备工作

  1. 确保你的CentOS系统已经安装了必要的软件和工具,如curlopenssh-server
  2. 确保系统已经更新到最新版本。

安装依赖

sudo yum update -y
sudo yum install -y curl policycoreutils-python openssh-server openssh-clients
sudo systemctl enable sshd
sudo systemctl start sshd
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 yum install gitlab-ce

配置GitLab

  1. 设置外部URL(如果需要):

    sudo vi /etc/gitlab/gitlab.rb
    

    找到并修改以下行:

    external_url 'http://your_domain_or_ip'
    

    保存并关闭文件。

  2. 重新配置GitLab

    sudo gitlab-ctl reconfigure
    

启动GitLab

sudo gitlab-ctl start

访问GitLab

  1. 在浏览器中输入你的服务器IP地址或域名,你将看到GitLab的欢迎页面。
  2. 首次访问时,需要创建一个管理员账户并设置密码。

使用Docker安装GitLab(可选)

如果你希望使用Docker来安装GitLab,可以按照以下步骤进行:

  1. 安装Docker

    sudo yum -y update
    sudo yum -y install yum-utils device-mapper-persistent-data lvm2
    sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    sudo yum -y install docker-ce-20.10.9-3.el7
    sudo systemctl start docker
    sudo systemctl enable docker
    
  2. 拉取GitLab镜像

    docker pull registry.gitlab.cn/omnibus/gitlab-ce:latest
    
  3. 运行GitLab容器

    docker run --detach \
      --hostname your_domain_or_ip \
      --publish 443:443 \
      --publish 80:80 \
      --name gitlab \
      --restart always \
      --volume $GITLAB_HOME/config:/etc/gitlab \
      --volume $GITLAB_HOME/logs:/var/log/gitlab \
      --volume $GITLAB_HOME/data:/var/opt/gitlab \
      --shm-size 256m \
      registry.gitlab.cn/omnibus/gitlab-ce:latest
    
  4. 重启GitLab容器

    docker restart gitlab
    
  5. 进入容器查看密码

    docker exec -it gitlab /bin/bash
    cat /etc/gitlab/initial_root_password
    
  6. 登录GitLab: 使用生成的密码和用户名root登录。

以上步骤可以帮助你在CentOS系统上成功搭建GitLab服务器。如果在安装过程中遇到问题,建议参考GitLab的官方文档或社区支持。

0
看了该问题的人还看了