2017-06-18 33 views

回答

0

看起來你試圖在虛擬機上啓動Jupyter筆記本服務器,並想使用虛擬機的外部IP訪問它(假設你沒有禁用虛擬機上的外部IP選項)。

你需要做到以下幾點:

  1. 修改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訪問這些實例的防火牆規則。標籤 也反映在元數據服務器中,因此您可以將它們用於在您的實例上運行的 應用程序。當您創建防火牆 規則時,您可以提供sourceRangessourceTags,但不能同時提供。

    # 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來詳細解釋。

    0

    您還可以「創建防火牆規則」來允許您的jupyter c.NotebookApp.port號碼。
    refer this image set 協議和端口tcp:<jupyter port number>