如何在gcloud计算引擎中启动jupyter笔记本
问题描述:
我想使用来自谷歌云计算引擎的jupyter笔记本。当我尝试通过命令行启动它时,我无法使用我的浏览器打开笔记本。如何在gcloud计算引擎中启动jupyter笔记本
请让我知道如何做到这一点。
答
看起来你试图在虚拟机上启动Jupyter笔记本服务器,并想使用虚拟机的外部IP访问它(假设你没有禁用虚拟机上的外部IP选项)。
你需要做到以下几点:
- 修改
jupyter_notebook_config.py
在~/.jupyter
目录。请仔细检查what you need to modify以及secure your notebook server,因为Jupyter笔记本默认只侦听回送接口(即127.0.0.1
又名localhost
)。
最低组配置选项,你应该取消注释和
jupyter_notebook_config.py
编辑如下:# Set options for certfile, ip, password, and toggle off # browser auto-opening c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem' c.NotebookApp.keyfile = u'/absolute/path/to/your/certificate/mykey.key' # Set ip to '*' to bind on all interfaces (ips) for the public server c.NotebookApp.ip = '*' c.NotebookApp.password = u'sha1:bcd259ccf...<your hashed password here>' c.NotebookApp.open_browser = False # It is a good idea to set a known, fixed port for server access c.NotebookApp.port = 9999
- 您将需要修改防火墙规则允许入口流量到您在上一步中配置的端口(在VM上)。为此,我将推荐tag based firewall rules,以便您可以控制防火墙规则适用的虚拟机。
网络代码用于通过网络来识别哪些实例是 受到一定的防火墙规则和网络路由。例如,如果 有几个正在为大型网站提供服务的VM实例,请使用共享字或术语标记 这些实例,然后使用该标记 应用允许HTTP访问这些实例的防火墙规则。标签 也反映在元数据服务器中,因此您可以将它们用于在您的实例上运行的 应用程序。当您创建防火墙 规则时,您可以提供
sourceRanges
或sourceTags
,但不能同时提供。
# Assuming Jupyter notebook is running on port 9999
# Add a new tag based firewall rule to allow ingress tcp:9999
gcloud compute firewall-rules create rule-allow-tcp-9999 --source-ranges 0.0.0.0/0 --target-tags allow-tcp-9999 --allow tcp:9999
# Add the allow-tcp-9999 target tag to the VM named say 'vm-1'
gcloud compute instances add-tags vm-1 --tags allow-tcp-9999
# If you want to list all the GCE firewall rules
gcloud compute firewall-rules list
这可能需要几秒钟到几分钟,以使更改生效的。
或者,您也可以使用Google Cloud Console代替gcloud来配置防火墙规则。你可以通过this answer来详细解释。
答
您还可以“创建防火墙规则”来允许您的jupyter c.NotebookApp.port
号码。
refer this image set 协议和端口到tcp:<jupyter port number>