如何更改 GCE 实例的机器类型?
How to change machine type of GCE instance?
因为没有任何直接选项可以更改机器类型,所以我必须创建一个新实例。要使我安装的 configuration/software 保持不变,需要执行哪些步骤?
更新答案
我不确定它何时启动,但现在可以更改机器类型,而无需删除实例并从头开始重新创建它,根据 docs:
You can change the machine type of a stopped instance if it is not part of a managed instance group.
以下是使用 gcloud
执行此操作的方法:
$ gcloud compute instances set-machine-type INSTANCE_NAME \
--machine-type NEW_MACHINE_TYPE
此外,请注意有关移动到 smaller instance types 的警告:
If you move from a machine type with more resources to a machine type with fewer resources, such as moving from a e2-standard-8
machine type to a e2-standard-2
, you could run into hardware resource issues or performance limitations because smaller machine types are less powerful than larger machine types. Make sure that your new machine type is able to support any applications or services that are currently running on the instance, or that you update your services and applications to run on the smaller machine types.
原始答案(已过时)
您无法即时更改 VM 的实例类型。要升级或降级 VM 类型,您应该执行以下操作:
非常重要: 确保在关闭 VM 时不要删除 VM 的引导磁盘;见 this answer for details
如果您通过 Google Developers Console or via gcloud
on the CLI by using the --keep-disks
option or by having already set those disks to not auto-delete as described in this answer:
执行此操作,请在考虑步骤 #1 中的信息的同时彻底关闭 VM
gcloud compute instances delete VM \
--keep-disks=all \
--project $PROJECT
--zone $ZONE
请注意 --keep-disks
接受以下任何选项:boot
、data
或 all
。在您的情况下,您至少需要 boot
,但如果您附加了其他磁盘,则需要指定 all
。有关详细信息,请参阅 docs。
创建一个新的 VM 并选择一个 larger/smaller 实例类型:同样,这可以通过 CLI 上的 Google Developers Console 或 gcloud
来完成,而不是创建新的启动磁盘,select 来自原始 VM 的启动磁盘,例如,
gcloud compute instances create $VM \
--disk name=${DISK_NAME},boot=yes \
--machine-type ${MACHINE_TYPE} \
--project $PROJECT
--zone $ZONE
有关详细信息,请参阅 docs。
1) 删除要升级的实例,保留启动盘。
gcloud compute instances delete <instance-name> --keep-disks boot
2) 现在从这个启动盘创建映像
gcloud compute images create <any-image-name> --source-disk <instance-name>
3) 现在检查图像列表
gcloud compute images list
4) 现在从开发人员控制台或使用 gcloud compute 创建新实例
和select您的映像作为启动盘。
5) 完成。
Here 就是 link.
截至今天,可以在 Google Compute Engine 上看到此功能。您将需要停止该实例,然后编辑该实例。这将为您提供机器类型的下拉菜单
https://cloud.google.com/sdk/gcloud/reference/alpha/compute/instances/set-machine-type?hl=en
因为没有任何直接选项可以更改机器类型,所以我必须创建一个新实例。要使我安装的 configuration/software 保持不变,需要执行哪些步骤?
更新答案
我不确定它何时启动,但现在可以更改机器类型,而无需删除实例并从头开始重新创建它,根据 docs:
You can change the machine type of a stopped instance if it is not part of a managed instance group.
以下是使用 gcloud
执行此操作的方法:
$ gcloud compute instances set-machine-type INSTANCE_NAME \
--machine-type NEW_MACHINE_TYPE
此外,请注意有关移动到 smaller instance types 的警告:
If you move from a machine type with more resources to a machine type with fewer resources, such as moving from a
e2-standard-8
machine type to ae2-standard-2
, you could run into hardware resource issues or performance limitations because smaller machine types are less powerful than larger machine types. Make sure that your new machine type is able to support any applications or services that are currently running on the instance, or that you update your services and applications to run on the smaller machine types.
原始答案(已过时)
您无法即时更改 VM 的实例类型。要升级或降级 VM 类型,您应该执行以下操作:
非常重要: 确保在关闭 VM 时不要删除 VM 的引导磁盘;见 this answer for details
如果您通过 Google Developers Console or via
执行此操作,请在考虑步骤 #1 中的信息的同时彻底关闭 VMgcloud
on the CLI by using the--keep-disks
option or by having already set those disks to not auto-delete as described in this answer:gcloud compute instances delete VM \ --keep-disks=all \ --project $PROJECT --zone $ZONE
请注意 --keep-disks
接受以下任何选项:boot
、data
或 all
。在您的情况下,您至少需要 boot
,但如果您附加了其他磁盘,则需要指定 all
。有关详细信息,请参阅 docs。
创建一个新的 VM 并选择一个 larger/smaller 实例类型:同样,这可以通过 CLI 上的 Google Developers Console 或
gcloud
来完成,而不是创建新的启动磁盘,select 来自原始 VM 的启动磁盘,例如,gcloud compute instances create $VM \ --disk name=${DISK_NAME},boot=yes \ --machine-type ${MACHINE_TYPE} \ --project $PROJECT --zone $ZONE
有关详细信息,请参阅 docs。
1) 删除要升级的实例,保留启动盘。
gcloud compute instances delete <instance-name> --keep-disks boot
2) 现在从这个启动盘创建映像
gcloud compute images create <any-image-name> --source-disk <instance-name>
3) 现在检查图像列表
gcloud compute images list
4) 现在从开发人员控制台或使用 gcloud compute 创建新实例
和select您的映像作为启动盘。
5) 完成。
Here 就是 link.
截至今天,可以在 Google Compute Engine 上看到此功能。您将需要停止该实例,然后编辑该实例。这将为您提供机器类型的下拉菜单
https://cloud.google.com/sdk/gcloud/reference/alpha/compute/instances/set-machine-type?hl=en