가상 머신(VM) 인스턴스에는 4개의 가상 직렬 포트가 있습니다. 인스턴스의 운영체제, BIOS, 기타 시스템 수준 항목은 보통 직렬 포트에 출력을 쓰므로 직렬 포트 출력은 장애, 부팅 실패, 시작 또는 종료 문제를 해결하는 데 유용합니다.
이 페이지에서는 인스턴스가 중지되거나 삭제된 후에도 Cloud Logging을 사용하여 직렬 포트 출력을 보존하는 방법을 포함하여 직렬 포트 출력을 보는 방법을 설명합니다. 인스턴스가 실행 중일 때 직렬 포트에 명령어를 전송해야 하는 경우 직렬 콘솔과 상호작용을 참조하세요.
직렬 포트 출력은 Google Cloud 콘솔, gcloud CLI, REST를 통해 액세스할 수 있지만 VM 인스턴스가 실행되는 동안에만 액세스할 수 있습니다. 로그는 포트당 최근 1MB 출력으로 제한됩니다.
기본적으로 Cloud Logging에 대한 직렬 포트 출력 로깅이 중지되어 있습니다. Cloud Logging에 직렬 포트 출력 로깅 기능이 조직에서 제한되지 않으면 serial-port-logging-enable 메타데이터 항목을 true 또는 false로 설정하여 프로젝트와 개별 VM 인스턴스의 직렬 포트 출력 로깅을 사용 설정하거나 중지할 수 있습니다.
프로젝트 차원 메타데이터 항목을 설정하면 프로젝트의 모든 VM 인스턴스가 해당 설정을 암시적으로 상속합니다. 인스턴스 메타데이터 항목을 설정하면 프로젝트 설정과 관계없이 해당 VM에만 메타데이터 항목이 사용 설정됩니다.
Google Cloud Console, gcloud CLI, Compute Engine API를 사용하여 메타데이터 항목을 설정할 수 있습니다. 자세한 내용은 커스텀 메타데이터 설정을 참조하세요.
예를 들어 다음 gcloud CLI 명령어는 프로젝트의 Cloud Logging에 직렬 포트 출력 로깅을 사용 설정합니다.
Cloud Logging 내에서 제외 필터를 만들어 로그 탐색기에서 특정 직렬 포트 항목을 삭제할 수 있습니다. 예를 들어 프로젝트 차원 메타데이터 항목이 serial-port-logging-enable=true로 설정된 경우 고급 필터를 사용하여 특정 VM 인스턴스에 대해 직렬 포트 출력 로깅을 사용 중지할 수 있습니다.
Google Cloud 리소스의 특정 구성을 제한하는 조직 정책을 설정하여 전체 조직에 대해 Cloud Logging으로의 직렬 포트 출력 로깅을 사용 중지할 수 있습니다. 구체적으로 constraints/compute.disableSerialPortLogging과 같은 불리언 제약조건을 설정합니다. 자세한 내용은 조직 정책 만들기 및 관리를 참조하세요.
constraints/compute.disableSerialPortLogging을 true로 설정하여 직렬 포트 로깅을 사용 중지해도 소급 적용되지 않습니다. Cloud Logging에 직렬 포트 로깅을 사용 설정하는 메타데이터 항목이 있는 기존 VM 인스턴스의 경우 해당 인스턴스에 대해 메타데이터를 재설정하지 않는 한 Cloud Logging에 계속 로깅됩니다.
이러한 조직 제약조건을 true로 설정한 후에는 조직 내 어느 인스턴스에도 Cloud Logging에 대한 직렬 포트 출력 로깅을 사용 설정하도록 인스턴스 또는 프로젝트 메타데이터를 설정할 수 없습니다.
직렬 포트 출력은 오픈소스 Abseil C++ 라이브러리의 CHexEscape() 메서드를 사용하여 이스케이프 처리되므로 UTF8 이외의 문자는 16진수 문자열로 인코딩됩니다. 해당하는 CUnescape() 메서드를 사용하여 직렬 포트로 전송된 정확한 출력을 가져올 수 있습니다.
일반적인 직렬 포트 오류
다음은 직렬 포트 출력에서 발생할 수 있는 일반적인 오류의 예시입니다.
IPv6 구성 오류
IPv6이 구성되지 않으면 OS 저널 로그에서 다음 오류가 발생할 수 있습니다.
ERROR addresses.go:301 Error configuring IPv6: Internet Systems Consortium DHCP Client 4.2.5
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-08-18(UTC)"],[[["\u003cp\u003eVM instances have four virtual serial ports that output data useful for troubleshooting crashes, failed boots, and other system-level issues.\u003c/p\u003e\n"],["\u003cp\u003eSerial port output can be viewed in real-time through the Google Cloud console, gcloud CLI, and REST, but is limited to the most recent 1 MB of output per port.\u003c/p\u003e\n"],["\u003cp\u003eCloud Logging can be enabled to retain serial port output beyond instance runtime, providing the first 50 GiB per month for free, and logs are kept for 30 days.\u003c/p\u003e\n"],["\u003cp\u003eYou can enable or disable serial port output logging for projects or individual VM instances using metadata settings, or disable the feature for an entire organization through organization policies.\u003c/p\u003e\n"],["\u003cp\u003eNon-UTF8 characters within the serial port output are encoded as hex strings and can be decoded to reveal their original form using the \u003ccode\u003eCUnescape()\u003c/code\u003e method.\u003c/p\u003e\n"]]],[],null,["*** ** * ** ***\n\nA virtual machine (VM) instance has four virtual serial ports. The instance's\noperating system, BIOS, and other system-level entities often write output to\nthe serial ports, which makes serial port output useful for troubleshooting\ncrashes, failed boots, startup issues, or shutdown issues.\n\nThis page describes methods to *view* serial port output, including using\nCloud Logging to retain serial port output even after an instance is\nstopped or deleted. If you need to *send* commands to a serial port while an\ninstance is running, see\n[Interacting with the serial console](/compute/docs/instances/interacting-with-serial-console).\n\nSerial port output is accessible through the Google Cloud console, the\ngcloud CLI, and REST, but only while the VM instance\nis running. Logs are limited to the most recent 1 MB of output per port.\n\nIf you enable serial port output logging, Cloud Logging [provides the first\n50 gibibytes (GiB) per month of logging for free](/stackdriver/pricing) and\nretains logs for [30 days](/logging/quotas#logs_retention_periods).\n\nBefore you begin\n\n- If you want to log serial port output in Cloud Logging, familiarize yourself with [Cloud Logging](/logging).\n- If you haven't already, set up [authentication](/compute/docs/authentication). Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:\n\n Select the tab for how you plan to use the samples on this page: \n\n Console\n\n\n When you use the Google Cloud console to access Google Cloud services and\n APIs, you don't need to set up authentication.\n\n gcloud\n 1.\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n After installation,\n [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command:\n\n ```bash\n gcloud init\n ```\n\n\n If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n | **Note:** If you installed the gcloud CLI previously, make sure you have the latest version by running `gcloud components update`.\n 2. [Set a default region and zone](/compute/docs/gcloud-compute#set_default_zone_and_region_in_your_local_client).\n\n REST\n\n\n To use the REST API samples on this page in a local development environment, you use the\n credentials you provide to the gcloud CLI.\n 1. [Install](/sdk/docs/install) the Google Cloud CLI. After installation, [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command: \n\n ```bash\n gcloud init\n ```\n 2. If you're using an external identity provider (IdP), you must first [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n\n For more information, see\n [Authenticate for using REST](/docs/authentication/rest)\n in the Google Cloud authentication documentation.\n\nEnabling and disabling serial port output logging\n\nYou can control whether your instances send serial port output to\nCloud Logging by\n[setting project- or instance-level metadata](#setting_project_and_instance_metadata).\nYou can also disable the feature for all of the users in your organization\nby [setting an organization policy](#setting_an_organization_policy).\n| **Note:** Serial port output is useful for troubleshooting VM crashes, failed boots, and startup or shutdown issues. Disabling these logs might limit Google's ability to troubleshoot such issues.\n\nSetting project and instance metadata\n\nBy default, serial port output logging to Cloud Logging is disabled. If serial port output logging to Cloud Logging is not\n[constrained for your organization](#setting_an_organization_policy),\nthen you can enable or disable it for projects and for individual VM\ninstances by setting the `serial-port-logging-enable` metadata entry to `true`\nor `false`.\n\nIf you set a project-wide metadata entry, all VM instances in the project\ninherit that setting implicitly. If you set an instance metadata entry, the\nmetadata entry is enabled for that VM only, regardless of the project setting.\n\nYou can set a metadata entry by using the Google Cloud console, the\ngcloud CLI, or the Compute Engine API. For more information, see\n[Setting custom metadata](/compute/docs/metadata/setting-custom-metadata).\n\nFor example, the following gcloud CLI command enables serial port\noutput logging to Cloud Logging for your project: \n\n```\ngcloud compute project-info add-metadata \\\n --metadata serial-port-logging-enable=true\n```\n\nSimilarly, the following gcloud CLI command enables serial port output logging\nto Cloud Logging for a specific instance instead: \n\n```\ngcloud compute instances add-metadata INSTANCE_NAME \\\n --metadata serial-port-logging-enable=true\n```\n\nTo disable serial port output logging to Cloud Logging, set\n`serial-port-logging-enable` to `false`: \n\n```\ngcloud compute instances add-metadata INSTANCE_NAME \\\n --metadata serial-port-logging-enable=false\n```\n\nExclusion filters\n\nFrom within Cloud Logging, you can\n[create an exclusion filter](/logging/docs/exclusions#exclusion-filters) to\nremove specific serial port entries from the Logs Explorer. For example, with\na project-wide metadata entry that is set to `serial-port-logging-enable=true`,\nyou can disable serial port output logging for specific VM instances by using\nan advanced filter: \n\n```\nlogName = \"projects/PROJECT_ID/logs/serialconsole.googleapis.com%2Fserial_port_1_output\"\nresource.type = \"gce_instance\"\nresource.labels.instance_id != \"INSTANCE_1_ID\"\nresource.labels.instance_id != \"INSTANCE_2_ID\"\n```\n\nSetting an organization policy\n\nYou can disable serial port output logging to Cloud Logging for your entire\norganization by setting an\n[Organization Policy](/resource-manager/reference/rest/v1/Policy), which\nconstrains certain configurations of Google Cloud resources. Specifically,\nset the following boolean constraint:\n`constraints/compute.disableSerialPortLogging`. For more information, see\n[Creating and managing organization policies](/resource-manager/docs/organization-policy/creating-managing-policies#creating_and_editing_policies).\n\nDisabling serial port logging by setting\n`constraints/compute.disableSerialPortLogging` to `true` is not\nretroactive. Existing VM instances with a metadata entry that enables\nserial port logging to Cloud Logging continue to log to Cloud Logging\nunless you [reset the metadata](#setting_project_and_instance_metadata) for\nthose instances.\n\nAfter setting this organization constraint to `true`, you cannot set instance or\nproject metadata to enable serial port output logging to Cloud Logging for\nany instances within the organization.\n\nViewing serial port output \n\nConsole\n\n1. In the Google Cloud console, go to the **VM instances** page.\n\n [Go to the VM instances page](https://console.cloud.google.com/compute/instances)\n2. Select the VM instance for which you want to view serial port output.\n\n3. Under **Logs** , click **Serial port 1** , **2** , **3** , or **4** .\n System-level entities typically use the first serial port (port 1), which\n is also known as the\n [serial console](/compute/docs/instances/interacting-with-serial-console).\n\ngcloud\n\nUse the [`gcloud compute instances get-serial-port-output` command](/sdk/gcloud/reference/compute/instances/get-serial-port-output). \n\n```\ngcloud compute instances get-serial-port-output INSTANCE_NAME \\\n --port PORT \\\n --start START \\\n --zone ZONE\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eINSTANCE_NAME\u003c/var\u003e: the name of the instance.\n- \u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e: the number of the port (`1`, `2`, `3`, or `4`) for which you want to view output. System-level entities typically use the first serial port (port 1), which is also known as the serial console. By default, the output of the first serial port is returned.\n- \u003cvar translate=\"no\"\u003eSTART\u003c/var\u003e: the byte index (zero-based) of the first byte you want returned. Use this flag if you want to continue getting the output from a previous request that was too long to return in one attempt.\n- \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e: the zone of your instance.\n\nREST\n\nIn the API, create a `get` request to the\n[`instances.getSerialPortOutput` method](/compute/docs/reference/rest/v1/instances/getSerialPortOutput). \n\n```\nGET https://compute.googleapis.com/compute/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/serialPort\n```\n\nCloud Logging\n\n1. [Enable serial port logging to Cloud Logging](#enable-stackdriver).\n2. Go to the **VM instances** page.\n\n [Go to the VM instances page](https://console.cloud.google.com/compute/instances)\n3. Select the VM instance for which you want to view startup agent logs.\n\n4. Under **Logs** , click **Cloud Logging** to view Cloud Logging\n logs.\n\nFor more information, including information about filtering, see\n[Using the Logs Explorer](/logging/docs/view/logs-explorer-interface).\n\nHandling non-UTF8 characters\n\nSerial port output is escaped by using the open source\n[Abseil](https://github.com/abseil) C++ library's\n[`CHexEscape()` method](https://github.com/abseil/abseil-cpp/blob/master/absl/strings/escaping.h#L92),\nso non-UTF8 characters are encoded as hex strings. You can use the corresponding\n[`CUnescape()` method](https://github.com/abseil/abseil-cpp/blob/master/absl/strings/escaping.h#L38)\nto get the exact output that was sent to the serial port.\n\nCommon serial port errors\n\nThe following are examples of common errors you might encounter in serial port output.\n\nError configuring IPv6\n\nThe following error might occur in OS journal logs when IPv6 isn't configured: \n\n```\nERROR addresses.go:301 Error configuring IPv6: Internet Systems Consortium DHCP Client 4.2.5\n```\n\nIgnore this error. This error doesn't affect your VM."]]