ssh AWS,Jupyter Notebook没有出现在Web浏览器上

时间:2017-10-04 16:43:35

标签: google-chrome amazon-web-services ssh deep-learning jupyter-notebook

我正在尝试使用ssh连接到AWS“用于Amazon Linux的深度学习AMI”,除了Jupyter Notebook之外,一切正常。这就是我得到的:

ssh -i ~/.ssh/id_rsa ec2-user@yy.yyy.yyy.yy

给了我

Last login: Wed Oct  4 18:01:23 2017 from 67-207-109-187.static.wiline.com

=============================================================================
       __|  __|_  )
       _|  (     /   Deep Learning AMI for Amazon Linux
      ___|\___|___|

The README file for the AMI ➜➜➜➜➜➜➜➜➜➜➜➜➜➜➜➜➜➜➜➜  /home/ec2-user/src/README.md
Tests for deep learning frameworks ➜➜➜➜➜➜➜➜➜➜➜➜   /home/ec2-user/src/bin
=============================================================================

1 package(s) needed for security, out of 3 available
Run "sudo yum update" to apply all updates.
Amazon Linux version 2017.09 is available.

然后

[ec2-user@ip-xxx-xx-xx-xxx ~]$ jupyter notebook
[I 16:32:14.172 NotebookApp] Writing notebook server cookie secret to /home/ec2-user/.local/share/jupyter/runtime/notebook_cookie_secret
[I 16:32:14.306 NotebookApp] Serving notebooks from local directory: /home/ec2-user
[I 16:32:14.306 NotebookApp] 0 active kernels 
[I 16:32:14.306 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=74e2ad76eee284d70213ba333dedae74bf043cce331257e0
[I 16:32:14.306 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 16:32:14.307 NotebookApp] No web browser found: could not locate runnable browser.
[C 16:32:14.307 NotebookApp] 


Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
    http://localhost:8888/?token=74e2ad76eee284d70213ba333dedae74bf043cce331257e0

复制http://localhost:8888/?token=74e2ad76eee284d70213ba333dedae74bf043cce331257e0并获取

can’t establish a connection to the server at localhost:8888”。在Firefox上,

This site can’t be reached localhost refused to connect”。在Chrome上 enter image description here

enter image description here

此外, jupyter notebook --ip=yy.yyy.yyy.yy --port=8888给出了

Traceback (most recent call last):
  File "/usr/bin/jupyter-notebook", line 11, in <module>
    sys.exit(main())
  File "/usr/lib/python3.4/dist-packages/jupyter_core/application.py", line 267, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/usr/lib/python3.4/dist-packages/traitlets/config/application.py", line 657, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-7>", line 2, in initialize
  File "/usr/lib/python3.4/dist-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/lib/python3.4/dist-packages/notebook/notebookapp.py", line 1296, in initialize
    self.init_webapp()
  File "/usr/lib/python3.4/dist-packages/notebook/notebookapp.py", line 1120, in init_webapp
    self.http_server.listen(port, self.ip)
  File "/usr/lib64/python3.4/dist-packages/tornado/tcpserver.py", line 142, in listen
    sockets = bind_sockets(port, address=address)
  File "/usr/lib64/python3.4/dist-packages/tornado/netutil.py", line 197, in bind_sockets
    sock.bind(sockaddr)
OSError: [Errno 99] Cannot assign requested address

请注意这确实有用(仅适用于MXNet吗?我不熟悉MXNet)Jupyter_MXNet

2 个答案:

答案 0 :(得分:3)

嗯,这里发生的事情很少。

问题#1 - Localhost

  1. 正如Y. Hernandez所说,您试图错误地访问该网址。您应该将localhost替换为您的AWS VM的公共IP地址(您用于ssh的IP)。
  2. 问题#2 - Jupyter需要正确的配置

    1. 但即便如此,这可能无法运行,因为Jupyter尚未完全配置开箱即用,您正在为Amazon Linux使用Deep Learning AMI。你需要完成以下这些步骤(当然还有很多其他的做同样的事情 - 这只是一种方式)。

    2. 配置Jupyter Notebook -

      $ jupyter notebook --generate-config
      
    3. 以.pem文件的形式为我们的连接创建认证。

      $ mkdir certs
      $ cd certs
      $ sudo openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
      
    4. 在运行最后一行后,您会被问到一些常见问题。只需用一些一般信息填写#或按Enter键。

    5. 接下来,我们需要完成编辑之前创建的Jupyter配置文件。所以改成.jupyter文件夹。为此,您可以使用nano或vi或您的fav编辑器。

      $ cd ~/.jupyter/
      
      $ nano jupyter_notebook_config.py
      
    6. 将此代码插入文件顶部 -

    7. -insert begin -

      c = get_config()
      
      # Notebook config this is where you saved your pem cert
      c.NotebookApp.certfile = u'/home/ubuntu/certs/mycert.pem' 
      # Run on all IP addresses of your instance
      c.NotebookApp.ip = '*'
      # Don't open browser by default
      c.NotebookApp.open_browser = False  
      # Fix port to 8888
      c.NotebookApp.port = 8888
      

      -insert end -

      保存文件

      1. cd出.jupyter文件夹

        $ cd
        
      2. 您可以为Jupyter设置单独的Notebook文件夹,也可以随身携带 选择,你可以启动Jupyter

        $ jupyter notebook
        
      3. 在您的浏览器上使用您的虚拟机IP地址和终端中提供的令牌转到此URL

        http://VM-IPAddress:8888/?token=72385d6d854bb78b9b6e675f171b90afad47b3edcbaa414b

        如果您收到SSL错误,则使用https而不是http。

        https://VM-IPAddress:8888/?token=72385d6d854bb78b9b6e675f171b90afad47b3edcbaa414b

        问题#3 - 将无法启动Python解释器。

        如果您打算运行Python 2或3,则需要升级iPython。如果没有,一旦你启动Jupyter,你将看不到启动Python解释器的选项。您只会看到文本,文件夹和终端的选项。

        1. 升级iPython。为此,请关闭Jupyter并运行此升级命令。

          $ sudo pip install ipython --upgrade
          
        2. 重新启动Jupyter。

答案 1 :(得分:2)

localhost只有在尝试使用机器本身的jupyter(或者好吧,任何东西)时才会起作用。在这种情况下,您似乎正在尝试从另一台计算机访问它。

您可以使用开关 - ip = abcd 来执行此操作,其中 abcd 是您的EC2实例的公共地址(或使用 0.0.0.0 < / strong>让它在所有界面中监听。)

您还可以使用 - port = X 来定义要收听的特定端口号。

请记住,您的安全组必须允许从外部访问您选择的IP /端口。

例如:

jupyter notebook --ip = a.b.c.d --port = 8888