이 가이드에서는 Compute Engine을 시작하는 방법을 보여줍니다. 이 가이드를 따라 Hello World Ruby 웹 앱을 Compute Engine에 배포합니다. App Engine을 시작하는 데 도움이 필요하면 App Engine 표준 환경을 참조하세요.
목표
- Cloud Shell을 사용하여 Hello World 샘플 앱을 다운로드하고 배포합니다.
- Hello World 샘플 앱을 단일 Compute Engine 인스턴스에 배포합니다.
비용
이 문서에서는 비용이 청구될 수 있는 구성요소를 사용합니다 Google Cloud.
프로젝트 사용량을 기준으로 예상 비용을 산출하려면 가격 계산기를 사용하세요.
시작하기 전에
- 계정에 로그인합니다. Google Cloud Google Cloud를 처음 사용하는 경우 계정을 만들고 Google 제품의 실제 성능을 평가해 보세요. 신규 고객에게는 워크로드를 실행, 테스트, 배포하는 데 사용할 수 있는 $300의 무료 크레딧이 제공됩니다.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Compute Engine API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Compute Engine API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
콘솔 Google Cloud 에서 Cloud Shell의 앱을 엽니다.
Cloud Shell을 사용하면 브라우저에서 직접 명령줄을 통해 클라우드 리소스에 액세스할 수 있습니다.
-
저장소를 클론하는 데 동의하면 확인 을 클릭하여 샘플 코드를 다운로드하고 앱 디렉터리로 변경합니다.
-
새
프로젝트를 Google Cloud 사용하도록 Cloud Shell에서 gcloud CLI를 구성합니다.
# Configure gcloud for your project gcloud config set project YOUR_PROJECT_ID
Cloud Shell에서 앱 실행
Cloud Shell에서
bundle를 사용하여 앱 종속 항목을 설치합니다.bundle installSinatra 앱을 실행합니다.
bundle exec ruby app.rb -p 8080Cloud Shell에서 웹 미리보기를 클릭하고 포트 8080에서 미리보기를 선택합니다. 그러면 실행 중인 앱이 표시된 새 창이 열립니다.
로컬 웹 서버를 중지하려면 Control+C를 누릅니다.
단일 인스턴스에 배포
이 섹션에서는 Compute Engine에서 앱의 단일 인스턴스 실행을 단계별로 알아봅니다.
Cloud Shell에서 앱을 실행하는 단일 Compute Engine 인스턴스 가상 머신(VM)에 배포할 수 있습니다.
시작 스크립트를 사용하여 인스턴스 초기화
인스턴스에서 코드를 다운로드하고 실행하도록 지시할 방법이 필요합니다. 인스턴스를 시작하거나 재시작할 때마다 실행되는 시작 스크립트를 인스턴스에 포함하면 됩니다.
시작 스크립트는 다음과 같은 작업을 수행합니다.
Cloud Logging 에이전트를 설치합니다. 에이전트는 syslog에서 자동으로 로그를 수집합니다.
Ruby 2.6.5, Bundler, 시스템 종속 항목을 설치합니다.
Cloud Source Repositories에서 앱의 소스 코드를 복제하고 종속 항목을 설치합니다.
Nginx를 설치 및 구성합니다.
앱을 데몬으로 실행하기 위해 Supervisor 를 설치합니다.
앱을 실행하도록 Supervisor를 구성합니다. Supervisor는 앱이 예기치 않게 종료되거나 관리자 또는 다른 프로세스에 의해 종료된 경우 앱이 다시 시작되게 만듭니다. 또한 앱의
stdout및stderr을 syslog로 보내서 Logging 에이전트가 이를 수집하도록 합니다.
Compute Engine 인스턴스 만들기 및 구성
Compute Engine 인스턴스를 만듭니다.
Linux/macOS