1

我想在 Compute Engine 中使用 Google Cloud SDK(包括 App Engine 的 Python 扩展),这样我就可以在虚拟机中复制我的本地开发设置。即在 VM 上运行本地dev_appserver.py和单元测试,或将新的应用程序版本部署到 Google App Engine。

从默认的 Ubuntu 16.04 映像和(机器类型n1-standard-1)创建新的 VM 实例后,我注意到它gcloud已经预安装。

anh@ani-dev-2:~$ gcloud components list

Your current Cloud SDK version is: 163.0.0
The latest available version is: 169.0.0

┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                   Components                                                   │
├──────────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬───────────┤
│      Status      │                         Name                         │            ID            │    Size   │
├──────────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼───────────┤
│ Update Available │ BigQuery Command Line Tool                           │ bq                       │   < 1 MiB │
│ Update Available │ Cloud SDK Core Libraries                             │ core                     │   6.7 MiB │
│ Update Available │ Cloud Storage Command Line Tool                      │ gsutil                   │   3.0 MiB │
│ Not Installed    │ App Engine Go Extensions                             │ app-engine-go            │  98.0 MiB │
│ Not Installed    │ Cloud Bigtable Command Line Tool                     │ cbt                      │   4.1 MiB │
│ Not Installed    │ Cloud Bigtable Emulator                              │ bigtable                 │   3.5 MiB │
│ Not Installed    │ Cloud Datalab Command Line Tool                      │ datalab                  │   < 1 MiB │
│ Not Installed    │ Cloud Datastore Emulator                             │ cloud-datastore-emulator │  15.4 MiB │
│ Not Installed    │ Cloud Datastore Emulator (Legacy)                    │ gcd-emulator             │  38.1 MiB │
│ Not Installed    │ Cloud Pub/Sub Emulator                               │ pubsub-emulator          │  33.2 MiB │
│ Not Installed    │ Emulator Reverse Proxy                               │ emulator-reverse-proxy   │  14.5 MiB │
│ Not Installed    │ Google Container Local Builder                       │ container-builder-local  │   3.7 MiB │
│ Not Installed    │ Google Container Registry's Docker credential helper │ docker-credential-gcr    │   2.2 MiB │
│ Not Installed    │ gcloud Alpha Commands                                │ alpha                    │   < 1 MiB │
│ Not Installed    │ gcloud Beta Commands                                 │ beta                     │   < 1 MiB │
│ Not Installed    │ gcloud app Java Extensions                           │ app-engine-java          │ 128.1 MiB │
│ Not Installed    │ gcloud app Python Extensions                         │ app-engine-python        │   6.5 MiB │
│ Not Installed    │ kubectl                                              │ kubectl                  │  16.0 MiB │
│ Installed        │ Default set of gcloud commands                       │ gcloud                   │           │
└──────────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴───────────┘

直观地说,我尝试安装缺少的app-engine-python组件。

anh@ani-dev-2:~$ gcloud components install app-engine-python
You cannot perform this action because this Cloud SDK installation is 
managed by an external package manager.  If you would like to get the 
latest version, please see our main download page at:

https://cloud.google.com/sdk/
ERROR: (gcloud.components.install) The component manager is disabled for 
this installation

据我了解,有其他可用的安装方法(yum、debian)和 deb 用于 VM 映像,这就是组件管理器被禁用的原因:

anh@ani-dev-2:~$ dpkg -s google-cloud-sdk
Package: google-cloud-sdk
Status: install ok installed
Priority: optional
Section: partner/admin
Installed-Size: 93228
Maintainer: Canonical CPC Team <cpc@canonical.com>
Architecture: all
Version: 163.0.0-0ubuntu1~16.04.0
Depends: findutils, python2.7, python:any (>= 2.6.6-7~), python-crcmod, python-google-compute-engine
Conflicts: gsutils
Conffiles:
 /etc/bash_completion.d/completion.bash.inc 860b91bfb6a0e6b513321ea6ca429e4c
Description: Google Cloud SDK for interacting with Google Cloud services.
 The command-line tools for Google App Engine, Compute Engine,
 Cloud Storage, BigQuery, Cloud SQL, and Cloud DNS are bundled as part of
 the Cloud SDK.
 .
 This is a packaged distribution of the Google Cloud SDK. For up-to-date
 versions please see https://developers.google.com/cloud/sdk.
Homepage: https://developers.google.com/cloud/sdk/

因此,我已google-cloud-sdk-app-engine-python通过 apt-get 成功安装了缺少的组件,如文档安装云 SDK中所述。好像是预装的 Cloud SDK 包 163.0.0 被最近的版本 169.0.0 替换了,现在安装了 python 组件。

anh@ani-dev-2:~$ gcloud components list

Your current Cloud SDK version is: 169.0.0
The latest available version is: 169.0.0

┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                  Components                                                 │
├───────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬───────────┤
│     Status    │                         Name                         │            ID            │    Size   │
├───────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼───────────┤
│ Not Installed │ App Engine Go Extensions                             │ app-engine-go            │  98.0 MiB │
│ Not Installed │ Cloud Bigtable Command Line Tool                     │ cbt                      │   4.1 MiB │
│ Not Installed │ Cloud Bigtable Emulator                              │ bigtable                 │   3.5 MiB │
│ Not Installed │ Cloud Datalab Command Line Tool                      │ datalab                  │   < 1 MiB │
│ Not Installed │ Cloud Datastore Emulator                             │ cloud-datastore-emulator │  15.4 MiB │
│ Not Installed │ Cloud Datastore Emulator (Legacy)                    │ gcd-emulator             │  38.1 MiB │
│ Not Installed │ Cloud Pub/Sub Emulator                               │ pubsub-emulator          │  33.2 MiB │
│ Not Installed │ Emulator Reverse Proxy                               │ emulator-reverse-proxy   │  14.5 MiB │
│ Not Installed │ Google Container Local Builder                       │ container-builder-local  │   3.7 MiB │
│ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr    │   2.2 MiB │
│ Not Installed │ gcloud app Java Extensions                           │ app-engine-java          │ 128.1 MiB │
│ Not Installed │ kubectl                                              │ kubectl                  │  16.0 MiB │
│ Installed     │ BigQuery Command Line Tool                           │ bq                       │   < 1 MiB │
│ Installed     │ Cloud SDK Core Libraries                             │ core                     │   6.7 MiB │
│ Installed     │ Cloud Storage Command Line Tool                      │ gsutil                   │   3.0 MiB │
│ Installed     │ Default set of gcloud commands                       │ gcloud                   │           │
│ Installed     │ gcloud Alpha Commands                                │ alpha                    │   < 1 MiB │
│ Installed     │ gcloud Beta Commands                                 │ beta                     │   < 1 MiB │
│ Installed     │ gcloud app Python Extensions                         │ app-engine-python        │   6.5 MiB │
└───────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴───────────┘
  1. 这种方法是在 Compute Engine 上添加 Cloud SDK 组件的推荐方法吗?

  2. 微型或小型机器类型是否也支持相同的方法?我认为,f1-micro(或g1-small)足以满足我的目的。但也许因为在较小的类型中,VM共享CPU,所以我无权更改安装。如果是这种情况,我是否应该在我的用户文件夹中手动安装一个额外的自定义 Cloud SDK,例如$HOME/google-cloud-sdk我在我的 Mac 上所做的那样?

PS 1

这是我在f1-micro(相同的 VM 映像)中执行相同步骤时的输出,我在两个新实例上尝试了两次:

anh@ani-dev-1:~$ sudo apt-get update && sudo apt-get install google-cloud-sdk
Hit:1 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]                             
Get:3 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]                           
Get:4 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial/main Sources [868 kB]                                  
Get:5 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial/restricted Sources [4,808 B]                           
Get:6 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial/universe Sources [7,728 kB]                            
Get:7 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]                                        
Hit:8 http://archive.canonical.com/ubuntu xenial InRelease                                                        
Get:9 http://packages.cloud.google.com/apt cloud-sdk-xenial InRelease [6,327 B]                                   
Get:10 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial/multiverse Sources [179 kB]                           
Get:11 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-updates/main Sources [273 kB]                         
Get:12 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-updates/restricted Sources [3,400 B]
Get:13 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-updates/universe Sources [171 kB]
Get:14 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-updates/multiverse Sources [7,232 B]
Get:15 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [632 kB]
Get:16 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-updates/main Translation-en [261 kB]
Get:17 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [8,048 B]
Get:18 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-updates/restricted Translation-en [2,688 B]
Get:19 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [529 kB]
Get:20 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [209 kB]
Get:21 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-backports/main Sources [3,396 B]
Get:22 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-backports/universe Sources [4,404 B]
Get:23 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [4,884 B]
Get:24 http://packages.cloud.google.com/apt cloud-sdk-xenial/main amd64 Packages [9,625 B]
Get:25 http://security.ubuntu.com/ubuntu xenial-security/main Sources [90.1 kB]  
Get:26 http://security.ubuntu.com/ubuntu xenial-security/restricted Sources [2,604 B]
Get:27 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [40.9 kB]
Get:28 http://security.ubuntu.com/ubuntu xenial-security/multiverse Sources [1,144 B]
Get:29 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [353 kB]
Get:30 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en [154 kB]
Get:31 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [166 kB]
Get:32 http://security.ubuntu.com/ubuntu xenial-security/universe Translation-en [86.8 kB]
Fetched 12.1 MB in 2s (4,922 kB/s)             
Reading package lists... Done
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  google-cloud-sdk-app-engine-java google-cloud-sdk-app-engine-python google-cloud-sdk-pubsub-emulator
  google-cloud-sdk-bigtable-emulator google-cloud-sdk-datastore-emulator kubectl
The following packages will be upgraded:
  google-cloud-sdk
1 upgraded, 0 newly installed, 0 to remove and 13 not upgraded.
Need to get 13.8 MB of archives.
After this operation, 10.7 MB of additional disk space will be used.
Get:1 http://packages.cloud.google.com/apt cloud-sdk-xenial/main amd64 google-cloud-sdk all 169.0.0-0 [13.8 MB]
Fetched 13.8 MB in 1s (11.4 MB/s)            
(Reading database ... 64568 files and directories currently installed.)
Preparing to unpack .../google-cloud-sdk_169.0.0-0_all.deb ...
Unpacking google-cloud-sdk (169.0.0-0) over (163.0.0-0ubuntu1~16.04.0) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up google-cloud-sdk (169.0.0-0) ...
Killed
dpkg: error processing package google-cloud-sdk (--configure):
 subprocess installed post-installation script returned error exit status 137
E: Sub-process /usr/bin/dpkg returned an error code (1)

PS 2

似乎安装过程被杀死的原因f1-micro是某种内存不足错误。请参阅: https ://serverfault.com/questions/862019/how-to-resolve-dpkg-error-processing-package-google-cloud-sdk 和https://groups.google.com/forum/#!topic/ gce-讨论/BBHc2QebbBw

但是,我可以用更大的机器类型来实现我的目标。

4

1 回答 1

1

apt-get是在 Ubuntu/Debian 系统中安装应用引擎组件的方式。

如果这是您的虚拟机之间的重复安装,您可能需要编写一个启动脚本来执行此安装。或将完成的安装保存为映像,具体取决于您的启动时间要求。

关于共享处理器,这根本不会影响您的安装。

于 2017-09-01T23:46:55.043 回答