×
Community Blog Deploy and Use GitLab on ECS

Deploy and Use GitLab on ECS

This article describes how to deploy and use GitLab on an Elastic Compute Service (ECS) instance.

By Alibaba Cloud ECS Team

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

1.  Connect to the ECS instance. 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.

a) 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

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

1

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

The following command output indicates that GitLab is installed.

2

Use GitLab

Log on to GitLab

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

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

3

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

4

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.

5

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.

6

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

7

3.  Add an SSH key.

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

8

b) Paste the content of the id_rsa.pub public key file to the Key field.

9

c) Click Add key.

The following page shows that the SSH key is added.

10

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

11

Use GitLab

1.  Configure a Git user.

a) Specify a username for the Git user.

git config --global user.name "testname" 

b) 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/test.git

12

3.  Upload a file to the GitLab server.

a) Access the on-premises project directory.

cd mywork/ 

b) Create a file that you want to upload to GitLab.

echo "test" > /home/test/test.sh

c) Copy the file or directory to the on-premises project directory.

cp /home/test/test.sh ./ 

d) Add the test.sh file to the index.

git add test.sh

e) Commit the test.sh file to the on-premises repository.

git commit -m "test.sh"

f) Push the file to the GitLab server.

git push -u origin main

13

The following page shows that the test.sh file is pushed to the GitLab server. You can view the file on the page.

14

0 1 0
Share on

Alibaba Cloud Community

887 posts | 199 followers

You may also like

Comments

Alibaba Cloud Community

887 posts | 199 followers

Related Products