温馨提示×

GitLab在CentOS上怎么配置

小樊
38
2025-06-08 04:20:30
栏目: 智能运维

在CentOS上配置GitLab涉及多个步骤,包括安装必要的依赖包、添加GitLab仓库、安装GitLab、配置GitLab以及启动和访问GitLab服务。以下是详细的步骤:

1. 安装必要的依赖包

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

sudo yum update -y sudo yum install -y curl policycoreutils-python openssh-server openssh-clients postfix perl git nodejs rsync cronie 

2. 配置防火墙

打开必要的端口以允许HTTP和SSH访问,并添加HTTP服务到防火墙:

sudo systemctl enable sshd sudo systemctl start sshd sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --reload 

3. 添加GitLab仓库

添加GitLab的官方仓库:

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

4. 安装GitLab

使用以下命令安装GitLab社区版(CE):

sudo EXTERNAL_URL="http://your_domain_or_ip" yum install -y gitlab-ce 

your_domain_or_ip 替换为你的GitLab服务器的域名或IP地址。

5. 配置GitLab

编辑GitLab的配置文件:

sudo vi /etc/gitlab/gitlab.rb 

修改 external_url 为你设置的域名或IP地址。如果需要,添加以下配置以允许HTTP和HTTPS流量:

gitlab_rails['gitlab_shell_ssh_port'] = 22 nginx['listen_port'] = 80 nginx['listen_https'] = 443 

保存并关闭文件,然后重新配置并启动GitLab服务:

sudo gitlab-ctl reconfigure sudo gitlab-ctl restart 

6. 访问GitLab

在浏览器中输入你在配置文件中设置的域名或IP地址,你应该能看到GitLab的登录页面。首次登录时,需要设置管理员账户的密码。

以上步骤提供了在CentOS上安装和配置GitLab的基本指南。根据你的具体需求,可能还需要进行额外的配置,例如设置HTTPS、配置SSL证书等。在生产环境中,建议详细配置GitLab的安全设置。

0