Deploying GitLab on CentOS 8 Using RPM Packages and Configuring an External PostgreSQL Database
This guide walks through installing GitLab CE on CentOS 8 via an RPM package, adjusting the gitlab.rb configuration, managing the GitLab service, testing access, and optionally connecting GitLab to an external PostgreSQL database running in Docker.
This article demonstrates how to install GitLab CE on a CentOS 8 system using the Tsinghua mirror RPM package, configure the instance, control its services, test web access, and optionally connect it to an external PostgreSQL database.
Using RPM Package Deployment
The system is CentOS 8 and the package is fetched from the Tsinghua mirror.
## 下载软件包
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el8/gitlab-ce-13.7.0-ce.0.el8.x86_64.rpm
## 安装
rpm -ivh gitlab-ce-13.7.0-ce.0.el8.x86_64.rpm
## 日志输出
warning: gitlab-ce-13.7.0-ce.0.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID f27eab47: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:gitlab-ce-13.7.0-ce.0.el8 ################################# [100%]
It looks like GitLab has not been configured yet; skipping the upgrade script.After installation, GitLab prompts to set external_url in /etc/gitlab/gitlab.rb and run sudo gitlab-ctl reconfigure to start the instance.
Configuration
Edit /etc/gitlab/gitlab.rb to set the desired hostname. The default line is:
32 external_url 'http://gitlab.example.com'To change the domain, replace it, for example:
## 修改gitlab.rb
external_url 'http://gitlab.devops.com'
## 重新配置
gitlab-ctl reconfigureService Control
## 启动服务
gitlab-ctl start
## 重启服务
gitlab-ctl restart
## 查看状态
gitlab-ctl status
## 停止
gitlab-ctl stopAccess Test
Add the chosen domain to /etc/hosts (e.g., 192.168.1.200 gitlab.devops.com ) and browse to http://gitlab.devops.com/ . Log in with the default user root and the password you set (e.g., devops1234 ).
Extension: Using an External PostgreSQL Database
Start PostgreSQL with Docker
mkdir /root/gitlab/pgdata
docker run --name dockerPG11 \
-e POSTGRES_PASSWORD=postgres \
-v /root/gitlab/pgdata:/var/lib/postgresql/data \
-p 54322:5432 \
-d postgres:11.5
## 创建数据库
psql -U postgres -h localhost -p 54322
# create role gitlab login encrypted password 'gitlab';
# create database gitlabhq_production owner=gitlab ENCODING = 'UTF8';
\c gitlabhq_production
CREATE EXTENSION IF NOT EXISTS btree_gist;
CREATE EXTENSION IF NOT EXISTS pg_trgm;
\qThese extensions must be created by a superuser; otherwise you will see permission‑denied errors.
Modify gitlab.rb for PostgreSQL
654 gitlab_rails['db_adapter'] = "postgresql"
655 gitlab_rails['db_encoding'] = "utf8"
657 gitlab_rails['db_database'] = "gitlabhq_production"
658 gitlab_rails['db_username'] = "gitlab"
659 gitlab_rails['db_password'] = "gitlab"
660 gitlab_rails['db_host'] = "192.168.1.200"
661 gitlab_rails['db_port'] = 54322
1025 postgresql['enable'] = false
## 配置更新
gitlab-ctl reconfigureVerify Configuration
cat /opt/gitlab/embedded/service/gitlab-rails/config/database.yml
# This file is managed by gitlab-ctl. Manual changes will be
# erased! To change the contents below, edit /etc/gitlab/gitlab.rb
# and run `sudo gitlab-ctl reconfigure`.
production:
adapter: postgresql
encoding: utf8
collation:
database: gitlabhq_production
username: "gitlab"
password: "gitlab"
host: "192.168.1.200"
port: 54322After reconfiguring, GitLab should start successfully and be reachable at the configured URL.
DevOps Cloud Academy
Exploring industry DevOps practices and technical expertise.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.