[英]How to create a VM instance on GCP from a snapshot using the nodejs google-cloud/compute tool
[英]How to run bash script in an already created/exisitng VM in GCP using NodeJS?
我浏览了Nodejs-GCP-Compute-Github文档,并使用示例代码创建了一个新的VM,并使用NodeJS和Npm模块列出了现有的VM。
现在,我想连接到现有的VM并运行一个小的bash脚本,以调用一些命令(主要是git clone
或curl
在VM中运行文件。
我在@google-cloud/compute
中找不到连接到现有VM并执行某些操作的方法。
我们有这种方法吗?
是否可以使用Nodejs以其他方式执行此操作?
我想到两种不同的方法:
您可以将公钥添加到实例,然后使用节点ssh
库( https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys )通过ssh
连接到它
创建实例时,为其设置启动脚本 。 这可以通过将createVM
的第二个参数(config) createVM
为类似的方式来完成:
{
os: 'ubunntu',
metadata: {
'startup-script': 'your commands'
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.