更改iPython笔记本服务器/ Jupyter的默认端口

时间:2015-07-07 13:54:26

标签: port ipython ipython-notebook anaconda jupyter

我正在尝试在防火墙后面的机器上运行ipython notebook / jupyter服务器。唯一打开的端口是端口80.所以我想知道如何将默认端口从8890更改为80?

我已运行以下命令ipython profile create来创建个人资料。

然后编辑ipython_notebook_config.py并对其进行编辑以包含以下内容:

c = get_config()
c.NotebookApp.port = 80

当我尝试运行python notebook时。我收到以下错误:

ERROR: the notebook server could not be started because no available port could be found.

但是,似乎没有其他东西使用端口80.Apache不会在启动时启动并被禁用。我甚至使用netstat来查看每个端口的使用情况。

$ sudo netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address                 State       PID/Program name
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      1226/vsftpd     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1532/sshd       
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      3433/cupsd      
tcp        0      0 127.0.0.1:5984          0.0.0.0:*               LISTEN      1410/beam.smp   
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1653/mysqld     
tcp6       0      0 :::22                   :::*                    LISTEN      1532/sshd       
tcp6       0      0 ::1:631                 :::*                    LISTEN      3433/cupsd      
udp        0      0 0.0.0.0:52741           0.0.0.0:*                           796/avahi-daemon: r
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           796/avahi-daemon: r
udp        0      0 0.0.0.0:31114           0.0.0.0:*                           1105/dhclient   
udp        0      0 0.0.0.0:68              0.0.0.0:*                           1105/dhclient   
udp        0      0 xxx.xxx.xxx.xxx:123        0.0.0.0:*                           2607/ntpd       
udp        0      0 127.0.0.1:123           0.0.0.0:*                           2607/ntpd       
udp        0      0 0.0.0.0:123             0.0.0.0:*                           2607/ntpd       
udp        0      0 0.0.0.0:631             0.0.0.0:*                           1630/cups-browsed
udp6       0      0 :::5353                 :::*                                796/avahi-daemon: r
udp6       0      0 :::69                   :::*                                1607/in.tftpd   
udp6       0      0 :::24682                :::*                                1105/dhclient   
udp6       0      0 xxxx::xxxx:xxxx:xxxx:123 :::*                                2607/ntpd       
udp6       0      0 ::1:123                 :::*                                2607/ntpd       
udp6       0      0 :::123                  :::*                                2607/ntpd       
udp6       0      0 :::59559                :::*                                796/avahi-daemon: r
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name    Path
unix  2      [ ACC ]     STREAM     LISTENING     20483    3253/pulseaudio     /run/user/1003/pulse/native
unix  2      [ ACC ]     STREAM     LISTENING     18697    3179/gnome-session  @/tmp/.ICE-unix/3179
unix  2      [ ACC ]     STREAM     LISTENING     15765    2507/X              /tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     20481    3253/pulseaudio     /tmp/.esd-1003/socket
unix  2      [ ACC ]     STREAM     LISTENING     18698    3179/gnome-session  /tmp/.ICE-unix/3179
unix  2      [ ACC ]     STREAM     LISTENING     15764    2507/X              @/tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     10538    768/bluetoothd      /var/run/sdp
unix  2      [ ACC ]     STREAM     LISTENING     21564    3433/cupsd          /var/run/cups/cups.sock
unix  2      [ ACC ]     STREAM     LISTENING     10820    1653/mysqld         /var/run/mysqld/mysqld.sock
unix  2      [ ACC ]     STREAM     LISTENING     16666    3184/dbus-daemon    @/tmp/dbus-1gowauBlhV
unix  2      [ ACC ]     STREAM     LISTENING     14432    748/dbus-daemon     /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     8877     1/init              @/com/ubuntu/upstart
unix  2      [ ACC ]     STREAM     LISTENING     16698    3136/ibus-daemon    @/tmp/dbus-ue1VKkXx
unix  2      [ ACC ]     STREAM     LISTENING     12135    3005/gnome-keyring- /run/user/1003/keyring-htUkSg/control
unix  2      [ ACC ]     STREAM     LISTENING     14469    796/avahi-daemon: r /var/run/avahi-daemon/socket
unix  2      [ ACC ]     STREAM     LISTENING     10034    3102/dbus-daemon    @/tmp/dbus-SCYaEa0Hje
unix  2      [ ACC ]     STREAM     LISTENING     18577    3005/gnome-keyring- /run/user/1003/keyring-htUkSg/pkcs11
unix  2      [ ACC ]     STREAM     LISTENING     18581    3005/gnome-keyring- /run/user/1003/keyring-htUkSg/gpg
unix  2      [ ACC ]     STREAM     LISTENING     18583    3005/gnome-keyring- /run/user/1003/keyring-htUkSg/ssh
unix  2      [ ACC ]     STREAM     LISTENING     18569    3007/init           @/com/ubuntu/upstart-session/1003/3007
unix  2      [ ACC ]     SEQPACKET  LISTENING     11473    396/systemd-udevd   /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     10725    1572/acpid          /var/run/acpid.socket

