IaC/CI CD Tool

1. GitLab이란? / 개념 및 설치

Somaz 2023. 4. 20. 19:19
728x90
반응형

Overview

오늘은 GitLab에 대해 공부해보려고 한다.


GitLab은 소프트웨어 개발 및 협업을 위한 올인원 DevOps 플랫폼으로, 코드 저장소 관리뿐만 아니라 CI/CD 기능까지 제공하는 강력한 도구이다.


이번 글에서는 GitLab의 개념, 주요 기능, CE vs EE 차이점, 설치 방법, 백업 및 복구, NFS 스토리지 구성 방법 등을 다룬다.

 


다음 시간에는 GitLab Runner에 대해 자세히 알아볼 예정이다.

 

 

 

 

 

📅 관련 글

2023.04.20 - [IaC/CI CD Tool] - 1. GitLab이란? / 개념 및 설치

2023.04.23 - [IaC/CI CD Tool] - 2. GitLab이란? / GitLab Runner 개념 및 설치

2023.04.24 - [IaC/CI CD Tool] - 3. GitLab이란? / GitLab CI/CD

2023.08.08 - [IaC/CI CD Tool] - 4. GitLab 버전 업그레이드

2023.08.08 - [IaC/CI CD Tool] - 5. GitLab ArgoCD 연동

2024.05.28 - [IaC/CI CD Tool] - 6. Gitlab CI Build(with GCP Artifact Registry, Harbor)

2024.06.18 - [IaC/CI CD Tool] - 7. Gitlab CI Template 활용

2025.01.09 - [IaC/CI CD Tool] - 8. Gitlab Repository Mirroring 방법

 


 

 


 

 

GitLab이란?

GitLab은 소프트웨어 개발 및 협업을 위한 올인원 솔루션을 제공하는 웹 기반 DevOps 플랫폼이다.
 
팀이 소프트웨어 프로젝트를 보다 효율적으로 계획, 생성, 구축, 테스트 및 배포하는 데 도움이 되는 다양한 도구와 기능을 제공한다. 
 


 

GitLab 주요기능

  • Git 리포지토리 관리
  • 이슈 추적 및 프로젝트 관리
  • CI(지속적인 통합) 및 CD(지속적인 배포)
  • 코드 검토
  • 보안 및 규정 준수
  • 타사 도구와의 통합

 

 

 

 


 

 

 

 

GitLab CE vs GitLab EE 차이점

비교 항목 GitLab CE (무료)  GitLab EE (유료)
라이선스 오픈소스 (MIT) 프로프라이어터리 (독점)
기본 기능 Git 리포지토리, CI/CD, 코드 리뷰 CE의 모든 기능 + 고급 보안 및 관리 기능
CI/CD ✅ 포함 ✅ 고급 CI/CD (병렬 실행, 실행 우선순위)
보안 및 규정 준수 ❌ 제한적 ✅ 스캔, 감사 로그, SAML 인증
고급 DevOps 기능 ❌ 없음 ✅ 프로젝트 관리, Jira 통합
Self-Hosted 지원 ✅ 가능 ✅ 가능
SaaS(Cloud) 지원 ✅ 가능 ✅ 가능 (GitLab Ultimate)
  • GitLab CE는 대부분의 프로젝트에 충분하지만, 엔터프라이즈 환경에서는 GitLab EE가 필요할 수 있음.

 

 

 

 


 

 

GitLab 설치(Ubuntu 18,20,22.04)

 

 

 

Step 1. 시스템 업데이트 & 패키지 설치

## Update System ##
sudo apt update
sudo apt upgrade -y

## Install package ##
sudo apt install -y ca-certificates curl openssh-server tzdata

 

 

 

Step 2. GitLab CE Repository 추가

## Install Package ##
sudo apt update
sudo apt install curl debian-archive-keyring lsb-release ca-certificates apt-transport-https software-properties-common -y

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

 

 

 

Step 3. Gitlab 설치 및 구성

## Install gitlab-ce ##
sudo apt update
sudo EXTERNAL_URL="https://gitlab.example.com/" apt-get install gitlab-ce

## Install gitlab-ce https cloud ##
sudo apt update
sudo EXTERNAL_URL="https://gitlab.example.com/" apt-get install gitlab-ce     # Replace with your Domain
echo "letsencrypt['enable'] = false" | sudo tee -a /etc/gitlab/gitlab.rb
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

## Install gitlab-ce https##
sudo apt update
sudo EXTERNAL_URL="https://gitlab.example.com/" apt-get install gitlab-ce     # Replace with your Domain

