GCP

Google Cloud Platform VM 인스턴스에 jenkins 설치하기 삽질(도커엔딩)

초코민트냠냠 2022. 12. 13. 14:19
반응형

구글 클라우드 플랫폼에 젠킨스를 올려보자!

하고싶었던것

 구글 클라우드 플랫폼에 VM인스턴스 평생 무료 옵션이 있길래 냉큼 가입해서 24시간 돌아가는거니까 Jenkins 서버로 써보자! 라고 생각을 하고 e2-micro 사양의 컴퓨팅 서버에 젠킨스 설치를 시도해 보았습니다.

 

 우분투(Ubuntu 18.04.6 LTS) 로 시작했고 vCPU 2개와 1GB 메모리 30GB의 스토리지의 사양으로 되어있습니다. 

Jenkins 최소사양

 젠킨스 공식 홈페이지에서 최소 사양을 확인해봤을때 충분히 가능해보여서 바로 설치 시작했습니다. 공식 홈페이지에 쓰여있는대로 젠킨스 LTS 설치 스크립트 복붙을 했습니다. Jenkins 구동에는 자바가 필요하므로 자바 11도 설치했습니다.

sudo apt update
sudo apt install openjdk-11-jre
java -version

 

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins

이상한 오류

설치오류

 설치 했을 때 오류가 났길래 안됐나보다 했지만 젠킨스 서비스 확인을 해보면 돌아가고 있었습니다.

sudo systemctl jenkins status
● jenkins.service - Jenkins Continuous Integration Server
   Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Fri 2022-12-09 02:45:47 UTC; 13s ago
  Process: 3371 ExecStart=/usr/bin/jenkins (code=exited, status=143)
 Main PID: 3371 (code=exited, status=143)

Dec 09 02:45:24 instance-1 systemd[1]: jenkins.service: Scheduled restart job, restart counter is at 10.
Dec 09 02:45:24 instance-1 systemd[1]: Stopped Jenkins Continuous Integration Server.
Dec 09 02:45:24 instance-1 systemd[1]: Starting Jenkins Continuous Integration Server...
Dec 09 02:45:28 instance-1 jenkins[3371]: Running from: /usr/share/java/jenkins.war
Dec 09 02:45:33 instance-1 jenkins[3371]: 2022-12-09 02:45:32.877+0000 [id=1]        INFO        winstone.Logger#
Dec 09 02:45:34 instance-1 jenkins[3371]: 2022-12-09 02:45:34.116+0000 [id=1]        WARNING        o.e.j.s.handl
Dec 09 02:45:35 instance-1 jenkins[3371]: 2022-12-09 02:45:35.613+0000 [id=1]        INFO        org.eclipse.jett
Dec 09 02:45:44 instance-1 jenkins[3371]: 2022-12-09 02:45:44.109+0000 [id=1]        INFO        o.e.j.w.Standard
Dec 09 02:45:45 instance-1 jenkins[3371]: 2022-12-09 02:45:45.629+0000 [id=1]        INFO        o.e.j.s.s.Defaul
Dec 09 02:45:47 instance-1 systemd[1]: Stopped Jenkins Continuous Integration Server.

 위에는 없지만 다른 로그를 확인해보면 정상적으로 실행되고 초기 설정을 하기 위한 Secret Key도 잘 적혀 있었습니다. 그런데 문제는 1분 30초마다 타임아웃이 되면서 재시작이 되는 것이었습니다. 위 로그에도 restart counter is at 10이라고 적힌 것을 볼 수 있습니다. 

 그래서 systemd쪽에 문제가 있는건가 해서 init.d도 건들여보고 이것저것 만져봤지만 해결되는게 없었습니다. (Ubuntu 문제가 아닐까..) 검색해보니 젠킨스 커뮤니티에도 비슷한 증상을 겪는 분이 계신거 같은데 해결방법은 마땅히 없었습니다.

https://community.jenkins.io/t/my-jenkins-startup-times-out-it-appears-to-work-but-the-start-command-times-out-on-the-shell-prompt/1038

 

My Jenkins startup times out. It appears to work, but the start command times out on the shell prompt

Hello all, For the past few releases, I’ve had to manually intervene to shutdown and startup Jenkins. Startup would be my primary concern and, possibly, the cause of the shutdown problems so I’d like to know that it has started OK before I worry about

community.jenkins.io

 결론적으로 시스템문제 혹은 환경문제라고 생각을 해서 Docker로 젠킨스를 실행시키기로 했습니다.

Docker로 Jenkins 실행하기

우선 도커 설치부터 진행했습니다.

sudo apt-get update
sudo apt-get install -y ca-certificates \ 
    curl \
    software-properties-common \
    apt-transport-https \
    gnupg \
    lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

 도커가 설치된것을 확인하고 젠킨스 이미지를 pull 합니다.

docker pull jenkins/jenkins:lts

그리고 docker run으로 실행시킵니다.

docker run -d -p 8080:8080 \
    -v /jenkins:/var/jenkins_home \
    --name jenkins -u root \
    jenkins/jenkins:lts

젠킨스 접속

 이제 VM인스턴스 네트워크 설정에 가서 VPC 네트워크 - 방화벽 - 방화벽 규칙 만들기를 누릅니다. 그리고 대상은 http-server, IPv4모든 범위에 8080포트를 열어 줍니다.

 VM인스턴스 외부 아이피를 확인하고 "외부아이피:8080"으로 접속하면 젠킨스에 접속이 됩니다. VM인스턴스 고정 아이피를 만들어서 연결할 수도 있습니다. VPC 네트워크 - IP 주소 - 외부 고정 주소 예약을 눌러서 만들고 연결하면 됩니다. 그리고 접속해서 젠킨스 설정을 하면 됩니다. 저는 이것저것 만들어놔서 바로 로그인이 뜹니다.

젠킨스 로그인 화면

결론

 환경문제로 설치가 잘 안되거나 할때 도커를 사용하자.

결과

반응형

'GCP' 카테고리의 다른 글

GCP e2-micro Jenkins yarn build 멈춤 (AWS EC2 t2.micro도 동일)  (0) 2022.12.15