在CentOS上部署GitLab可以通过多种方式实现,包括使用官方的GitLab仓库中的RPM包、使用Docker容器或者使用源代码编译安装。以下是使用官方RPM包和Docker容器两种常见方法的步骤:
添加GitLab仓库
首先,你需要添加GitLab的官方YUM仓库。创建一个新的YUM仓库文件 /etc/yum.repos.d/gitlab.repo
并添加以下内容:
[gitlab]
name=GitLab repository
baseurl=https://packages.gitlab.com/gitlab/gitlab-ce/el/$releasever/$basearch
repo_gpgcheck=1
gpgcheck=1
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
安装GitLab 使用YUM安装GitLab CE(社区版):
sudo yum install -y curl policycoreutils openssh-server
sudo yum install -y gitlab-ce gitlab-ce-cli
配置GitLab
安装完成后,GitLab会自动启动并进行基本配置。你可以通过浏览器访问 http://your_server_ip
来完成初始设置。
调整防火墙设置 如果你的服务器启用了防火墙,确保开放HTTP(80)和HTTPS(443)端口:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
重新配置GitLab 如果需要重新配置GitLab,可以使用以下命令:
sudo gitlab-ctl reconfigure
安装Docker 如果你还没有安装Docker,可以按照以下命令进行安装:
sudo yum install -y docker
sudo systemctl start docker
sudo systemctl enable docker
添加GitLab Docker仓库 添加GitLab的Docker仓库:
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
安装GitLab Docker包 使用YUM安装GitLab的Docker包:
sudo yum install -y gitlab-ce-gitlab-ce-cli
运行GitLab容器 使用以下命令运行GitLab容器:
sudo gitlab-ctl start
访问GitLab
打开浏览器并访问 http://your_server_ip
,你应该能够看到GitLab的登录页面。
调整防火墙设置 确保开放HTTP(80)和HTTPS(443)端口:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
通过以上两种方法,你可以在CentOS上成功部署GitLab。选择哪种方法取决于你的具体需求和环境。使用Docker部署通常更简单且易于管理,而使用RPM包则提供了更多的配置选项。