排解 Ubuntu Pro 註冊問題


有時 Compute Engine 無法自動註冊即付即用 Ubuntu Pro 授權。本文說明如何解決註冊問題,這類問題可能發生在執行隨用隨付 (PAYG) Ubuntu Pro 授權的 Compute Engine 虛擬機器 (VM) 執行個體上。

檢查註冊狀態

如要檢查授權是否已註冊,請連線至 VM 並執行下列指令:

sudo ua status

如果註冊成功,您會看到類似下列內容的輸出,且不需要採取進一步行動:

SERVICE          ENTITLED  STATUS    DESCRIPTION
cc-eal           yes       disabled  Common Criteria EAL2 Provisioning Packages
cis              yes       disabled  Security compliance and audit tools
esm-apps         yes       enabled   Expanded Security Maintenance for Applications
esm-infra        yes       enabled   Expanded Security Maintenance for Infrastructure
fips             yes       disabled  NIST-certified core packages
fips-updates     yes       disabled  NIST-certified core packages with priority security updates
livepatch        yes       enabled   Canonical Livepatch service

如果註冊失敗且 Ubuntu Pro 未註冊,您會看到類似下列的訊息:

This machine is not attached to an Ubuntu Pro subscription.

手動註冊授權

如果 Compute Engine 無法自動註冊 Ubuntu Pro 授權,您可以執行下列指令手動註冊授權:

sudo pro auto-attach

輸出結果會與下列內容相似:

  • 註冊成功

    This machine is already attached to PROJECT_ID
    To use a different subscription first run: sudo pro detach.
    
  • 註冊失敗

    Internal Server Error
    

排解授權註冊問題

如果無法手動註冊 Ubuntu Pro 授權,請按照下列步驟解決問題:

  1. 執行下列指令,檢查附加至 VM 的磁碟數量,確認 VM 能連上中繼資料伺服器:

    curl "http://metadata.google.internal/computeMetadata/v1/instance/disks/" -H "Metadata-Flavor: Google"
    

    輸出內容會與以下所示內容類似,顯示附加至 VM 的磁碟數量:

    0/
    1/
    2/
    

    如果輸出內容未顯示附加至 VM 的磁碟數量,請參閱「排解中繼資料伺服器存取問題」。

  2. 執行下列指令,確認 Google 客戶代理程式正在執行:

    systemctl status google-guest-agent.service
    

    輸出結果會與下列內容相似:

    ● google-guest-agent.service - Google Compute Engine Guest Agent
    Loaded: loaded (/lib/systemd/system/google-guest-agent.service; enabled;
    vendor preset: enabled)
    Active: active (running) since Thu 2023-04-20 16:35:11 PDT; 2h 12min ago
    Main PID: 4582 (google_guest_ag)
    Tasks: 10 (limit: 9525)
    

    如果未安裝或安裝失敗,請安裝或重新安裝訪客環境

  3. 從本機工作站執行下列指令,確認服務帳戶已附加至 VM:

    gcloud compute instances describe VM_NAME \
       --zone ZONE --format="table(serviceAccounts.email)"
    

    更改下列內容:

    • VM_NAME:VM 名稱
    • ZONE:VM 所在的可用區

    輸出結果會與下列內容相似:

    EMAIL: ['XXXXXXXX-compute@developer.gserviceaccount.com']
    

    記下服務帳戶的電子郵件地址。

  4. 執行下列查詢,檢查服務帳戶是否已啟用:

    gcloud logging read --freshness=90d "SERVICE_ACCOUNT_EMAIL protoPayload.methodName=google.iam.admin.v1.DisableServiceAccount"
    

    SERVICE_ACCOUNT_EMAIL 替換為與 VM 服務帳戶相關聯的電子郵件地址。

    輸出結果會與下列內容相似:

    insertId: 1ne5thkf13sxec
    logName: projects/testproject/logs/cloudaudit.googleapis.com%2Factivity
    protoPayload:
     '@type': type.googleapis.com/google.cloud.audit.AuditLog
    authenticationInfo:
    principalEmail: principalemail@google.com
    principalSubject: user:pricipalemail@google.com
    authorizationInfo:
     granted: true
    permission: iam.serviceAccounts.disable
    resource: projects/-/serviceAccounts/XXXXXXXXXXXXXX
    resourceAttributes:
      name: projects/-/serviceAccounts/XXXXXXXXXXXXXXXX
    methodName: google.iam.admin.v1.DisableServiceAccount
    request:
    '@type': type.googleapis.com/google.iam.admin.v1.DisableServiceAccountRequest
    name: projects/testproject/serviceAccounts/-compute@developer.gserviceaccount.com
    requestMetadata:
     destinationAttributes: {}
     requestAttributes:
       auth: {}
       time: '2024-01-25T21:37:55.748811275Z'
    resourceName: projects/-/serviceAccounts/XXXXXXXXXX
    response:
     '@type': type.googleapis.com/google.protobuf.Empty
     serviceName: iam.googleapis.com
     status: {}
    receiveTimestamp: '2024-01-25T21:37:56.409675900Z'
    resource:
    labels:
     email_id: -compute@developer.gserviceaccount.com
     project_id: testproject
     unique_id: 'XXXXXXXXXXXXXXXX'
    type: service_account
    severity: NOTICE
    timestamp: '2024-01-25T21:37:55.721215307Z'
    

    如果服務帳戶未啟用,請重新啟用

重新啟用服務帳戶後,請按照本文件「手動註冊授權」一節的說明,嘗試註冊授權。