All Products
Search
Document Center

Elastic Compute Service:Install and use GitLab

Last Updated:Apr 18, 2024

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:

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

  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 policycoreutils-python 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 set up 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 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
    2. Start Postfix and configure Postfix to run on system startup.

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

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

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

    image.png

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

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

    image.png

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 and use Docker on a Linux instance.

  3. Create a directory to which the Docker container mounts the volume.

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

    export GITLAB_HOME=/srv/gitlab
  5. 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.

    image.png

  6. Run the following command to install the GitLab container image:

    Note
    • hostname: 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
  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

Log on to GitLab

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

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

    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

    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

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