centos

如何在 CentOS 上配置 GitLab

小樊
45
2025-04-28 19:16:14
栏目: 智能运维

在 CentOS 上配置 GitLab 需要几个步骤,包括安装必要的依赖项、添加 GitLab 仓库、安装 GitLab 以及配置 GitLab。以下是一个详细的步骤指南:

1. 安装必要的依赖项

首先,确保你的系统是最新的,并且安装了一些必要的依赖项。

sudo yum update -y
sudo yum install -y curl policycoreutils openssh-server

2. 添加 GitLab 仓库

GitLab 提供了一个官方的 YUM 仓库,你可以使用它来安装 GitLab。

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

3. 安装 GitLab

添加仓库后,你可以安装 GitLab Community Edition (CE)。

sudo yum install -y gitlab-ce

4. 配置 GitLab

安装完成后,GitLab 会自动启动并运行。你可以通过浏览器访问 GitLab 的默认地址 http://<your_server_ip> 来完成初始配置。

external_url 'http://yourdomain.com'
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

5. 配置防火墙

确保你的防火墙允许 HTTP 和 HTTPS 流量。

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

6. 配置 SSH 访问

如果你希望通过 SSH 访问 GitLab,确保你的服务器上已经生成了 SSH 密钥,并将公钥添加到 GitLab 用户的 ~/.ssh/authorized_keys 文件中。

sudo su - git
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "your_ssh_public_key" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

7. 验证配置

最后,验证你的配置是否正确。你可以通过浏览器访问 http://<your_server_ip> 并使用管理员账户登录,或者通过 SSH 访问 GitLab 服务器。

ssh git@your_server_ip

通过以上步骤,你应该能够在 CentOS 上成功配置 GitLab。如果有任何问题,请参考 GitLab 的官方文档或社区支持。

0
看了该问题的人还看了