gitlabUrl : 도메인
registration token : YOUR WORK > Amdin Area > CI/CD > Runners > [New instance runner] > runner 생성시 토큰 자동 발급
(gitlab 버전 마다 경로 다를 수 있음)
# root 로 실행
# gitlab-runner 파일 다운로드
$ sudo curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64"
# 설치중
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 61.0M 100 61.0M 0 0 7198k 0 0:00:08 0:00:08 --:--:-- 8812k
$ cd /usr/local/bin/
$ ll
# 결과
total 62544
-rw-r--r--. 1 root root 64042939 Mar 14 17:40 gitlab-runner
# 권한 부여
$ chmod +x /usr/local/bin/gitlab-runner
# 사용자계정 추가 --comment : 로그인에 대한 설명, --create-home :
사용자 홈디렉토리설정, --shell : 지정할 쉘 계정명(기본값은 /bin/bash)
요약하자면, 이 명령은 'GitLab Runner'라는 설명이 달린 'gitlab-runner'라는 이름의 새 사용자를 생성하고, 사용자에게 홈 디렉토리를 제공하며, 사용자의 기본 쉘로 /bin/bash를 설정합니다. 이러한 설정은 주로 GitLab CI/CD 파이프라인을 자동으로 실행하기 위해 GitLab Runner를 설치할 때 사용자 계정을 구성할 때 사용됩니다.
$ useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
# 사용자 계정 생성 확인
$ vi /etc/passwd
$ gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
Runtime platform arch=amd64 os=linux pid=2903 revision=782c6ecb version=16.9.1
$ gitlab-runner start
Runtime platform arch=amd64 os=linux pid=3005 revision=782c6ecb version=16.9.1
# 결과
$ systemctl status gitlab-runner
● gitlab-runner.service - GitLab Runner
Loaded: loaded (/etc/systemd/system/gitlab-runner.service; enabled; preset: disabled)
Active: active (running) since Thu 2024-03-14 17:52:08 KST; 6s ago
Main PID: 3010 (gitlab-runner)
Tasks: 6 (limit: 1114)
Memory: 14.6M
CPU: 93ms
CGroup: /system.slice/gitlab-runner.service
└─3010 /usr/local/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml -->
Mar 14 17:52:08 ip-172-31-33-50.ap-northeast-2.compute.internal systemd[1]: Started gitlab-runner.service - GitLab Runner.
Mar 14 17:52:08 ip-172-31-33-50.ap-northeast-2.compute.internal gitlab-runner[3010]: Runtime platform >
Mar 14 17:52:08 ip-172-31-33-50.ap-northeast-2.compute.internal gitlab-runner[3010]: Starting multi-runner from /etc/gitlab-runner/conf>
Mar 14 17:52:08 ip-172-31-33-50.ap-northeast-2.compute.internal gitlab-runner[3010]: Running in system-mode.
Mar 14 17:52:08 ip-172-31-33-50.ap-northeast-2.compute.internal gitlab-runner[3010]:
Mar 14 17:52:08 ip-172-31-33-50.ap-northeast-2.compute.internal gitlab-runner[3010]: Created missing unique system ID >
Mar 14 17:52:08 ip-172-31-33-50.ap-northeast-2.compute.internal gitlab-runner[3010]: Configuration loaded >
Mar 14 17:52:08 ip-172-31-33-50.ap-northeast-2.compute.internal gitlab-runner[3010]: listen_address not defined, metrics & debug endpoi>
Mar 14 17:52:08 ip-172-31-33-50.ap-northeast-2.compute.internal gitlab-runner[3010]: [session_server].listen_address not defined, sessi>
Mar 14 17:52:08 ip-172-31-33-50.ap-northeast-2.compute.internal gitlab-runner[3010]: Initializing executor providers >
[root@ip-172-31-33-50 usr]#
# gitlab runner 설치, 사용자는 user로 실행하며, 작업 디렉토리에서 빌드
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
# gitlab에 gitlab-runner 연결
$ gitlab-runner register
Runtime platform arch=amd64 os=linux pid=3074 revision=782c6ecb version=16.9.1
Running in system-mode.
# 입력
Enter the GitLab instance URL (for example, https://gitlab.com/):
도메인
Enter the registration token:
토큰
Verifying runner... is valid runner=d8xFM3Uzm
Enter a name for the runner. This is stored only in the local config.toml file:
[ip-172-31-33-50.ap-northeast-2.compute.internal]: practice-sch
Enter an executor: custom, shell, parallels, kubernetes, instance, ssh, virtualbox, docker, docker-windows, docker+machine, docker-autoscaler:
shell # runner 실행시 shell 로 실행
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"
# 등록한 gitlab runner 리스트 확인
$ gitlab-runner list
# 결과
Runtime platform arch=amd64 os=linux pid=3082 revision=782c6ecb version=16.9.1
Listing configured runners ConfigFile=/etc/gitlab-runner/config.toml
practice-sch Executor=shell Token=토큰 URL=도메인
# 등록된 gitlab runner 확인
$ vi /etc/gitlab-runner/config.toml
concurrent = 1
check_interval = 0
connection_max_age = "15m0s"
shutdown_timeout = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "practice-sch"
url = "도메인"
id = 35
token = "토큰값"
token_obtained_at = 2024-03-14T08:54:04Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "shell"
[runners.cache]
MaxUploadedArchiveSize = 0
~
참고 :
https://nakanara.tistory.com/240
https://jforj.tistory.com/227