温馨提示×

CentOS环境下如何搭建GitLab服务器

小樊
70
2025-04-30 19:43:16
栏目: 云计算

在CentOS环境下搭建GitLab服务器需要以下几个步骤:

1. 安装必要的依赖

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

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

2. 添加GitLab仓库

添加GitLab的官方仓库以便安装最新版本的GitLab。

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

3. 安装GitLab CE(社区版)

使用yum安装GitLab社区版。

sudo yum install -y gitlab-ce

4. 配置GitLab

编辑GitLab的配置文件 /etc/gitlab/gitlab.rb,根据你的需求进行配置。例如,你可以更改GitLab的监听端口、外部URL等。

sudo nano /etc/gitlab/gitlab.rb

一些常见的配置项包括:

  • external_url 'http://your-gitlab-url':设置GitLab的外部访问URL。
  • gitlab_rails['lfs_enabled'] = true:启用Git LFS。
  • gitlab_rails['gitlab_shell_ssh_port'] = 2222:更改GitLab Shell的SSH端口。

5. 重新配置并重启GitLab

保存并退出配置文件后,重新配置并重启GitLab服务。

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

6. 访问GitLab

打开浏览器,访问你在配置文件中设置的 external_url,你应该能够看到GitLab的登录页面。

7. 配置防火墙

如果你启用了防火墙,确保开放GitLab使用的端口(默认是80和443)。

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

8. 设置SSL证书(可选)

为了安全起见,建议为GitLab设置SSL证书。你可以使用Let’s Encrypt免费获取SSL证书。

sudo yum install -y certbot python2-certbot-nginx
sudo certbot --nginx -d your-gitlab-url

按照提示完成SSL证书的安装和配置。

9. 配置SSH访问(可选)

如果你希望通过SSH访问GitLab,确保你的SSH密钥已经添加到GitLab账户中,并且GitLab Shell的SSH端口已经正确配置。

通过以上步骤,你应该能够在CentOS环境下成功搭建一个GitLab服务器。如果有任何问题,请参考GitLab的官方文档或社区支持。

0