Installing and Configuring GitLab on CentOS 7: A Complete Guide

Understanding GitLab

GitLab is an open-source version management system built with Ruby on Rails. It provides a self-hosted Git repository solution that integrates code托管, testing, and deployment capabilities. Through its web interface, you can access both public and private projects. Similar to GitHub, GitLab enables code browsing, issue tracking, and comment management. It offers robust access control for team repositories, comprehensive commit history visualization, and a code snippet collection feature that facilitates code reuse and future retrieval.

To clarify the Git ecosystem:

  • Git is a distributed version control system and command-line tool
  • Gitlib is a development library implementing Git functionality
  • GitHub is a web-based code hosting service using Git, offering both free public repositories and paid private options
  • GitLab is self-hosted Git repository software that lets you deploy your own GitHub-like infrastructure

GitLab has specific hardware requirements. A single CPU core can support approximately 100 users, though running the web interface alongside background jobs may strain resources. A minimum of 4GB RAM is essential for installation and operation, accounting for the operating system and other running applications. Systems with less memory experience configuration errors during reconfiguration. For evaluation purposes, virtual machines with 1GB or 2GB memory prove inadequate.

Enstalling GitLab on CentOS 7

Preparing the Environment

Begin by configuring the firewall to allow HTTP and SSH access:

sudo yum install curl policycoreutils openssh-server openssh-clients
sudo systemctl enable sshd
sudo systemctl start sshd
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld

Adding the Repository and Installing

The official Yum repository provides straightforward installation, though download speeds may be slow. For faster access in China, consider using a domestic mirror:

sudo vim /etc/yum.repos.d/gitlab-ce.repo

Configure the mirror source with the following content:

[gitlab-ce]
name=GitLab CE Repository
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key

Proceed with installation and initial configuration:

sudo yum install gitlab-ce
sudo gitlab-ctl reconfigure

Initial Configuration

Upon first access, the system redirects to a password reset page. The default administrator username is root, with the initial password set to 5iveL!fe. After resetting, your new password becomes active.

Chinese Localization

For teams preferring Chinese interface, GitLab offers community-maintained translations. The Chinese localization project originated with Larry Li (covering versions 7.x through 8.8.x) and is now maintained by xhang starting from version 8.9.

Prepare the localization environment:

mkdir -p /tmp/localization
cd /tmp/localization
git clone https://gitlab.com/xhang/gitlab.git

If Gits not installed:

sudo yum install git -y

For specific versions, specify the corresponding branch. To download the localization for version 10.0.2:

git clone https://gitlab.com/xhang/gitlab.git -b v10.0.2-zh

Stop GitLab services before applying the localization:

sudo gitlab-ctl stop
sudo cp -r /tmp/localization/* /opt/gitlab/embedded/service/gitlab-rails/

If prompted about overwriting files during copying, this occurs because cp has an alias for interactive mode. To bypass this, comment out the alias in your shell profile:

vim ~/.bashrc
# Comment out: alias cp='cp-i'
source ~/.bashrc

Apply the changes and restart services:

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

GitLab Command Reference

The gitlab-ctl utility manages all GitLab services. The general syntax follows:

gitlab-ctl command [subcommand]

Service Management

Command Description
start Launch all services
stop Stop all services
restart Restart all services
status Display service status for all components
tail Stream log output in real-time
service-list Enumerate all running services
graceful-kill Gracefully terminate a specific service

Operational Examples

# Start all GitLab services
sudo gitlab-ctl start

# Start a specific service (nginx)
sudo gitlab-ctl start nginx

# Monitor all logs in real-time
sudo gitlab-ctl tail

# Follow a particular service log
sudo gitlab-ctl tail nginx

General Administration

Command Description
help Display command documentation
reconfigure Apply configuration changes
show-config Reveal all service configuration files
uninstall Remove GitLab installation
cleanse Delete all data for a fresh installation
# View complete configuration
sudo gitlab-ctl show-config

# Remove GitLab from the system
sudo gitlab-ctl uninstall

Email Configuration with QQ Mail

By default, GitLab cannot send confirmation emails through standard QQ mail accounts. Enterprise QQ mail accounts (exmail.qq.com) work reliably, while personal accounts may encounter issues.

Edit the GitLab configuration file:

sudo vim /etc/gitlab/gitlab.rb

Configure SMTP settings for QQ enterprise mail:

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "your-email@example.com"
gitlab_rails['smtp_password'] = "your-email-password"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'your-email@example.com'

After saving the configuration, apply the changes:

sudo gitlab-ctl reconfigure

When configuring email services for any software, always prioritize official documentation as third-party guides may contain outdated or incorrect information.

Tags: gitlab centos devops Version Control Installation Guide

Posted on Mon, 18 May 2026 21:30:56 +0000 by Shawnaize