320x100
320x100

빌드 서버 세팅

1. 서버 시간 동기화
: rm /etc/localtime
: sudo ln -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime

2. 패키지 업데이트 및 시스템 업그레이드
: yum update -y && yum upgrade -y

3. 필요 패키지 설치 
: yum install -y docker git firewalld 

4. 필요 패키지 등록
: systemctl enable docker
: systemctl enable firewalld
: systemctl start docker
: systemctl start firewalld

5. Jenkins 이미지 다운로드
: docker pull jenkins/jenkins:lts

6. SSH 포트 변경

7. Jenkins 세팅 (시스템 설정)
: firewall-cmd --permanent --add-port=80/tcp --zone=public
: firewall-cmd --permanent --add-service=http --zone=public
: mkdir /home/ec2-user/jenkins_home

8. Jenkins 이미지 작성
# fc Build Server Container Image
FROM jenkins/jenkins
LABEL maintainer = tlgns7386@gmail.com
LABEL version = 1.0
USER root

# TimeZone Setting
RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime

# Jenkins Option Save
VOLUME /home/ec2-user/jenkins_home:/var/jenkins_home

9. Jenkins Compose file 작성
version: '3.8'

services:
  build_server:
    image: 2mukee/fc-build-server:1.0
    ports:
      - 80:8080
      - 50000:50000
    environment:
      - TZ=Asia/Seoul
    volumes:
      - /home/ec2-user/jenkins_home:/var/jenkins_home
    deploy:
      update_config:
        delay: 10s
        order: start-first
        failure_action: rollback

10. Jenkins 구동
docker build --tag 2mukee/fc-build-server:1.0 /home/ec2-user
docker stack deploy -c /home/ec2-user/fc-build-server.yml fc-stack
=> Jenkins 컨테이너는 한 대만 구동

11. Jenkins 설정
- 계정 생성 (별도 연락)
- github 레포지터리 연동

12. Docker Permission 설정
usermod -aG docker ec2-user




배포 서버 세팅

1. 서버 시간 동기화
: rm /etc/localtime
: sudo ln -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime

2. 패키지 업데이트 및 시스템 업그레이드
: yum update -y && yum upgrade -y

3. 필요 패키지 설치 
: yum install -y docker git firewalld 

4. 필요 패키지 등록
: systemctl enable docker
: systemctl enable firewalld
: systemctl start docker
: systemctl start firewalld

5. SSH 및 http 포트 설정

6. 필요한 도커 이미지 다운로드
docker pull node:16.13.0
docker pull alpine:edge
docker pull golang:1.17

7. Docker Permission 설정
usermod -aG docker ec2-user




Jenkins Agent Node Setting
- Master Node 및 Agent Node 50000 포트 개방
- 참조
https://2mukee.tistory.com/325




Agent Node 설정
: vi /home/ec2-user/jenkins-agent.sh
java -jar agent.jar -jnlpUrl http://3.37.28.236/computer/fc%2Ddeploy/jenkins-agent.jnlp -secret @secret-file -workDir "/home/ec2-user/jenkins"

: chmod 700 /home/ec2-user/jenkins-agent.sh
: vi /usr/lib/systemd/system/jenkins-agent.service
[Unit]
Description=jenkins agent
After=syslog.target network.target

[Service]
Type=simple
User=root
Group=root
ExecStart=/home/ec2-user/jenkins-agent.sh -d
WorkingDirectory=/data

[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl enable jenkins-agent
systemctl start jenkins-agent




컨테이너 빌드 테스트 및 정상작동 확인
=> Jenkins 빌드 성공
=> 배포용 이미지인 alpine linux 이미지에서의 실행 불가 (package.json 필요)
=> 수정완료 (next 프로그램의 패키징 필요)
=> 백엔드 서버 작동불가 (log가 뜨지 않아 문제 알 수 없음)



결론
1. 프론트엔드 = 하나의 파일로 실행가능 하도록 next.js에 대한 패키징 연구 필요
2. 백엔드 = /backend 에서 go build 후 backend.exe 실행이 맞는지? (로그가 나오지 않음...)

 

 

 

agent node 다시시작
: vi /etc/rc.d/rc.local
: chmod u+x /etc/rc.d/rc.local


※ Jenkins Agent Node -> Publish Over SSH 변경
: 빌드 서버에서의 빌드 이후 배포 서버에서의 배포


배포서버 Jenkins Agent Node 해제
firewall-cmd --permanent --remove-port=50000/tcp --zone=public
systemctl disable jenkins-agent
rm /usr/lib/systemd/system/jenkins-agent.service
vi /etc/rc.d/rc.local 


빌드서버 jenkins Agent Node 해제
firewall-cmd --permanent --remove-port=50000/tcp --zone=public
Jenkins 설정에서 노드 삭제


배포서버 SSH 설정
cat /etc/ssh/ssh_host_rsa_key 
vi /etc/ssh/sshd_config
  PubkeyAuthentication yes
systemctl restart sshd


빌드서버 SSH 설정
1. EC2 인스턴스 접속을 위한 pem 파일의 내용 복사 
2. 젠킨스 > 설정 > Publish Over SSH에 붙혀넣기
3. 필요파일 세팅
vi fc-login.sh
docker login -u 2mukee -p ~~
chmod 700 fc-login.sh



빌드서버 컨테이너 Docker 설치
참조 : https://docs.docker.com/engine/install/debian/



도커 컨테이너에서 Docker 실행하기
docker run -d -v /var/run/docker.sock:/var/run/docker.sock

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock



배포서버 SSH 결과물 디렉터리 권한변경
chmod 707 fc-jenkins


빌드 및 배포 테스트
=> SSH를 통한 배포 성공
=> go 프로그램에 대한 패키징에 대한 디버깅 필요
=> next js 프로그램에 패키징에 대한 디버깅 필요

 

300x250
728x90