Operations 11 min read

Step-by-Step Guide to Install and Configure GitLab on CentOS and Docker

This article provides a comprehensive, hands‑on tutorial for installing GitLab on a CentOS 7 server and via Docker, covering prerequisite setup, dependency installation, repository configuration, SSL handling, service startup, first‑login procedures, and common troubleshooting tips.

Ops Development Stories
Ops Development Stories
Ops Development Stories
Step-by-Step Guide to Install and Configure GitLab on CentOS and Docker

1. Preparation

Use a CentOS 7 machine with at least 4 GB RAM (recommended 4 CPU × 8 GB). Example system: CentOS Linux release 7.3.1611 (Core), GitLab CE version 11.10.1.

2. Install Dependency Packages

# sudo yum install -y git vim gcc glibc-static telnet
# sudo yum install -y curl policycoreutils-python openssh-server
# sudo systemctl enable sshd && sudo systemctl start sshd
# sudo yum install -y postfix && sudo systemctl enable postfix && sudo systemctl start postfix
# sudo systemctl stop firewalld && sudo systemctl disable firewalld
# sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
# setenforce 0

3. Configure GitLab Repository

# vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
# yum makecache

4. Install GitLab

# yum install -y gitlab-ce
# yum install -y gitlab-ce-{VERSION}   # install a specific version

5. Configure GitLab

Edit /etc/gitlab/gitlab.rb and set the following key sections:

# Basic configuration
external_url 'http://gitlab.example.com/'
gitlab_rails['time_zone'] = 'Asia/Shanghai'

# SSH configuration
gitlab_rails['gitlab_shell_ssh_port'] = 10222

# Email (SMTP) configuration
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "xxx"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]'

# Nginx (Web) configuration
nginx['enable'] = true
nginx['client_max_body_size'] = '250m'
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.xxx.cn.pem"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.xxx.cn.key"
nginx['ssl_protocols'] = "TLSv1.1 TLSv1.2"
nginx['ssl_session_cache'] = "builtin:1000  shared:SSL:10m"
nginx['ssl_session_timeout'] = "5m"
nginx['listen_addresses'] = ['*', '[::]']
nginx['gzip_enabled'] = true

6. Upload SSL Certificates

# ll /etc/gitlab/ssl/
# -rw-r--r-- 1 root root 1675 gitlab.xxx.cn.key
# -rw-r--r-- 1 root root 3671 gitlab.xxx.cn.pem

7. Reconfigure GitLab

# systemctl restart gitlab-runsvdir
# gitlab-ctl reconfigure

8. Start Services

# gitlab-ctl restart
# gitlab-ctl status

9. Test Email Sending

# gitlab-rails console
irb(main):001:0> Notify.test_email('[email protected]', 'Test Title', 'Test Content').deliver_now
irb(main):002:0> exit

10. First Login

Add gitlab.example.com to /etc/hosts, then open the URL in a browser, set the initial root password, and log in.

GitLab login screen
GitLab login screen
GitLab dashboard
GitLab dashboard

11. Disable User Registration

To prevent arbitrary registrations, turn off the sign‑up feature in the admin settings.

Disable registration
Disable registration
Registration settings
Registration settings

12. Set Language to Simplified Chinese

Save the setting and restart the login page to apply.

Language selection
Language selection

Docker Deployment of GitLab

1. Environment Description

Environment

Version

centos

7

docker

1.13.1

gitlab/gitlab-ce

latest

2. Disable SELinux for Containers

# vi /etc/selinux/config
# SELINUX=enforcing   # comment out
# SELINUXTYPE=targeted # comment out
SELINUX=disabled      # add this line
:wq!
# setenforce 0   # apply immediately

3. Pull GitLab Image

# docker search gitlab
# sudo docker pull gitlab/gitlab-ce:latest

4. Create Docker Network

# docker network create gitlab_net

5. Run GitLab Container with Persistent Volumes

# docker run --name='gitlab' -d \
  --net=gitlab_net \
  --publish 443:443 --publish 80:80 \
  --restart always \
  --volume ~/docker/gitlab/config:/etc/gitlab \
  --volume ~/docker/gitlab/logs:/var/log/gitlab \
  --volume ~/docker/gitlab/data:/var/opt/gitlab \
  --privileged=true \
  gitlab/gitlab-ce:latest
# docker ps | grep gitlab   # verify container is running

6. Modify Configuration Inside Container

# vim ~/docker/gitlab/config/gitlab.rb
... 
external_url 'http://gitlab.example.com/'
...

7. Access the Service

Open http://gitlab.example.com/ in a browser, set the initial root password, and log in.

GitLab Docker login
GitLab Docker login

Common Issues

Browser access denied – check docker logs gitlab for errors.

502 error – likely port conflict; adjust unicorn['port'] in gitlab.rb and restart.

Slow access – the image is >1 GB; initial start takes time.

Persistent 502 – monitor CPU and memory usage; resource exhaustion can cause failures.

Future article will cover GitLab‑CI Runner installation.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerDevOpsGitLabInstallationCentOS
Ops Development Stories
Written by

Ops Development Stories

Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.