Installing and Deploying GitLab Community Edition on Linux

Introduction to GitLab:

A very popular open-source project that supports self-hosting and provides a rich feature set, including CI/CD.

The GitLab Community Edition is open-source and free, allowing users to download and install it on their local servers.

Official Website:

https://packages.gitlab.com/gitlab/gitlab-ce

GitLab Download Links:

https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el9/

https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/9/gitlab-ce-17.7.2-ce.0.el9.x86_64.rpm/download.rpm

Upload the installation package

gitlab-ce-17.7.2-ce.0.el9.x86_64.rpm

to the server in the /opt directory

1. Preparation
1. Operating System: Rocky Linux-9.x
Rocky Linux 9.x system installation configuration tutorial
https://www.osyunwei.com/archives/14859.html
2. Disable SELinux
# Check if the grubby package is installed
rpm -q grubby
# Add selinux=0 to the kernel command line
grubby –update-kernel ALL –args selinux=0
# Restart the system
shutdown -r now
# Check the result should be Disabled
getenforce
3. Firewall configuration
The default port for GitLab is configured to be 80
Here we use iptables as the firewall
3.1 Stop the firewall
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl mask firewalld
systemctl stop firewalld
yum -y remove firewalld
3.2 Install iptables firewall and open the corresponding port
We use port 80
yum -y install iptables-services # Install
vi /etc/sysconfig/iptables
# Sample configuration for iptables service
# You can edit this manually or use system-config-firewall
# Please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state –state NEW -m tcp –dport 22 -j ACCEPT
-A INPUT -p tcp -m state –state NEW -m tcp –dport 80 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
:wq! # Save and exit
systemctl enable iptables.service # Set firewall to start on boot
systemctl restart iptables.service # Start the firewall to apply the configuration
4. Set the system time
rm -rf /etc/localtime # First delete the default timezone setting
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime # Replace Asia/Shanghai as the default timezone
vi /etc/sysconfig/clock # Add timezone
Zone=Asia/Shanghai
:wq! # Save and exit
timedatectl set-local-rtc 0
hwclock –systohc -u # Sync system clock and hardware clock, the current system timezone is not UTC, it’s CST time, so add -u parameter
date # Display system time
date -s “2025-01-15 15:24:00” # Modify time
watch -n 1 date # Display real-time time
vi /etc/chrony.conf
#pool 2.rocky.pool.ntp.org iburst # Commented out
server ntp.aliyun.com iburst # Added
:wq! # Save and exit
systemctl enable chronyd # Restart service
systemctl restart chronyd # Restart service
chronyc sources -v # View time synchronization information
5. System parameter optimization
vi /etc/security/limits.conf # Add the following code to the last line
* soft nproc unlimited
* hard nproc unlimited
* soft nofile 1000000
* hard nofile 1000000
:wq! # Save and exit
vi /etc/sysctl.conf # Add the following code to the last line
fs.file-max = 65535000
fs.nr_open = 65535000
kernel.pid_max=655350
vm.swappiness = 0
net.ipv4.ip_forward = 1
:wq! # Save and exit
/sbin/sysctl -p
ulimit -a # View
ulimit -n 1000000 # Set
2. Installation
1. Install GitLab
# Check if GitLab is currently installed
gitlab-ctl status
# Install dependencies
yum install policycoreutils-python-utils perl
# yum install policycoreutils-python perl # This command is used for rhel-7 series
cd /opt
rpm -ivh gitlab-ce-17.7.2-ce.0.el9.x86_64.rpm # Install
Installing and Deploying GitLab Community Edition on Linux
2. Modify the configuration file
mkdir -p /data/server/gitlab # Create a directory for GitLab data storage, default is /var/opt/gitlab
cp /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb.bak # Backup before modification
vi /etc/gitlab/gitlab.rb # Modify or add configuration information
external_url ‘http://192.168.21.190:80/’ # Set external URL
gitlab_rails[‘time_zone’] = ‘Asia/Shanghai’ # Set timezone
gitlab_rails[‘locale’] = ‘zh-CN’ # Set language
# Set data storage directory
git_data_dirs({
“default” => {
“path” => “/data/server/gitlab” # Set GitLab data storage directory
}
})
# Uncomment the following 3, reduce worker processes, minimum is 2
puma[‘worker_processes’] = 2
puma[‘min_threads’] = 2
puma[‘max_threads’] = 2
# SSH host IP
gitlab_rails[‘gitlab_ssh_host’] = ‘192.168.21.190’
# SSH port configuration
gitlab_rails[‘gitlab_shell_ssh_port’] = 22
# Email settings edit configuration file
# We use QQ email, smtp_password is the authorization code, not the email login password, pay special attention
gitlab_rails[‘smtp_enable’] = true
gitlab_rails[‘smtp_address’] = “smtp.qq.com”
gitlab_rails[‘smtp_port’] = 465
gitlab_rails[‘smtp_user_name’] = “[email protected]
gitlab_rails[‘smtp_password’] = “xxxxxxxxxx”
gitlab_rails[‘smtp_domain’] = “smtp.qq.com”
gitlab_rails[‘smtp_authentication’] = “login”
gitlab_rails[‘smtp_enable_starttls_auto’] = false
gitlab_rails[‘smtp_tls’] = true
gitlab_rails[‘gitlab_email_from’] = ‘[email protected]
:wq! # Save and exit
Installing and Deploying GitLab Community Edition on Linux
gitlab-ctl reconfigure # Reload configuration
# Enter console
gitlab-rails console
# Test sending email
Notify.test_email(‘recipient email’, ‘email title’, ‘email body’).deliver_now # Template
Notify.test_email(‘[email protected]’, ‘Test Email’, ‘This is a test email’).deliver_now
Installing and Deploying GitLab Community Edition on Linux
If you can receive the email, it means the configuration is successful
exit; # Exit console
gitlab-rake “gitlab:password:reset” # Change the password of the admin user root, fill in according to the prompt, the root user is built-in
root/3j+w0#mN
Installing and Deploying GitLab Community Edition on Linux
gitlab-rails console # Enter console
user = User.find_by(username: ‘root’) # Find user
user.email = ‘[email protected]’ # Modify email address
user.save! # Save
exit; # Exit console
# Make configuration file effective
gitlab-ctl reconfigure
# Set to start on boot
systemctl enable gitlab-runsvdir
# Stop
gitlab-ctl stop
# Start
gitlab-ctl start
# Restart
gitlab-ctl restart
3. Access GitLab
# Open in browser
http://192.168.21.190/
Installing and Deploying GitLab Community Edition on Linux
Enter username and password to log in
root/3j+w0#mN
Installing and Deploying GitLab Community Edition on Linux
# Set Chinese interface
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
Finally, refresh the page, and it is displayed in Chinese.
Continue to create a project
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
The default created project main branch is protected, now cancel the restriction.
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
This cancels the restriction
# Related commands
# View rpm package
rpm -qa | grep gitlab
# Uninstall GitLab
rpm -ev –nodeps `rpm -qa | grep gitlab`
# Delete directories and files
rm -rf /opt/gitlab /etc/gitlab /var/opt/gitlab /var/log/gitlab
# Related directory description
# Installation directory
/opt/gitlab
# Configuration file directory
/etc/gitlab
# Default data directory
/var/opt/gitlab
# Log directory
/var/log/gitlab
4. Use Git to commit and pull code
Install Git software: https://git-scm.com/downloads
Here we use the Windows client, just download and install it by default
Before committing and pulling code, you need to configure the SSH key
Right-click on the desktop – Open Git Bash here
4.1 Configure username
# osyunwei is your username, you can customize it, it will be displayed in the commit records
git config –global user.name ‘osyunwei’
4.2 Configure email
# Add your email address
git config –global user.email ‘[email protected]
git config –list # View configuration
# The information generated in the last two steps will create a .gitconfig configuration file in C:\Users\your_account, note that this file cannot be deleted, it records the account and email
4.3 Use Git to generate SSH key pair, press enter three times during command execution
ssh-keygen -t ed25519
4.4 In the C:\Users\username\.ssh directory, a .ssh folder will be generated, which contains the following two files
id_ed25519
id_ed25519.pub
Installing and Deploying GitLab Community Edition on Linux
You need to add the public key (id_ed25519.pub) in the folder to the GitLab management platform
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
Installing and Deploying GitLab Community Edition on Linux
As shown in the figure, add it
Now the SSH key has been added
4.5 Clone the remote repository to the local, then upload and pull code
Create a new directory D:\work, right-click on the work folder – Open Git Bash here
Clone the remote repository to the local
A folder named project will be created in the current directory, and the origin remote repository address will be automatically set
git clone ssh://[email protected]/group/project.git
Check the directory D:\work\project, there is already a README file
Create a test file in this directory, then upload the code
Right-click on the D:\work\project folder – Open Git Bash here
Link to the remote repository, since the code has been pulled before, the remote repository information already exists
Related commands
View existing remote repository information
git remote -v
Remove existing remote repository
git remote remove origin
# Add remote repository information
git remote add origin ssh://[email protected]/group/project.git
# Upload code to the repository
git add .
git commit -m 20250117
git fetch origin # Get the latest information from the remote repository
git push -uf origin main # Push code
git pull origin main # Pull the latest code from the remote repository
Installing and Deploying GitLab Community Edition on Linux
4.6 Create a new repository locally, initialize the repository, and upload and pull code
Create a new directory D:\newwork, create a test file in this directory, then right-click on the newwork folder – Open Git Bash here
git init # Initialize a new Git repository
git checkout -b main # Create and switch to the main branch
# Add remote repository address
git remote add origin ssh://[email protected]/group/project.git
git remote -v # View remote repository information
# Upload code to the repository
git add .
git commit -m 20250117new
git fetch origin # Get the latest information from the remote repository
git push -uf origin main # Push code
git pull origin main # Pull the latest code from the remote repository
git branch -m main # Rename local branch to main
Installing and Deploying GitLab Community Edition on Linux
Thus, the installation and deployment of GitLab Community Edition on Linux is complete.

Leave a Comment