All Products
Search
Document Center

Elastic Compute Service:Install and use GitLab

Last Updated:Nov 20, 2024

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.

    Important

    If 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.

  1. 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.

  2. Install the dependencies that are required by GitLab.

    sudo yum install -y curl python3-policycoreutils openssh-server
  3. Start the SSH service and configure the service to run on system startup.

    sudo systemctl start sshd
    sudo systemctl enable sshd
  4. (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.

    1. 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
    2. Start Postfix and configure Postfix to run on system startup.

      sudo systemctl start postfix
      sudo systemctl enable postfix
  5. Add the GitLab package repository.

    curl -fsSL https://get.gitlab.cn | sudo /bin/bash
    Note

    The 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.

    image.png

  6. 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
    Important

    If 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.

    image.png

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.

  1. 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.

  2. Install the dependencies that are required by GitLab.

    sudo apt-get update
    sudo apt-get install -y curl openssh-server ca-certificates tzdata perl
  3. Start the SSH service and configure the service to run on system startup.

    sudo systemctl start sshd
    sudo systemctl enable sshd
  4. (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.

    1. Install Postfix.

      sudo apt-get install -y postfix
    2. Start Postfix and configure Postfix to run on system startup.

      sudo systemctl start postfix
      sudo systemctl enable postfix
  5. Add the GitLab package repository.

    sudo curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
    Note

    The 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.

    image

  6. Refresh the software package list.

    sudo apt-get update
  7. 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
    Important

    If 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.

    image

Use Docker Engine to install GitLab

  1. 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.

  2. Install Docker.

    For more information, see Install Docker.

  3. Create a directory to store GitLab data.

     sudo mkdir -p /srv/gitlab 
  4. Configure the $GITLAB_HOME environment variable.

    export GITLAB_HOME=/srv/gitlab
  5. Pull the GitLab image.

    sudo docker pull gitlab/gitlab-ce

    The following command output indicates that the GitLab image is pulled.

    image.png

  6. Install the GitLab container image.

    Note
    • hostname: 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
  7. View the container status.

    sudo docker ps -a

    If the container is in the healthy state, the GitLab container is started.

    image.png

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

  1. 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.

    Important

    For 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.

    image.png

  2. 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. asda5

Generate a key pair file and obtain the public key

  1. Install Git.

    sudo yum install git
  2. 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.

    image.png

  3. 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

  1. On the GitLab homepage, click Create new project to create a project.

    ada55

  2. Click Create blank project, set Project name and Project URL, and then click Create project.

    In this example, a project named mywork is created.

    asda566

  3. Add an SSH key.

    1. On the Project overview page of the project that you created, click Add SSH key.sdaa

    2. Paste the content of the id_rsa.pub public key file to the Key field.asda

    3. Click Add key.

      The following page shows that the SSH key is added.sda

  4. Copy the clone link of the project. You can use the link to clone the project.

    项目地址

Use GitLab

  1. Configure a Git user.

    1. Specify a username for the Git user.

      git config --global user.name "testname" 
    2. Specify an email address for the Git user.

      git config --global user.email "abc@example.com" 
  2. Clone the project to an on-premises directory.

    git clone git@101.132.XX.XX:root/mywork.git

    简单配置

  3. Upload a file to the GitLab server.

    1. Access the on-premises project directory.

      cd mywork/ 
    2. Create a file that you want to upload to GitLab.

      echo "test" > /home/test/test.sh
    3. Copy the file or directory to the on-premises project directory.

      cp /home/test/test.sh ./ 
    4. Add the test.sh file to the index.

      git add test.sh
    5. Commit the test.sh file to the on-premises repository.

      git commit -m "test.sh"
    6. 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.