设置Compute Engine VM的环境变量 [英] Setting environment variable for a Compute Engine VM

本文介绍了设置Compute Engine VM的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Google Compute Engine上的虚拟机中设置一个环境变量.我需要设置的变量称为"GOOGLE_APPLICATION_CREDENTIALS",根据Google文档,我需要将其值设置为json文件的路径.我有两个问题:

I need to set an environment variable within my virtual machine on Google Compute Engine. The variable I need to set is called "GOOGLE_APPLICATION_CREDENTIALS"and according to Google documentation I need to set its value to the path of a json file. I have two questions:

1:我可以在GCP的Google Compute Engine界面内设置此变量吗?

1: Can I set this variable within the Google Compute Engine interface on GCP?

2:我可以使用System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", Resources.googlecredentials.credentials);吗?每当我尝试在本地计算机上设置此变量时,我都会使用此技术,但会将值设置为文件(本地目录)的路径.但是,因为我现在正在使用虚拟机,所以我想知道是否可以将环境变量设置为资源文件的实际内容?有利的是,这使我可以将凭据嵌入到实际的应用程序本身中.

2: Can I use System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", Resources.googlecredentials.credentials);? Whenever I try and set this variable on my local machine I use this technique, but I set the value to the path of the file (local directory). However, because I am now using a virtual machine, I was wondering, can I set the environment variable to the actual contents of a resource file? Advantageously, this allows me to embed the credentials into the actual app itself.

欢呼

推荐答案

您还可以编辑用户的个人资料:

you could also edit the user's profile:

nano ~/.bashrc

,甚至系统范围内的/etc/profile/etc/bash.bashrc/etc/environment

or even system-wide with /etc/profile, /etc/bash.bashrc, or /etc/environment

然后添加:

export GOOGLE_APPLICATION_CREDENTIALS=...

也可以使用

自定义元数据.而不是特定于GCE.

Custom Metadata can also be used, which is rather GCE specific.

这篇关于设置Compute Engine VM的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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