## Install gitlab-ce https cloud(aws,gcp... ##
sudo apt update
sudo EXTERNAL_URL="https://gitlab.example.com/" apt-get install gitlab-ce     # Replace with your Domain
sudo vi /etc/gitlab/gitlab.rb

letsencrypt['enable'] = true
external_url 'https://gitlab.example.com'  # Ensure your external URL is using HTTPS
letsencrypt['contact_emails'] = ['somaz@somaz.link'] # Use your email
letsencrypt['auto_renew'] = true
letsencrypt['auto_renew_day_of_month'] = "*/30"
letsencrypt['auto_renew_log_directory'] = '/var/log/gitlab/lets-encrypt'
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

## gitlab reconfigure ##
sudo gitlab-ctl reconfigure

## gitlab restart ##
sudo gitlab-ctl restart

## gitlab status ##
sudo gitlab-ctl status

## gitlab initial_root_passowrd ##
$ 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: kOtOjWp7v70OjkjtadnSJAhcDbCNo9nTNGVC5UoSCyE=

 

 

 

 

Step 4. GitLab Web 접속

출처 : gitlab 설치 참고 블로그

 
 

 

 

중요 디렉토리 설명

/var/opt/gitlab/gitlab-rails/shared/lfs-objects
  • 해당 디렉터리는 Git 대용량 파일 저장소(LFS) 개체를 저장하는 데 사용된다.
  • Git LFS는 사용자가 바이너리 자산과 같은 대용량 파일을 보다 효율적으로 버전화할 수 있도록 하는 Git용 extension이다.
  • 전체 대용량 파일을 Git 저장소에 저장하는 대신 LFS는 파일에 대한 포인터만 저장하는 반면 실제 파일은 서버(이 경우 lfs-objects 디렉토리)에 별도로 저장된다.
  • 이 설정은 Git 리포지토리의 크기를 줄이고 Git 작업의 성능을 향상시키는 데 도움이 됩니다.

 

 

/var/opt/gitlab/git-data
  • 해당 디렉토리는 GitLab 인스턴스에서 관리하는 실제 Git 리포지토리 및 기타 리포지토리 관련 데이터를 저장하는 데 사용된다.
  • GitLab 설치에서 각 프로젝트에는 프로젝트의 소스 코드, 버전 기록 및 기타 관련 데이터가 포함된 자체 Git 리포지토리가 있다.
  • /var/opt/gitlab/git-data 디렉토리는 이러한 모든 리포지토리와 관련 데이터를 저장하기 위한 루트 디렉토리 역할을 한다.

 

 

 
따라서 아래와 같이 mount해서 쓰면 좋다.

$ df-h
/dev/xvdb1                         2.0T  310G  1.6T  17% /var/opt/gitlab/gitlab-rails/shared/lfs-objects
/dev/xvdc1                         984G  273G  661G  30% /var/opt/gitlab/git-data

 

 

 

 

 

 


 

 

 

 

 

 

GitLab Docker 설치 방법

GitLab은 Docker를 통해 간편하게 배포할 수 있으며, 테스트 환경이나 경량 개발 환경에 적합하다. 아래는 Docker 기반 GitLab CE 설치 방법이다.

 

 

사전 준비 사항

  • Docker가 설치된 환경 (Linux/macOS/Windows)
  • Docker Compose (선택 사항이지만 권장)
  • 4GB 이상의 메모리
  • 도메인 또는 외부 접속 가능한 IP

 

 

 

1. Docker Compose 파일 작성

 
mkdir gitlab-docker && cd gitlab-docker
vi docker-compose.yml
version: '3.6'

services:
  gitlab:
    image: gitlab/gitlab-ce:17.10.3-ce.0 # stable 버전 권장
    container_name: gitlab
    restart: always
    hostname: 'test-gitlab.concrit.us'  # 수정 필요
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://test-gitlab.concrit.us'  # 또는 https://로 설정
    ports:
      - '80:80'
      - '443:443'
      - '22:22'
    volumes:
      - './config:/etc/gitlab'
      - './logs:/var/log/gitlab'
      - './data:/var/opt/gitlab'
    networks:
      concrit_bridge:
        ipv4_address: 10.10.10.46 # docker network 변경방법(선택)

networks:
  concrit_bridge:
    external: true
  • HTTPS 설정 시 external_urlhttps:// 로 변경하고 SSL 인증서 파일을 /etc/gitlab/ssl 디렉터리에 넣어야 한다.

 

 

