Gcloud-如何在服务器上自动安装gcloud? [英] Gcloud - How to automate installation of gcloud on a server?

查看:68
本文介绍了Gcloud-如何在服务器上自动安装gcloud?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个shell脚本,该脚本基本上完成了gcloud的所有安装步骤,如下所述:

I want to write a shell script which basically goes through all the installation steps for gcloud, as outlined at: https://cloud.google.com/sdk/?hl=en

但是,当您运行install.sh时,系统将要求您输入授权码,您的项目ID,以及是否要帮助改进Google Cloud.基本上,用户输入是必需的.

However, when you are run install.sh, you will be asked to enter an authorization code, your project-id, whether you want to help improve Google Cloud or not and so on. Basically user-inputs are required.

但是,如果我想在没有任何用户的机器上自动化安装过程,该怎么做?

But if I want to automate the installation process on a machine where there will not be any user, how can I do this?

推荐答案

这里有两个独立的问题.

There are two separate problems here.

首先,如何在没有提示的情况下进行安装:

First, how do you install without prompts:

  1. 下载google cloud sdk tar文件.可以在 https://cloud.google.com/sdk/上的curl命令下找到该文件.
  2. 解压缩并cd进入新创建的目录.
  3. 运行CLOUDSDK_CORE_DISABLE_PROMPTS=1 ./install.sh(或install.bat)
  1. Download the google cloud sdk tar file. This can be found right under the curl command on https://cloud.google.com/sdk/
  2. Untar and cd into the newly created directory.
  3. run CLOUDSDK_CORE_DISABLE_PROMPTS=1 ./install.sh (or install.bat)

这将禁用所有提示.如果您不喜欢它回答提示的方式,则可以用标志预先回答它们.如果您回答所有问题,则不需要设置CLOUDSDK_CORE_DISABLE_PROMPTS环境变量.运行./install.sh --help以获得标志列表.

This disables all prompts. If you don't like the way it answers the prompts, you can pre-answer them with flags. If you preanswer all the questions, you don't need the CLOUDSDK_CORE_DISABLE_PROMPTS environment variable set. Run ./install.sh --help for a list of flags.

现在您已经安装了它,如何进行身份验证?

Now that you have it installed, how do you auth it?

如果您使用的是GCE,则可以自动使用计算机本身上的凭据.如果没有,则需要进行一些设置.

If you are on GCE, you can use the credentials on the machine itself automatically. If not, some setup is required.

由于这些是自动安装,因此您要为它们提供服务器密钥.如果有人参与,他就可以按照正常流程进行操作.

Since these are automated installs, you want to give them a server key. If there was a human involved, he can just proceed through the normal flow.

可以从开发人员控制台的"APIs& auth->凭据"下下载密钥.单击新凭据->服务帐户密钥". Google建议您使用JSON密钥.

Keys can be downloaded from the developer console under "APIs & auth -> Credentials". Click "New credentials -> Service account key". Google recommends you use a JSON key.

拥有该密钥后,需要将其移至新服务器并运行:

When you have that key, you need to move it to the new server and run:

gcloud auth activate-service-account --key-file servicekey.json
gcloud config set project MYPROJECT

这篇关于Gcloud-如何在服务器上自动安装gcloud?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