This topic describes how to install GitLab on a Linux Elastic Compute Service (ECS) instance and use GitLab.
Prerequisites
An ECS instance is created and meets the following requirements:
IP address: The ECS instance is associated with a static public IP address (also called system-assigned or auto-assigned public IP address) or an elastic IP address (EIP). For information about how to associate an EIP with an ECS instance, see the Associate one or more EIPs with an instance section of the "Associate or disassociate an EIP" topic.
The instance type of the ECS instance is suitable for the size of your team and the expected workload. We recommend that you use an instance type that has at least 4 vCPUs and 8 GiB of memory. For more information, see Installation system requirements.
ImportantIf you use an instance type that has less than 4 vCPUs and 8 GiB of memory, GitLab installation will fail due to insufficient specifications. Upgrade the instance type before you install GitLab. For more information, see Overview of instance configuration changes.
Operating system: The ECS instance runs a Linux operating system. For information about the supported operating systems, see Supported operating systems.
An inbound rule is added to a security group of the ECS instance to open ports 80, 443, and 22. For more information, see Add a security group rule.
Install GitLab
Install JiHu GitLab on Alibaba Cloud Linux 3
If an ECS instance runs Alibaba Cloud Linux 3, you can use an installation package to install only JiHu GitLab on the instance.
To install GitLab Community Edition on an ECS instance that runs Alibaba Cloud Linux 3, use Docker Engine, which is operating system-agnostic.
To install GitLab Community Edition on an ECS instance that runs a different operating system, perform the operations that are described in the Install GitLab Community Edition on Ubuntu or Debian section of this topic.
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 python3-policycoreutils 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 configure 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 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 repository.
curl -fsSL https://get.gitlab.cn | sudo /bin/bash
NoteThe GitLab package repository may fail to be added due to network issues. If this issue occurs, we recommend that you re-add the GitLab package repository.
The following command output indicates that the GitLab package repository is added.
Install GitLab.
sudo EXTERNAL_URL=<Public IP address of the GitLab server> yum install -y gitlab-jh
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-jh
ImportantIf you install GitLab on an ECS instance of a low-specification instance type, the installation may remain in the Installing state for a long time or fail to install. We recommend that you upgrade the instance type to the one with at least 4 vCPUs and 8 GiB of memory before installation.
The following command output indicates that GitLab is installed.
Install GitLab Community Edition on Ubuntu or Debian
GitLab Community Edition does not support Alibaba Cloud Linux 3. This section describes how to install GitLab Community Edition on Ubuntu or Debian. For information about how to install GitLab Community Edition on other operating systems, see Install GitLab Community Edition.
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 apt-get update sudo apt-get install -y curl openssh-server ca-certificates tzdata perl
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 configure an external SMTP server after you install GitLab. For more information, see SMTP settings.
Install Postfix.
sudo apt-get install -y postfix
Start Postfix and configure Postfix to run on system startup.
sudo systemctl start postfix sudo systemctl enable postfix
Add the GitLab package repository.
sudo curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
NoteThe GitLab package repository may fail to be added due to network issues. If this issue occurs, we recommend that you re-add the GitLab package repository.
The following command output indicates that the GitLab package repository is added.
Refresh the software package list.
sudo apt-get update
Install GitLab.
sudo EXTERNAL_URL=<Public IP address of the GitLab server> apt-get 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 apt-get install -y gitlab-ce
ImportantIf you install GitLab on an ECS instance of a low-specification instance type, the installation may require an extended period of time to complete. During the installation, GitLab remains in the Installing state. Wait for the installation to complete.
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 Docker.
Create a directory to store GitLab data.
sudo mkdir -p /srv/gitlab
Configure the
$GITLAB_HOME
environment variable.export GITLAB_HOME=/srv/gitlab
Pull the GitLab image.
sudo docker pull gitlab/gitlab-ce
The following command output indicates that the GitLab image is pulled.
Install the GitLab container image.
Notehostname: the hostname. We recommend that you replace this parameter with the public IP address of the ECS instance.
publish 443:443: maps port 443 of the container to port 443 of the host to allow HTTPS access.
publish 8080:80: maps port 80 of the container to port 8080 of the host to allow HTTP access.
publish 5000:22: maps port 22 of the container to port 5000 of the host to allow the SSH service.
The inbound rules of the security groups of the ECS 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
This section describes how to use GitLab Community Edition. The procedure for using GitLab Community Edition is similar to the procedure for using JiHu GitLab.
Log on to GitLab
Obtain the password of GitLab.
If GitLab is installed by using a 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
.
The following command output 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 the path in which you want 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
.The following command output is returned.
View the content of the
id_rsa.pub
public key file. Copy the content for later use.cat .ssh/id_rsa.pub
The following command output 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 figure shows a page indicating 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.