docker-compose.yml 수정 (Let’s Encrypt 활성화 선택)

version: '3.6'

services:
  gitlab:
    image: gitlab/gitlab-ce:17.10.3-ce.0         # stable 버전 권장
    container_name: gitlab
    restart: always
    hostname: 'gitlab.example.com'                # 반드시 실제 도메인으로 설정 (DNS가 연결되어 있어야 함)
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'https://gitlab.example.com'   # HTTPS 설정
        letsencrypt['enable'] = true
        letsencrypt['contact_emails'] = ['youremail@example.com'] # 인증서 갱신 관련 알림 받을 이메일
        letsencrypt['auto_renew'] = true
        letsencrypt['auto_renew_hour'] = "0"
        letsencrypt['auto_renew_minute'] = "30"
        letsencrypt['auto_renew_day_of_month'] = "*/7"
    ports:
      - '80:80'
      - '443:443'
      - '22:22'
    volumes:
      - './config:/etc/gitlab'
      - './logs:/var/log/gitlab'
      - './data:/var/opt/gitlab'
    networks:
      somaz_bridge:
        ipv4_address: 10.10.10.39 # docker network 변경방법(선택)
 
 networks:
  somaz_bridge:
    external: true

 

 

 

 

 

2. GitLab 컨테이너 실행

mkdir config && mkdir logs && mkdir data

docker-compose up -d

 

 

 

 

초기 비밀번호 확인

cat data/initial_root_password
  • 웹에서 로그인 시 root 계정과 위의 비밀번호를 사용한다.

 

 

 

 

3. 웹으로 접속

브라우저에서 아래 주소로 접속해 GitLab을 확인한다.

http://localhost
또는 http://<서버IP>
또는 http://gitlab.example.com
  • 도메인을 사용한 경우 DNS가 올바르게 설정돼 있어야 한다.

 

 

 

 

 


 

 

 

 

 

 

GitLab Backup 및 복구 방법

 

 

GitLab 백업 실행

sudo gitlab-backup create

  • 백업 파일은 기본적으로 /var/opt/gitlab/backups/ 디렉토리에 저장됨.

 

 

GitLab 백업 복구

# GitLab 서비스 중지
sudo gitlab-ctl stop puma
sudo gitlab-ctl stop sidekiq

# 백업 파일 복원 (파일명은 `gitlab-backup create` 실행 시 생성된 파일명)
sudo gitlab-backup restore BACKUP=1675369324_2023_02_02_13.2.0

# 서비스 다시 시작
sudo gitlab-ctl restart

  • 이제 GitLab 데이터가 복구됨!

 

 

 

 


 

 

 

 

 

GitLab NFS 스토리지 구성 방법

 

GitLab NFS 마운트 설정

sudo mkdir -p /mnt/gitlab-nfs
sudo mount -t nfs4 nfs.example.com:/gitlab /mnt/gitlab-nfs

 

 

GitLab 설정 파일 수정 (/etc/gitlab/gitlab.rb)

git_data_dirs({
  "default" => {
    "path" => "/mnt/gitlab-nfs/git-data"
  }
})

 

 

변경 사항 적용

bash
복사편집
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

  • NFS를 사용하면 GitLab 데이터 저장소를 확장 가능!

 

 

 

 


 

 

 

 

마무리

 

GitLab은 단순한 Git 저장소를 넘어 CI/CD, 이슈 트래킹, 코드 리뷰, 보안 검사, 배포 자동화 등의 기능을 제공하는 강력한 DevOps 플랫폼이다.


특히 자체 호스팅이 가능하여 보안이 중요한 기업 환경에서 많이 사용된다.

이번 글에서는 GitLab의 개념부터 설치 방법, 백업/복구, NFS 스토리지 구성까지 실무에서 유용하게 활용할 수 있는 내용을 정리했다.

 


다음 글에서는 GitLab Runner를 활용하여 CI/CD를 설정하는 방법을 알아볼 예정이다.

 

 

 

 

 

 


 

Reference

 
gitlab 설치 참고 블로그

728x90
반응형

'IaC > CI CD Tool' 카테고리의 다른 글

2. Github Action (With Syntax)  (0) 2023.05.22
1. Github Action이란?  (0) 2023.05.19
ArgoCD란?  (0) 2023.05.17
3. GitLab이란? / GitLab CI/CD  (0) 2023.04.24
2. GitLab이란? / GitLab Runner 개념 및 설치  (5) 2023.04.23