Setting Up a Private GitLab Instance on CentOS 7
This guide outlines the steps to deploy a private GitLab instance on a CentOS 7 system.
Prerequisites
Install required dependencies:
sudo yum install curl policycoreutils openssh-server openssh-client
sudo systemctl enable sshd
sudo systemctl start sshd
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
Installation
Method 1: Install via YUM Repository
sudo yum install -y gitlab-ce
Method 2: Install Specific Version
Download the desired version from the mirror site:
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
Install the downloaded RPM package:
rpm -i gitlab-ce-11.6.3-ce.0.el7.x86_64.rpm
If you encounter an error related to policycoreutils-python, install it:
sudo yum -y install policycoreutils-python
Configuration
Edit the GitLab configuration file:
vim /etc/gitlab/gitlab.rb
Locate the external_url setting and update it with your domain or IP address and port.
Apply the configuration changes:
sudo gitlab-ctl reconfigure
This process may take several minutes. A successful configuration is indicated by completion messages.
Starting GitLab
Start the GitLab services:
sudo gitlab-ctl start
Common GitLab Commands
# Remove all GitLab-related files
find / -name gitlab | xargs rm -rf
# Start all GitLab components
sudo gitlab-ctl start
# Stop all GitLab components
sudo gitlab-ctl stop
# Restart all GitLab components
sudo gitlab-ctl restart
# Check service status
sudo gitlab-ctl status
# View logs
sudo gitlab-ctl tail
# View logs for a specific service
sudo gitlab-ctl tail <service_name>
After starting GitLab, access it via you're configured IP address and port.
Accessing the Administrator Account
Default Root Password
View the initial root password:
vi /etc/gitlab/initial_root_password
Creating an Administrator Account
If the initial password file is unavailable, create an administrator account via the Rails console:
sudo gitlab-rails console
Execute the following commands in the console:
admin_user = User.new(email: 'admin@example.com', username: 'admin_user', name: 'Administrator', password: 'secure_password')
admin_user.skip_confirmation!
admin_user.save!
# Assign administrator role
admin_user.add_role(:admin)
# Exit the console
quit
Migration Considerations
For migration purposes, note the following:
- Ensure GitLab versions are consistent.
- Key data directories:
- Project repository path:
/var/opt/gitlab/git-data/repositories - PostgreSQL data path:
/var/opt/gitlab/postgresql/data
- Project repository path:
Set appropriate permissions for these directories:
sudo chown -R git:root /var/opt/gitlab/git-data/repositories
sudo chmod -R 0700 /var/opt/gitlab/git-data/repositories
sudo chown -R gitlab-psql:gitlab-psql /var/opt/gitlab/postgresql/data
sudo chmod -R 0700 /var/opt/gitlab/postgresql/data