6 个答案:

答案 0 :(得分:49)

ipython notebook --ip=0.0.0.0 --port=80 or
jupyter notebook --ip=0.0.0.0 --port=80

是我在流浪盒中运行ipython所做的。 (打开流浪盒上的端口以在我的主机mac上访问它)

usage: ipython [-h] [--certfile NOTEBOOKAPP.CERTFILE] [--ip NOTEBOOKAPP.IP]
               [--pylab [NOTEBOOKAPP.PYLAB]]
               [--log-level NOTEBOOKAPP.LOG_LEVEL]
               [--port-retries NOTEBOOKAPP.PORT_RETRIES]
               [--notebook-dir NOTEBOOKAPP.NOTEBOOK_DIR]
               [--config NOTEBOOKAPP.CONFIG_FILE]
               [--keyfile NOTEBOOKAPP.KEYFILE] [--port NOTEBOOKAPP.PORT]
               [--transport KERNELMANAGER.TRANSPORT]
               [--browser NOTEBOOKAPP.BROWSER] [--script] [-y] [--no-browser]
               [--debug] [--no-mathjax] [--no-script] [--generate-config]

如果端口已被占用,请查看阻止它的内容 - 在我的情况下,这是一个未正确终止的旧的ipython实例。我用这个命令把它们全部搞好了

ps auxww | grep 'ipython' | awk '{print $2}' | xargs sudo kill -9

答案 1 :(得分:18)

要暂时更改端口,请通过触发以下命令从终端启动jupyter笔记本电脑服务器时指示其他端口号。

jupyter notebook --port 9999

了解更多https://jupyter.readthedocs.io/en/latest/running.html

答案 2 :(得分:4)

有些东西已经在80上侦听,你无法将2台服务器绑定到同一个端口。使用侦听80的代理,并根据URL或地址重​​定向到其他服务器和IPython。也不要使用80,使用443,如果你正在运行公共服务器,它应该通过TLS来保证安全。

请注意,对于任何低端口号,您可能需要将进程权限增加到root,可能使用sudo。

答案 3 :(得分:0)

在Jupyter中,我们可以通过两种方式在不同的端口上启动笔记本电脑。

  1. 临时端口-通过像下面的命令一样在args中提及端口,我们可以在该端口上运行Jupyter。但是,每当需要在其他端口中运行Jupyter时,都必须在命令参数中提及端口。
jupyter notebook --port 9999
  1. 永久端口配置-通过更改配置,我们可以在计算机上的其他端口上永久运行Jupyter。为此,请按照以下步骤操作。

    • 在nano中打开配置文件

    nano ~/.jupyter/jupyter_notebook_config.py

    • 通过更改以下配置的值来更改端口

    c.NotebookApp.port = 9999

    • 启动笔记本

    jupyter notebook

宾果!!!

答案 4 :(得分:0)

仅供参考,在Docker容器中运行并将配置更改为使用端口80:

c.NotebookApp.port = 80

依次导致这些错误:

