본문 바로가기

퍼블릭 클라우드

[WIP] Amazon Linux 2에서 AWS CodeDeploy Agent를 설치하는 방법

728x90

Amazon Linux 2에서 AWS CodeDeploy Agent를 설치하는 방법

AWS CodeDeploy Agent는 EC2 인스턴스에서 애플리케이션 배포 작업을 수행하는 에이전트입니다.

CodeDeploy 서비스와 통신하여 배포 스크립트 실행, 파일 배포 등을 처리합니다.

1. 필수 패키지 설치

CodeDeploy Agent는 Ruby 기반이므로 먼저 설치합니다.

sudo yum install -y ruby wget

설치 확인

$ ruby --version
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]

2. CodeDeploy Agent 설치

방법 1: 현재 리전에 맞게 자동 설치 (권장)

cd /home/ec2-user

REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}')

wget -q https://aws-codedeploy-${REGION}.s3.${REGION}.amazonaws.com/latest/install -O install

chmod +x install
sudo ./install auto

방법 2: 특정 리전 (예: us-east-1)

wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install
chmod +x install
sudo ./install auto

3. 서비스 시작 및 자동 실행 설정

sudo systemctl start codedeploy-agent
sudo systemctl enable codedeploy-agent

서비스 상태 확인

systemctl status codedeploy-agent
$ systemctl status codedeploy-agent
● codedeploy-agent.service - AWS CodeDeploy Host Agent
   Loaded: loaded (/usr/lib/systemd/system/codedeploy-agent.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2023-08-10 19:21:01 KST; 1h 14min ago
  Process: 1939 ExecStart=/bin/bash -a -c [ -f /etc/profile ] && source /etc/profile; /opt/codedeploy-agent/bin/codedeploy-agent start (code=exited, status=0/SUCCESS)
 Main PID: 2881 (ruby)
   CGroup: /system.slice/codedeploy-agent.service
           ├─2881 codedeploy-agent: master 2881
           └─2885 codedeploy-agent: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller of master 2881

Agent가 정상적으로 설치되고 실행되었다면 설치된 Agent의 버전 및 상태가 표시될 것입니다.

4. Agent 버전 확인

yum info codedeploy-agent
$ yum info codedeploy-agent
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
247 packages excluded due to repository priority protections
Installed Packages
Name        : codedeploy-agent
Arch        : noarch
Version     : 1.6.0
Release     : 49
Size        : 13 M
Repo        : installed
Summary     : Provides the required files for CodeDeploy agent to run in EC2 instances
License     : Amazon.com Internal
Description : CodeDeploy instance agent is responsible for doing the actual work of deploying software
            : on an EC2 instance.

5. 로그 확인

문제 발생 시 가장 먼저 확인해야 하는 부분입니다.

sudo tail -f /var/log/aws/codedeploy-agent/codedeploy-agent.log

6. 설치 경로 및 구조

/opt/codedeploy-agent
$ tree -L 2
.
├── bin
│   ├── codedeploy-agent
│   ├── codedeploy-local
│   └── install
├── certs
│   ├── host-agent-deployment-signer-ca-chain.pem
│   └── windows-ca-bundle.crt
├── codedeploy_agent.gemspec
├── Gemfile
├── lib
│   ├── aws
│   ├── codedeploy-agent.rb
│   ├── core_ext.rb
│   ├── instance_agent
│   ├── instance_agent.rb
│   ├── instance_metadata.rb
│   ├── register.rb
│   └── winagent.rb
├── LICENSE
├── state
└── vendor
    ├── gems
    └── specifications

9 directories, 14 files

7. 트러블슈팅

Agent가 시작되지 않는 경우

sudo systemctl restart codedeploy-agent

로그 확인

/var/log/aws/codedeploy-agent/codedeploy-agent.log

 

이제 AWS CodeDeploy Agent가 Amazon Linux 2 인스턴스에 설치되었으며 CodeDeploy를 사용하여 애플리케이션을 배포할 수 있습니다.

 

728x90