Deploy GitLab
Deploying GitLab on an ECS instance gives you a self-managed code hosting and CI/CD platform with private access and on-premises data storage. You can deploy GitLab on a Linux ECS instance by using an installation package, a Docker image, or an ECS extension.
Prerequisites
The ECS instance must meet the following requirements:
-
Instance type: A minimum of 4 vCPUs and 8 GiB of memory is recommended, depending on your project and team size. For more information, see Installation system requirements and Running GitLab in a memory-constrained environment.
ImportantAn instance with less than 4 vCPUs and 8 GiB of memory may hang during installation or fail. Upgrade the instance type before you start the installation. For more information, see Configuration change overview.
-
Operating system: Linux. For a list of supported distributions, see Supported OSes.
-
A public IP address is automatically assigned to the ECS instance. Alternatively, an elastic IP address (EIP) is associated with the ECS instance. For instructions on how to enable public bandwidth, see Enable public bandwidth.
-
Security group: Configure an inbound rule to allow traffic on ports 80, 443, and 22. For instructions, see Add a security group rule.
Install GitLab
GitLab is available in Enterprise Edition (EE) and Community Edition (CE). JiHu GitLab is an enterprise-grade version distributed in the Chinese mainland, Hong Kong (China), and Macao (China), with servers located within China for faster access. For a detailed version comparison, see JiHu GitLab installation and version comparison.
Installation package
For users in the Chinese mainland, JiHu GitLab is recommended for faster download and access speeds. Choose GitLab Community Edition when you need to collaborate with teams outside of China or require full consistency with the GitLab Community Edition codebase and documentation.
JiHu GitLab
For a list of operating systems supported by JiHu GitLab, see supported_os.
Alibaba Cloud Linux 3
-
Download the latest RPM installation package to a local temporary directory. The command dynamically reads the current primary.xml.gz filename from
repomd.xml(the hash in this filename changes with each repository reindex), and then parses the relative path of the latest RPM and downloads it.cd /tmp && \ ARCH=$(uname -m) && \ PRIMARY=$(curl -s https://packages.gitlab.cn/repository/el/8/repodata/repomd.xml \ | grep -oE "[a-f0-9]{64}-primary\.xml\.gz" | head -1) && \ URL=$(curl -s "https://packages.gitlab.cn/repository/el/8/repodata/${PRIMARY}" \ | gunzip \ | grep -oE "href=\"[^\"]*gitlab-jh[^\"]*${ARCH}\.rpm\"" \ | sed 's/href="//;s/"$//' \ | sort -V \ | tail -1) && \ wget -c "https://packages.gitlab.cn/repository/el/8/${URL}" -
Install the RPM package downloaded in the previous step. The command uses a glob wildcard to match the downloaded version, preventing a version mismatch. The output
Complete!indicates that the RPM installation is successful.RPM=$(ls /tmp/gitlab-jh-*.x86_64.rpm | sort -V | tail -1) && \ sudo yum localinstall -y --disablerepo=gitlab-jh "$RPM" && rm -f "$RPM"The --disablerepo=gitlab-jh parameter prevents `yum` from refreshing the metadata of the `gitlab-jh` remote repository when you install a local RPM package. This avoids an Out of Memory (OOM) error, which can be triggered by an exception during repository metadata parsing and cause the installation to fail. -
Configure the external access URL and start GitLab.
Replace
ECS_PUBLIC_IPwith the public IP address of the ECS instance.sudo EXTERNAL_URL="http://ECS_PUBLIC_IP" gitlab-ctl reconfigureThe initial run takes about 5 to 10 minutes to complete.
-
Verify the service status.
sudo gitlab-ctl statusThe output shows that processes such as puma, sidekiq, nginx, postgresql, redis, and prometheus are all in the
runstate, which indicates that GitLab has started successfully.
Alibaba Cloud Linux 4
-
Create the repository file.
sudo tee /etc/yum.repos.d/gitlab-jh.repo > /dev/null << 'EOF' [gitlab-jh] name=JiHu GitLab baseurl=https://packages.gitlab.cn/repository/el/9/ gpgcheck=1 gpgkey=https://packages.gitlab.cn/repository/raw/gpg/public.gpg.key priority=1 enabled=1 EOF -
Install GitLab. A
Complete!message at the end of the output indicates that the installation is successful.sudo yum install -y gitlab-jh -
Configure the external access URL and start GitLab.
Replace
ECS_PUBLIC_IPwith the public IP address of the ECS instance.sudo EXTERNAL_URL="http://ECS_PUBLIC_IP" gitlab-ctl reconfigureThe initial run takes about 5 to 10 minutes to complete.
-
Verify the service status.
sudo gitlab-ctl statusThe output shows that the puma, sidekiq, nginx, postgresql, redis, and prometheus processes are all in the
runstate, indicating that GitLab has started successfully.
CentOS 7.x
-
Install the required dependencies.
sudo yum install -y curl policycoreutils-python openssh-server -
Add the GitLab package repository.
curl -fsSL https://get.gitlab.cn | sudo /bin/bashThis step may fail due to network issues. If it does, try again.
When the output contains the keyword
Successfully added gitlab-jh repo, the GitLab package repository is installed. -
Install and start GitLab.
Replace
ECS_PUBLIC_IPwith the public IP address of the instance where GitLab is installed and run the following:sudo EXTERNAL_URL="http://ECS_PUBLIC_IP" yum install -y gitlab-jhThe initial run takes about 5 to 10 minutes to complete.
-
Verify the service status.
sudo gitlab-ctl statusThe output shows that processes such as puma, sidekiq, nginx, postgresql, redis, and prometheus are all in the
runstate, which indicates that GitLab has started successfully.
Ubuntu
-
Install the required dependencies.
sudo apt-get update sudo apt-get install -y curl openssh-server ca-certificates tzdata perl -
Configure the software source mirror for JiHu GitLab.
curl -L get.gitlab.cn | bashIf the output contains
Successfully added gitlab-jh repo, the GitLab software package repository is installed. -
Install and start GitLab.
Replace
ECS_PUBLIC_IPwith the public IP address of your GitLab instance.sudo EXTERNAL_URL="http://ECS_PUBLIC_IP" apt-get install -y gitlab-jh -
Verify the service status.
sudo gitlab-ctl statusThe output shows that processes such as puma, sidekiq, nginx, postgresql, and redis are all in the
runstatus. This indicates that GitLab has started successfully.
GitLab Community Edition
ECS extension
An ECS extension is a plug-in that extends the functionality of ECS instances. It installs JiHu GitLab by default on Alibaba Cloud Linux 3 and GitLab Community Edition on other supported systems.
-
Log on to the ECS console and go to the Extensions tab of the target instance.
-
Find the GitLab extension in the list and complete the installation. For detailed steps, see OOS extension. The supported OS versions are subject to what is displayed in the console.
Supported OS versions currently include Ubuntu 24.04, Ubuntu 22.04, Ubuntu 20.04, CentOS 7.9, CentOS 7.8, CentOS 7.7, and Alibaba Cloud Linux 3.2. Note that Alibaba Cloud Linux 3.2 uses JiHu GitLab. To install the extension, go to the Server Management > Extensions page from the left-side navigation pane. Click GitLab to view its details, and then click Install Extension.
-
After the extension status changes to successful, remotely connect to the ECS instance and run the following command to check the GitLab service status.
sudo gitlab-ctl statusA
runstatus for processes such as puma, sidekiq, nginx, postgresql, and redis indicates that GitLab has started successfully.
Docker image
-
Docker Compose is not required.
-
Create mount directories on the host. These directories persist GitLab configuration files, logs, and data outside the container.
sudo mkdir -p /srv/gitlab -
Set the environment variable
$GITLAB_HOME.export GITLAB_HOME=/srv/gitlab -
Run the following command to start the GitLab container.
ImportantPulling images from Docker Hub can be slow or fail due to network issues. You can use the official image accelerator provided by Alibaba Cloud Container Registry (ACR) to speed up downloads. For instructions, see Accelerate the download of official images.
GitLab Community Edition
sudo docker run --detach \ --hostname gitlab.example.com \ --publish 443:443 --publish 80:80 --publish 2222: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:latestParameter
Description
hostname
The hostname for the container. Set this to the public IP address of your ECS instance.
publish 443:443
Map port 443 of the host to port 443 of the container for HTTPS access. If the host port is already in use, replace it with a non-standard port, such as
publish 8443:443.NoteIf you switch to a non-standard port, you must add an inbound security group rule to allow traffic on that port (for example, 8443). For more information, see Add a security group rule. Security group rules are stateful, so you only need to configure an inbound rule. The system automatically allows the corresponding outbound response traffic.
publish 80:80
Map port 80 on the host to port 80 in the container for HTTP access. If the host port is already in use, replace it with a non-standard port, such as
publish 8080:80.NoteIf you switch to a non-standard port, you must add an inbound security group rule to allow traffic on that port (for example, 8080). For more information, see Add a security group rule. Security group rules are stateful, so you only need to configure an inbound rule. The system automatically allows the corresponding outbound response traffic.
publish 2222:22
Maps host port 2222 to container port 22 for SSH-based Git clone, push, and pull operations.
Note-
The SSH service starts by default on an ECS instance and uses port 22.
-
If you switch to a non-standard port like 2222, you must first add an inbound rule to the security group to allow traffic on that port, and then modify the SSH port number in the
gitlab.rbfile.
The following table shows the mapping between host paths and container paths.
ECS path
Container path
Description
$GITLAB_HOME/data/var/opt/gitlabStores application data.
$GITLAB_HOME/logs/var/log/gitlabStores GitLab log files.
$GITLAB_HOME/config/etc/gitlabStores GitLab configuration files.
JiHu GitLab
sudo docker run --detach \ --hostname gitlab.example.com \ --publish 443:443 --publish 80:80 --publish 2222: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 \ registry.gitlab.cn/omnibus/gitlab-jh:latestParameter
Description
hostname
The hostname for the container. Set this to the public IP address of your ECS instance.
publish 443:443
Map port 443 of the host to port 443 of the container for HTTPS access. If the host port is already in use, replace it with a non-standard port, such as
publish 8443:443.NoteIf you switch to a non-standard port, you must add an inbound security group rule to allow traffic on that port (for example, 8443). For more information, see Add a security group rule. Security group rules are stateful, so you only need to configure an inbound rule. The system automatically allows the corresponding outbound response traffic.
publish 80:80
Map port 80 on the host to port 80 in the container for HTTP access. If the host port is already in use, replace it with a non-standard port, such as
publish 8080:80.NoteIf you switch to a non-standard port, you must add an inbound security group rule to allow traffic on that port (for example, 8080). For more information, see Add a security group rule. Security group rules are stateful, so you only need to configure an inbound rule. The system automatically allows the corresponding outbound response traffic.
publish 2222:22
Maps host port 2222 to container port 22 for SSH-based Git clone, push, and pull operations.
Note-
The SSH service starts by default on an ECS instance and uses port 22.
-
If you switch to a non-standard port like 2222, you must first add an inbound rule to the security group to allow traffic on that port, and then modify the SSH port number in the
gitlab.rbfile.
The following table shows the mapping between host paths and container paths.
ECS path
Container path
Description
$GITLAB_HOME/data/var/opt/gitlabStores application data.
$GITLAB_HOME/logs/var/log/gitlabStores GitLab log files.
$GITLAB_HOME/config/etc/gitlabStores GitLab configuration files.
-
-
Check the container status.
sudo docker ps -aA
(healthy)status in the STATUS column indicates that the GitLab container is running normally.[ecs-user@iZ2zeee22a96g ~]$ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 75b3bc5de483 gitlab/gitlab-ce:latest "/assets/wrapper" 2 hours ago Up 2 hours (healthy) 0.0.0.0:443->443/tcp, :::443->443/tcp, 0.0.0.0:5000->22/tcp, :::5000->22/tcp, 0.0.0.0:8080->80/tcp, :::8080->80/tcp gitlabFor a more thorough check, inspect the GitLab processes inside the container:
sudo docker exec gitlab gitlab-ctl statusProcesses such as puma, sidekiq, nginx, postgresql, and redis should all be in the
runstate, indicating that GitLab inside the container is running.
Access the GitLab admin page
-
Enter the following URL in your browser:
http://${ECS public IP address}.ImportantIf you installed GitLab using a Docker image and mapped the default HTTP port 80 to a non-standard port, append the new port number to the URL.
-
For your first login, use the username
rootand obtain the password as follows.On your ECS instance, run the command for your installation method:
-
Linux installation package:
sudo cat /etc/gitlab/initial_root_password -
Docker installation:
sudo docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
The output is similar to the following. The value after the
Passwordfield is the initial login password for GitLab.[test@iZuf63zs0dn0cxxx ~]$ sudo cat /etc/gitlab/initial_root_password # WARNING: This value is valid only in the following conditions # 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`), it was provided before database was seeded for the first time (usually, the first reconfigure run). # 2. Password hasn't been changed manually, either via UI or via command line. # # If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password. Password: nB9P+4UUY2yx8Gp3BYgwQpKSfdo4wh11DpQH_ # NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.ImportantFor security reasons, this file is automatically deleted after 24 hours. Change the initial password immediately after your first sign-in. For instructions, see reset_user_password.
-
-
Go to the Admin page.
At the top of the page, click Menu and select Admin.
-
On the Users>Pending approval page, approve new user sign-up requests. For details on managing projects and users, see admin_area.
This example shows how to upload a file to a GitLab repository. For more information about GitLab operations such as common commands, data backup, configuration, user management, service integration, and troubleshooting, see the documentation for JiHu GitLab and GitLab Community Edition.
Register a user and set up passwordless access
-
Go to the GitLab page. Click Register now under the Sign in button to create a new user. After a GitLab administrator approves your request, sign in to GitLab with the new account.
-
Generate a key pair on your local machine:
ssh-keygenThe command prompts you to enter a directory to save the key pair (the default is
.ssh/id_rsain your home directory, for example,/home/test/.ssh/id_rsa) and a passphrase. You can enter custom values or press Enter to accept the defaults.The output is similar to the following:
[test@iZuf63zs0dn0qxxx : ~]$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/test/.ssh/id_rsa): Created directory '/home/test/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/test/.ssh/id_rsa. Your public key has been saved in /home/test/.ssh/id_rsa.pub. The key fingerprint is: SHA256:c8wCYK16ByqC8jEWaL9G/2gkWVe3lQUaens xxx test@iZuf63zs0dn0xxx The key's randomart image is: +---[RSA 2048]----+ | o. .+o.| | . .. ...0+.. | | . . ...oo.+ .| |... o. o o..oE.o | |o .+o.. S +..oo | |= *=... + .+ | |o+.+=. . | | .o o. | | .... | +----[SHA256]-----+ -
View and copy the contents of the
id_rsa.pubpublic key file.cat ~/.ssh/id_rsa.pubThe output is similar to the following:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQVwWjF3KXmI549jDI0fuCgl+syJjjn55iMUDRRiCd/B+9TwUda3l9WXH5i7RU53QGRCsDVFZxixLOlmXr9E3VSqkf8xXBnHs/5E2z5PIOCN0nxfB9xeA1db/QxPwK4gkHisep+eNHRn9x+DpCYDoSoYQN0nBg+H3uqfOqL42mJ+tqSfkyqbhjBf1kjtDTlBfVCWtI0siu7owm+c65+8KNyPlj5/0AyJ4Aqk1OX2jv+YE4nTipucn7rHwWuowasPU86l+uBsLNwOSb+H7loJvQyhEINX2FS1KnpRU+ld20t07n+N3ErfX5xBAGfxXpoN9BKKSP+RT7rvTeXTVE**** test@iZuf63zs0dn0qccsisy**** -
Add the public key to your GitLab account as an SSH key to enable passwordless access.
-
Click your profile picture in the upper-right corner, and then click Profile.
In earlier versions of GitLab, this menu item was named Edit profile.
-
In the left navigation bar, click SSH Keys. Paste the content of the public key file
id_rsa.pubinto theKeytext box, and then click Add key. -
After you add the SSH key, the page displays key details including its content, fingerprint (MD5 and SHA256), and metadata such as creation and expiration dates.
-
Create a project and host code
Create a new project
-
On the GitLab home page, click the New Project button on the right, and then click Create blank project.
-
On the Create blank project page, set the Project name and Project URL, and then click the Create project button at the bottom of the page. This example uses a project named mywork.
-
Return to the project page and copy the SSH clone URL. You will need this URL to clone the repository.
ImportantThe SSH clone URL on the project page uses
gitlab.example.comas the default host (the built-in default hostname in GitLab). Cloning directly will fail due to a DNS resolution error. Before you clone, manually replace the host with the public IP of your ECS instance or a custom domain.To make the project page display the correct host, configure
gitlab_rails['gitlab_shell_ssh_host']in/etc/gitlab/gitlab.rband then runsudo gitlab-ctl reconfigure. For more information, see Configuring the external URL for GitLab.
Clone the remote repository
-
Install Git on your local machine:
sudo yum install git -
Configure your local Git identity:
-
Set your Git username:
git config --global user.name "testname" -
Set your Git email address:
git config --global user.email "abc@example.com"
-
-
Clone the project to your local machine.
-
Run
git clonewith the SSH clone URL. Git automatically creates a directory named after the repository and downloads its contents.git clone ${SSH URL}If you installed GitLab using a Docker image, prepend the
ssh://prefix to the URL and specify the port mapped in thedocker runcommand. For example:ImportantTo avoid modifying the SSH URL, modify the
gitlab_rails['gitlab_shell_ssh_port']parameter so that the GitLab page displays the correct port. For more information, see What do I do if port 22 is already in use when I use Docker to start GitLab?.git clone ssh://git@{IP_address_or_domain_name}:{SSH_port}/root/mywork[ecs-user@iZ2zefuyca xxx ~]$ git clone git@59.xxx.xxx.xxx:root/mywork.git Cloning into 'mywork'... The authenticity of host '59.xxx.xxx.xxx (59.xxx.xxx.xxx)' can't be established. ECDSA key fingerprint is SHA256:I4eX9gjdR2dwOBmI5xerO+dTnJOZ/xxx. ECDSA key fingerprint is MD5:18:54:b5:be:b2:6d:e9:25:c1:4d:84:89:2f:b5:13:d1. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '59.xxx.xxx.xxx' (ECDSA) to the list of known hosts. remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (3/3), done. -
Change to the project directory:
cd mywork/ -
Check the current branch. By default, this is the
mainbranch.git branch
-
Create a new branch and modify a file
Create a new local branch to modify files.
-
Create a branch named
example:git checkout -b example -
Create a file named
test.txtand write the contentHello World!into it:echo "Hello world!" > test.txt
Commit and push changes
Push the new example branch to the remote repository.
-
Add the
test.txtfile to the staging area:git add test.txt -
Check the status of your changes:
git statusThe output is as follows:
On branch example Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: test.txt -
Commit the staged file
test.txt:git commit -m "Test commit" -
The
examplebranch currently exists only locally. Push the branch to the GitLab repository to make it accessible to others:git push origin example -
After you push to the GitLab repository, other users can view the new branch.
On the code repository page, click the branch selector in the upper-left corner. You can see the pushed example branch in the Branches list.
Merge changes
Merge the changes from your local example branch into the main branch, and then push the merged main branch to the remote repository.
-
Switch to the
mainbranch:git checkout main -
Merge the
examplebranch into themainbranch:git merge example -
Push the merged main branch to the GitLab repository:
git push -
The changes are now on the
mainbranch in the GitLab repository.In the main branch, the test.txt file contains
Hello world!.