centos

CentOS上GitLab配置指南

小樊
38
2025-07-12 14:54:47
栏目: 智能运维

在CentOS上配置GitLab涉及多个步骤,包括安装必要的依赖包、配置网络设置、安装GitLab软件包、修改配置文件以及启动和验证GitLab服务。以下是详细的步骤:

1. 安装必要的依赖包

首先,确保系统是最新的,并安装SSH、防火墙、Postfix、wget等必要的软件包。

sudo yum update -y
sudo yum install -y curl policycoreutils-python openssh-server openssh-client postfix wget

2. 配置网络设置

配置SSH服务开机自启动并启动SSH服务:

sudo systemctl enable sshd
sudo systemctl start sshd

配置防火墙以允许HTTP和HTTPS流量:

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

3. 添加GitLab仓库

添加GitLab的官方仓库镜像,以便使用YUM命令安装GitLab。

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

4. 安装GitLab

使用YUM命令安装GitLab社区版(CE)。

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

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

5. 配置GitLab

编辑GitLab的配置文件 /etc/gitlab/gitlab.rb,设置外部URL和其他必要配置。

sudo vi /etc/gitlab/gitlab.rb

在编辑器中找到并修改以下配置项:

external_url 'http://your_domain_or_ip'

替换为实际的服务器IP地址或域名。

如果需要,添加以下配置以允许HTTP和HTTPS流量:

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

保存文件后,应用配置更改:

sudo gitlab-ctl reconfigure

6. 启动和验证GitLab服务

重启GitLab服务以使配置生效:

sudo gitlab-ctl restart

访问GitLab页面以验证安装是否成功。默认情况下,GitLab通常监听80端口,可以通过浏览器访问 http://your_domain_or_ip

7. 配置邮件服务(可选)

如果你需要使用邮件通知功能,可以配置PostgreSQL数据库并设置SMTP邮件服务器。

sudo yum install -y postgresql-server postgresql-contrib
sudo postgresql-setup initdb
sudo systemctl enable postgresql
sudo systemctl start postgresql

编辑PostgreSQL的配置文件 /var/lib/pgsql/data/pg_hba.conf,将 peer 改为 md5

local   all             all                                     md5

然后重启PostgreSQL服务。

sudo systemctl restart postgresql

以上步骤应该可以帮助你在CentOS上成功安装和配置GitLab。

0
看了该问题的人还看了