[W 18:11:42.852 NotebookApp] Permission to listen on port 80 denied.
[W 18:11:42.853 NotebookApp] Permission to listen on port 81 denied.
[W 18:11:42.854 NotebookApp] Permission to listen on port 82 denied.
[W 18:11:42.855 NotebookApp] Permission to listen on port 83 denied.
[W 18:11:42.856 NotebookApp] Permission to listen on port 84 denied.
[W 18:11:42.857 NotebookApp] Permission to listen on port 49 denied.
[W 18:11:42.857 NotebookApp] Permission to listen on port 24 denied.
[W 18:11:42.858 NotebookApp] Permission to listen on port 114 denied.
[W 18:11:42.859 NotebookApp] Permission to listen on port 58 denied.
[W 18:11:42.860 NotebookApp] Permission to listen on port 81 denied.
[W 18:11:42.860 NotebookApp] Permission to listen on port 153 denied.
[W 18:11:42.861 NotebookApp] Permission to listen on port 66 denied.
[W 18:11:42.862 NotebookApp] Permission to listen on port 60 denied.
[W 18:11:42.862 NotebookApp] Permission to listen on port 73 denied.
[W 18:11:42.863 NotebookApp] Permission to listen on port 103 denied.
[W 18:11:42.863 NotebookApp] Permission to listen on port 123 denied.
[W 18:11:42.864 NotebookApp] Permission to listen on port 131 denied.
[W 18:11:42.864 NotebookApp] Permission to listen on port 123 denied.
[W 18:11:42.865 NotebookApp] Permission to listen on port 21 denied.
[W 18:11:42.865 NotebookApp] Permission to listen on port 66 denied.
[W 18:11:42.866 NotebookApp] Permission to listen on port 156 denied.
[W 18:11:42.867 NotebookApp] Permission to listen on port 107 denied.
[W 18:11:42.867 NotebookApp] Permission to listen on port 1 denied.
[W 18:11:42.868 NotebookApp] Permission to listen on port 140 denied.
[W 18:11:42.869 NotebookApp] Permission to listen on port 54 denied.
[W 18:11:42.869 NotebookApp] Permission to listen on port 81 denied.
[W 18:11:42.869 NotebookApp] Permission to listen on port 134 denied.
[W 18:11:42.870 NotebookApp] Permission to listen on port 148 denied.
[W 18:11:42.871 NotebookApp] Permission to listen on port 27 denied.
[W 18:11:42.871 NotebookApp] Permission to listen on port 1 denied.
[W 18:11:42.872 NotebookApp] Permission to listen on port 137 denied.
[W 18:11:42.873 NotebookApp] Permission to listen on port 33 denied.
[W 18:11:42.874 NotebookApp] Permission to listen on port 163 denied.
[W 18:11:42.875 NotebookApp] Permission to listen on port 1 denied.
[W 18:11:42.876 NotebookApp] Permission to listen on port 59 denied.
[W 18:11:42.877 NotebookApp] Permission to listen on port 34 denied.
[W 18:11:42.878 NotebookApp] Permission to listen on port 74 denied.
[W 18:11:42.879 NotebookApp] Permission to listen on port 126 denied.
[W 18:11:42.880 NotebookApp] Permission to listen on port 92 denied.
[W 18:11:42.880 NotebookApp] Permission to listen on port 161 denied.
[W 18:11:42.881 NotebookApp] Permission to listen on port 1 denied.
[W 18:11:42.882 NotebookApp] Permission to listen on port 124 denied.
[W 18:11:42.883 NotebookApp] Permission to listen on port 146 denied.
[W 18:11:42.883 NotebookApp] Permission to listen on port 1 denied.
[W 18:11:42.884 NotebookApp] Permission to listen on port 155 denied.
[W 18:11:42.884 NotebookApp] Permission to listen on port 57 denied.
[W 18:11:42.885 NotebookApp] Permission to listen on port 1 denied.
[W 18:11:42.886 NotebookApp] Permission to listen on port 1 denied.
[W 18:11:42.887 NotebookApp] Permission to listen on port 139 denied.
[W 18:11:42.887 NotebookApp] Permission to listen on port 68 denied.
[W 18:11:42.887 NotebookApp] Permission to listen on port 14 denied.

答案 5 :(得分:0)

jupyter notebook --port 3 [ 或任何您喜欢的端口范围 0 到 65353 不能与任何正在运行的应用程序当前时间冲突。