CentOS 内网如何安装 GitLab
GitLab 是一个基于 Web 的 Git 仓库管理工具,具有完整的 CI/CD 功能。在内网环境中安装 GitLab,可以使开发团队在一个安全的本地环境中进行协作。本文将详细介绍在 CentOS 上安装 GitLab 的步骤。
环境准备
在进行 GitLab 安装之前,需要确保 CentOS 系统已经更新到最新版本,并且拥有管理员权限。此外,还需要关闭 SELinux,或者为 GitLab 配置正确的规则。
# 更新系统
sudo yum update -y
# 检查并禁用 SELinux
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
安装必备工具
GitLab 需要一些依赖包,比如 curl、policycoreutils 和 openssh-server。使用以下命令安装这些工具:
sudo yum install -y curl policycoreutils-python-utils openssh-server
配置防火墙
为了允许外部访问 GitLab,需要配置防火墙开放 HTTP 和 SSH 服务端口:
# 启用、启动并检查防火墙状态
sudo systemctl enable firewalld
sudo systemctl start firewalld
sudo systemctl status firewalld
# 开放 HTTP 和 SSH 端口
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
安装并配置 GitLab
访问 GitLab 官方网站,获得最新的安装脚本 URL,然后执行以下命令下载并安装 GitLab:
# 添加 GitLab 包并安装
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="http://" yum install -y gitlab-ce
通过编辑 /etc/gitlab/gitlab.rb
文件来自定义 GitLab 的配置。例如,要要修改访问 URL:
sudo vi /etc/gitlab/gitlab.rb
找到内容 external_url
并修改为您的实际 URL。
启动 GitLab 服务
应用所有配置并启动 GitLab:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl start
通过http://
访问 GitLab,初次登录需要创建管理员账户。
结语
通过上述步骤,您已在 CentOS 内网环境中成功安装并配置了 GitLab。这将有助于团队在安全且受控的内网环境中管理代码库,提高开发效率。同时可以使用 GitLab 提供的 CI/CD 功能来自动化您的开发流程。