GitLab is an open source Git repository management tool for version control, code review, issue tracking, and continuous integration. It provides an integrated development environment that allows team members to collaboratively develop and manage projects on one platform. This topic describes how to install GitLab on an ECS instance that runs CentOS 7.x or Alibaba Cloud Linux. This topic also describes how to use GitLab.
Prerequisites
This topic describes how to install GitLab. Before performing the installation operation, make sure that an Elastic Compute Service (ECS) instance that meets the following requirements has been created:
The instance is associated with an auto-assigned public IP address or an elastic IP address (EIP) For information about how to associate an EIP with an instance, see Associate or disassociate an EIP.
The instance is of an instance type that fits the scale of your team or your project. For a team of around 500 people, we recommend an instance type with at least 4 vCPU cores and 4 GiB of memory. For more information, see Installation system requirements.
Operating System:
Use the installation package for Linux to install GitLab on an instance that runs CentOS 7.x: CentOS 7.x is used in this example. For more information about how to install GitLab in operating systems such as Ubuntu, Debian, and AlmaLinux 8, see GitLab official documentation.
Use Docker Engine to install GitLab: We recommend that you use this method for operating systems such as Alibaba Cloud Linux 2 and Alibaba Cloud Linux 3 on which GitLab cannot be installed.
An inbound rule is added to a security group of the instance to open ports 80, 443, and 22. For more information, see Add security group rules.
Install GitLab
You can use one of the following methods to install GitLab. The following table describes the differences between these methods.
Item | Installation package for Linux | Docker Engine |
Installation method | Run the installation package on a Linux instance. | Run a GitLab container on Docker Engine. |
System dependency | You need to install and configure specific system runtime and dependencies based on the operating system version and configuration. | No dependencies are in the instance operating system where Docker resides. All dependencies are included in the Docker image. |
Flexibility and portability | You can customize the configurations based on your requirements with flexibility. However, more system administration and maintenance work may be required. | You can deploy and run GitLab containers in different environments with better portability and consistency. |
Version management | You need to manually manage and upgrade GitLab versions. You need to download updated installation packages and perform corresponding upgrade operations. | You can manage GitLab versions with ease by pulling updated Docker images and running the container again. |
System resource utilization | GitLab runs on an ECS instance and consumes a certain amount of system resources. | GitLab runs as a container which allows you to use system resources more efficiently. Containers are isolated from each other and do not affect ECS instances. |
Use the installation package for Linux to install GitLab on an instance that runs CentOS 7.x
Connect to the ECS instance on which you want to install GitLab.
For more information, see Connect to a Linux instance by using a password or key.
Install the dependencies that are required by GitLab.
sudo yum install -y curl policycoreutils-python openssh-server
Start the SSH service and configure the service to run on system startup.
sudo systemctl start sshd sudo systemctl enable sshd
(Optional) Install and configure Postfix.
Postfix is used to send notification emails from GitLab. If you want to use other methods to send notification emails, skip this step and set up an external simple mail transfer protocol (SMTP) server after you install GitLab. For more information, see SMTP settings.
Install Postfix.
sudo yum install -y postfix
If you receive error messages that are similar to the following error messages, run the
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
command and then re-install Postfix:Falling package is : mysql-community-libs-compat-5.7.41-1.el7.x86_64 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Start Postfix and configure Postfix to run on system startup.
sudo systemctl start postfix sudo systemctl enable postfix
Add the GitLab package registry.
sudo curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
NoteThe GitLab package registry may fail to be added due to network issues. If such a failure occurs, we recommend that you re-add the GitLab package registry.
The following command output indicates that the GitLab package registry is added.
Install GitLab.
sudo EXTERNAL_URL=<Public IP address of the GitLab server> yum install -y gitlab-ce
In the preceding command, replace
<Public IP address of the GitLab server>
with the public IP address of the ECS instance on which you want to install GitLab. Sample command:sudo EXTERNAL_URL=101.132.XX.XX yum install -y gitlab-ce
ImportantThe installation process may be prolonged due to lower instance types. Wait till the Installing state ends.
The following command output indicates that GitLab is installed.
Use Docker Engine to install GitLab
Connect to the ECS instance on which you want to install GitLab.
For more information, see Connect to a Linux instance by using a password or key.
Install Docker.
For more information, see Install and use Docker on a Linux instance.
Create a directory to which the Docker container mounts the volume.
sudo mkdir -p /srv/gitlab
Set environment variable
$GITLAB_HOME
.export GITLAB_HOME=/srv/gitlab
Run the following command to pull the GitLab image:
sudo docker pull gitlab/gitlab-ce
The following message indicates that the GitLab image is pulled.
Run the following command to install the GitLab container image:
Notehostname: the specified hostname. Change it to the IP address of the current ECS instance.
publish 443:443: maps the 443 port of the container to the 443 port of the host for accesses over HTTPS.
publish 8080:80: maps the 80 port of the container to the 8080 port of the host for accesses over HTTP.
publish 5000:22: maps the 22 port of the container to the 5000 port of the host for the SSH service.
The inbound rule of the security group of the instance must open ports 443, 8080, and 5000.
sudo docker run --detach \ --hostname gitlab.example.com \ --publish 443:443 --publish 8080:80 --publish 5000:22 \ --name gitlab \ --restart always \ --volume $GITLAB_HOME/config:/etc/gitlab \ --volume $GITLAB_HOME/logs:/var/log/gitlab \ --volume $GITLAB_HOME/data:/var/opt/gitlab \ --shm-size 256m \ gitlab/gitlab-ce:latest
View the container status.
sudo docker ps -a
If the container is in the healthy state, the GitLab container is started.
Use GitLab
Log on to GitLab
Obtain the password of GitLab.
If GitLab is installed by using the Linux installation package, run the following command:
sudo cat /etc/gitlab/initial_root_password
If GitLab is installed by using Docker Engine, run the following command:
sudo docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
A command output similar to the following one is returned. Obtain the initial password of GitLab from the value of
Password
.ImportantFor security purposes, the file will be automatically deleted in 24 hours. We recommend that you change the initial password the first time you log on.
Log on to GitLab.
If GitLab is installed by using the Linux installation package, enter http://The public IP address of the ECS instance in the browser address bar to go to the GitLab logon page.
If GitLab is installed by using Docker Engine, enter http://The public IP address of the ECS instance:8080 in the browser address bar to go to the GitLab logon page.
The first time you log on to GitLab, use the
root
username and the password that is obtained in step 1.
Generate a key pair file and obtain the public key
Install Git.
sudo yum install git
Generate a key pair file named
id_rsa
.ssh-keygen
When the key pair file is being generated, you are prompted to specify a password and a path to store the key pair file. You can specify a path or press the Enter key to use the default
.ssh/id_rsa
path in the current user directory. Example:/home/test/.ssh/id_rsa
.A command output similar to the following one is returned.
View the content of the
id_rsa.pub
public key file. Copy the content for later use.cat .ssh/id_rsa.pub
A command output similar to the following one is returned.
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQVwWjF3KXmI549jDI0fuCgl+syJjjn55iMUDRRiCd/B+9TwUda3l9WXH5i7RU53QGRCsDVFZxixLOlmXr9E3VSqkf8xXBnHs/5E2z5PIOCN0nxfB9xeA1db/QxPwK4gkHisep+eNHRn9x+DpCYDoSoYQN0nBg+H3uqfOqL42mJ+tqSfkyqbhjBf1kjtDTlBfVCWtI0siu7owm+c65+8KNyPlj5/0AyJ4Aqk1OX2jv+YE4nTipucn7rHwWuowasPU86l+uBsLNwOSb+H7loJvQyhEINX2FS1KnpRU+ld20t07n+N3ErfX5xBAGfxXpoN9BKKSP+RT7rvTeXTVE**** test@iZuf63zs0dn0qccsisy****
Create a project
On the GitLab homepage, click Create new project to create a project.
Click Create blank project, set Project name and Project URL, and then click Create project.
In this example, a project named mywork is created.
Add an SSH key.
On the Project overview page of the project that you created, click Add SSH key.
Paste the content of the
id_rsa.pub
public key file to theKey
field.Click Add key.
The following page shows that the SSH key is added.
Copy the clone link of the project. You can use the link to clone the project.
Use GitLab
Configure a Git user.
Specify a username for the Git user.
git config --global user.name "testname"
Specify an email address for the Git user.
git config --global user.email "abc@example.com"
Clone the project to an on-premises directory.
git clone git@101.132.XX.XX:root/mywork.git
Upload a file to the GitLab server.
Access the on-premises project directory.
cd mywork/
Create a file that you want to upload to GitLab.
echo "test" > /home/test/test.sh
Copy the file or directory to the on-premises project directory.
cp /home/test/test.sh ./
Add the
test.sh
file to the index.git add test.sh
Commit the
test.sh
file to the on-premises repository.git commit -m "test.sh"
Push the file to the GitLab server.
git push -u origin main
The following page shows that the
test.sh
file is pushed to the GitLab server. You can view the file on the page.
References
For more information about GitLab operations, such as common GitLab commands, data backup, configuration options, user management, integration with other services, and troubleshooting, see GitLab official documentation.