운영 에이전트

아키텍처

운영 에이전트는 Monitoring 및 Logging 서비스와 통합을 위해 가상 머신을 만들고 운영 에이전트를 설치합니다. 여기에는 다음이 사용됩니다.

  • Compute Engine
  • 모니터링
  • 로깅

이 예시에서는 간단한 단일 가상 머신을 설정하고 Logging에 보고하도록 연결합니다.


시작하기

Cloud Shell에서 소스 코드의 복사본에 대해 다음 링크를 클릭합니다. 링크에 도착한 다음 단일 명령어로 프로젝트에서 애플리케이션의 작업 복사본이 작동합니다.

Cloud Shell에서 열기

GitHub에서 소스 코드 보기


운영 에이전트 구성요소

운영 에이전트 아키텍처에는 여러 제품이 사용됩니다. 다음은 관련 동영상 링크, 제품 문서 및 대화형 둘러보기를 포함하여 구성 요소에 대한 자세한 정보와 함께 구성요소 목록을 보여줍니다.
동영상 문서 둘러보기
Compute Engine Compute Engine은 Google Cloud의 가상 기술입니다. 이를 사용하면 어떤 컴퓨팅 요구든 그에 맞게 여러 다른 VM 구성을 가동할 수 있습니다.
Cloud Monitoring Cloud Monitoring은 애플리케이션 및 인프라의 성능, 가용성, 상태에 대한 가시성을 제공합니다.
Cloud Logging Cloud Logging은 엑사바이트급 스토리지, 검색, 분석, 알림을 지원하는 완전 관리형 실시간 로그 관리를 제공합니다.

스크립트

설치 스크립트는 go 및 Terraform CLI 도구로 작성된 실행 파일을 사용하여 빈 프로젝트를 가져오고 여기에 애플리케이션을 설치합니다. 출력은 작동하는 애플리케이션과 부하 분산 IP 주소의 URL입니다.

./main.tf

서비스 사용 설정

Google Cloud 서비스는 기본적으로 프로젝트에서 사용 중지되어 있습니다. 여기에서 솔루션을 사용하려면 다음을 활성화해야 합니다.

  • Compute Engine - 가상 머신 및 네트워킹
variable "gcp_service_list" {
    description = "The list of apis necessary for the project"
    type        = list(string)
    default = [
        "compute.googleapis.com",
    ]
}

resource "google_project_service" "all" {
  for_each                   = toset(var.gcp_service_list)
  project                    = var.project_number
  service                    = each.key
  disable_dependent_services = false
  disable_on_destroy         = false
}

가상 머신 만들기

VM을 만듭니다.

resource "google_compute_instance" "default" {
  project      = var.project_id
  name         = "${var.basename}-instance"
  machine_type = "f1-micro"
  zone         = var.zone

  boot_disk {
    initialize_params {
      image = "centos-cloud/centos-8-v20210817"
    }
  }
  labels = {
    env        = "prod"
    app        = "myproduct"
    created_by = "terraform"
  }

  network_interface {
    network = "default"

    access_config {
      // Include this section to give the VM an external ip address
    }
  }
  service_account {
    // Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles.
    // This non production example uses the default compute service account.
    email  = local.sacompute
    scopes = ["cloud-platform"]
  }
}

운영 에이전트 설치

운영 에이전트는 Compute Engine 인스턴스에서 원격 분석을 수집하기 위한 기본 에이전트입니다. terraform을 사용하여 이를 설치하는 방법을 보여줍니다.

module "agent_policy" {
    source  = "terraform-google-modules/cloud-operations/google//modules/agent-policy"
    version = "~> 0.1.0"

    project_id = var.project_id
    policy_id  = "ops-agents-example-policy"
    agent_rules = [
        {
        type               = "ops-agent"
        version            = "current-major"
        package_state      = "installed"
        enable_autoupgrade = true
        },
    ]
    group_labels = [
        {
        env        = "prod"
        app        = "myproduct"
        created_by = "terraform"
        }
    ]

    os_types = [
        {
        short_name = "centos"
        version    = "8"
        },
    ]
}

결론

실행이 완료되면 이제 Google Cloud Logging에 이벤트를 로깅하도록 올바르게 구성된 VM이 설정됩니다. 또한 환경에 맞게 이 솔루션을 수정하거나 확장할 수 있도록 모든 코드가 준비되었습니다.