GitLab is a self-managed Git project repository that was developed by Ruby and provides a web interface for access to public or private projects. This topic describes how to deploy and use GitLab on an Elastic Compute Service (ECS) instance.
Prerequisites
An ECS instance that meets the following requirements is 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 runs a CentOS 7.x operating system.
The instance type has at least four vCPUs and 4 GiB of memory.
An inbound rule is added to a security group of the instance to open port 80. For more information, see Add a security group rule.
Deploy a GitLab environment
Connect to the ECS instance.
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
The following command output indicates that GitLab is installed.
Use GitLab
Log on to GitLab
Obtain the password of GitLab.
sudo cat /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.
In the address bar of your browser, enter public IP address of the ECS instance on which GitLab is installed to access the GitLab logon page. The first time you log on, enter the
root
username and the password that you 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.
On the Create new project page, click Create blank project. On the Create blank project page, configure parameters.
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/test.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.