Help us improve the AWS re:Post Knowledge Center by sharing your feedback in a brief survey. Your input can influence how we create and update our content to better support your AWS journey.
시작 템플릿을 사용하여 Amazon Linux 또는 Ubuntu를 실행하는 Amazon EC2 인스턴스에 CodeDeploy 에이전트를 자동으로 설치하려면 어떻게 해야 하나요?
4분 분량
0
Linux 또는 Ubuntu를 실행하는 Amazon Elastic Compute Cloud(Amazon EC2) 인스턴스에 AWS CodeDeploy 에이전트를 자동으로 설치하려고 합니다.
해결 방법
시작 템플릿을 생성할 때 사용자 데이터 필드를 사용하여 인스턴스 시작 시 실행되는 구성 스크립트를 추가합니다. 쉘 스크립트는 모든 AWS 지역과 지원되는 Amazon Linux 및 Ubuntu 배포에 CodeDeploy 에이전트를 설치합니다.
부팅 시 자동 업데이트되도록 CodeDeploy를 구성하려면 AUTOUPDATE 변수를 true로 설정합니다. 예를 들어, 인스턴스 메타데이터 버전을 기반으로 Amazon EC2 User data 필드에 다음 구성 스크립트를 추가합니다.
중요: 다음 스크립트는 Linux용 EC2에서만 작동합니다. Windows 환경에서는 스크립트가 실패합니다.
IMSDv1:
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 #!/bin/bash -xe ## CodeDeploy Agent Bootstrap Script## exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1AUTOUPDATE=false function installdep(){ if [ ${PLAT} = "ubuntu" ]; then apt-get -y update # Satisfying even ubuntu older versions. apt-get -y install jq awscli ruby2.0 || apt-get -y install jq awscli ruby elif [ ${PLAT} = "amz" ]; then yum -y update yum install -y aws-cli ruby jq fi } function platformize(){ #Linux OS detection# if hash lsb_release; then echo "Ubuntu server OS detected" export PLAT="ubuntu" elif hash yum; then echo "Amazon Linux detected" export PLAT="amz" else echo "Unsupported release" exit 1 fi } function execute(){ if [ ${PLAT} = "ubuntu" ]; then cd /tmp/ wget https://aws-codedeploy-${REGION}.s3.amazonaws.com/latest/install chmod +x ./install if ./install auto; then echo "Installation completed" if ! ${AUTOUPDATE}; then echo "Disabling Auto Update" sed -i '/@reboot/d' /etc/cron.d/codedeploy-agent-update chattr +i /etc/cron.d/codedeploy-agent-update rm -f /tmp/install fi exit 0 else echo "Installation script failed, please investigate" rm -f /tmp/install exit 1 fi elif [ ${PLAT} = "amz" ]; then cd /tmp/ wget https://aws-codedeploy-${REGION}.s3.amazonaws.com/latest/install chmod +x ./install if ./install auto; then echo "Installation completed" if ! ${AUTOUPDATE}; then echo "Disabling auto update" sed -i '/@reboot/d' /etc/cron.d/codedeploy-agent-update chattr +i /etc/cron.d/codedeploy-agent-update rm -f /tmp/install fi exit 0 else echo "Installation script failed, please investigate" rm -f /tmp/install exit 1 fi else echo "Unsupported platform ''${PLAT}''" fi } platformize installdep REGION=$(curl -s 169.254.169.254/latest/dynamic/instance-identity/document | jq -r ".region") execute
IMSDv2:
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 #!/bin/bash -xe ## CodeDeploy Agent Bootstrap Script## exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 AUTOUPDATE=false function installdep(){ if [ ${PLAT} = "ubuntu" ]; then apt-get -y update # Satisfying even ubuntu older versions. apt-get -y install jq awscli ruby2.0 || apt-get -y install jq awscli ruby elif [ ${PLAT} = "amz" ]; then yum -y update yum install -y aws-cli ruby jq fi } function platformize(){ #Linux OS detection# if hash lsb_release; then echo "Ubuntu server OS detected" export PLAT="ubuntu" elif hash yum; then echo "Amazon Linux detected" export PLAT="amz" else echo "Unsupported release" exit 1 fi } function execute(){ if [ ${PLAT} = "ubuntu" ]; then cd /tmp/ wget https://aws-codedeploy-${REGION}.s3.amazonaws.com/latest/install chmod +x ./install if ./install auto; then echo "Installation completed" if ! ${AUTOUPDATE}; then echo "Disabling Auto Update" sed -i '/@reboot/d' /etc/cron.d/codedeploy-agent-update chattr +i /etc/cron.d/codedeploy-agent-update rm -f /tmp/install fi exit 0 else echo "Installation script failed, please investigate" rm -f /tmp/install exit 1 fi elif [ ${PLAT} = "amz" ]; then cd /tmp/ wget https://aws-codedeploy-${REGION}.s3.amazonaws.com/latest/install chmod +x ./install if ./install auto; then echo "Installation completed" if ! ${AUTOUPDATE}; then echo "Disabling auto update" sed -i '/@reboot/d' /etc/cron.d/codedeploy-agent-update chattr +i /etc/cron.d/codedeploy-agent-update rm -f /tmp/install fi exit 0 else echo "Installation script failed, please investigate" rm -f /tmp/install exit 1 fi else echo "Unsupported platform ''${PLAT}''" fi } platformize installdep TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` REGION=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r ".region") execute
관련 정보
- 언어
- 한국어

AWS 공식업데이트됨 2년 전
댓글 없음