ipython笔记本远程服务器的特性 [英] ipython notebook on remote server peculiarity

查看:136
本文介绍了ipython笔记本远程服务器的特性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ipython笔记本电脑迈出第一步,并将其成功安装在我的远程服务器上(通过SSH),并使用以下命令启动它:

I am taking my first steps with ipython notebook and I installed it successfully on a remote server of mine (over SSH) and I started it using the following command:

ipython notebook --ip='*' ---pylab=inline --port=7777

然后我检查了 http://myserver.sth:7777 / 和笔记本运行得很好。然后我想关闭与服务器的SSH连接并让ipython在后台运行。当我这样做时,我无法连接到myserver.sth:7777。一旦我通过SSH再次连接到远程服务器,我就可以再次连接到笔记本电脑。然后我尝试使用 screen 来启动ipython:我通过创建了一个新屏幕-S ipy ,我开始了ipython笔记本如上,我使用 Ctrl + A,D 分离屏幕并退出到TTY。我仍然可以远程连接到笔记本电脑。然后我关闭了SSH连接,当我试图访问我之前存储的笔记本时,我得到了一个 404 NOT FOUND 错误,我在笔记本列表中看不到它< a href =http://myserver.sth:7777 / =nofollow> http://myserver.sth:7777 / 。我试图创建一个新的笔记本,但我得到了一个 500内部服务器错误

I then checked on http://myserver.sth:7777/ and the notebook was running just fine. I then wanted to close the SSH connection with the server and keep ipython running in the background. When I did this, I couldn't connect to myserver.sth:7777 anymore. Once I connected again to the remote server by SSH, I could connect again to the notebook. I then tried to use screen to start ipython: I created a new screen by screen -S ipy, I started ipython notebook as above and I used Ctrl+A,D to detach the screen and exit to the TTY. I could still connect remotely to the notebook. I then closed the SSH connection and I got a 404 NOT FOUND error when I tried to access my previously stored notebook and I couldn't see it on the list of notebook at http://myserver.sth:7777/. I tried to create a new notebook, but I got a 500 Internal Server Error.

我也尝试过运行 ipython notebook 使用和不使用 sudo

I also tried running ipython notebook with and without using sudo.

任何想法?

推荐答案

您可以切换到init脚本或 supervisord 让IPython笔记本保持正常运行。

Rather than use screen, perhaps you could switch to an init script or supervisord to keep IPython notebook up and running.

让我们假设你走上了监督路线:

Let's assume you go the supervisord route:

安装supervisord

使用您的软件包管理器安装supervisord。对于ubuntu,它名为主管

Install supervisord using your package manager. For ubuntu it's named supervisor.

apt-get install supervisor

如果你决定通过pip安装supervisor,你必须自己设置它的init.d脚本。

If you decide to install supervisor through pip, you'll have to set up its init.d script yourself.

为IPython编写主管配置文件

配置文件告诉主管运行什么以及如何运行。

The configuration file tells supervisor what to run and how.

安装后主管,应该创建 /etc/supervisor/supervisord.conf 。这些行应该存在于文件中:

After you install supervisor, it should have created /etc/supervisor/supervisord.conf. These lines should exist in the file:

[include]
files = /etc/supervisor/conf.d/*.conf

如果它们包含这些行,那么你的状态良好。我只展示它们以展示它期望新配置文件的位置。您的配置文件可以去那里,名称类似于 /etc/supervisor/conf.d/ipynb.conf

If they contain these lines, you're in good shape. I only show them to demonstrate where it expects new configuration files. Your configuration file can go there, named something like /etc/supervisor/conf.d/ipynb.conf.

这是一个示例配置,由Chef通过运行的 ipython-notebook-cookbook 生成virtualenv中的笔记本:

Here's a sample configuration that was generated by Chef by an ipython-notebook-cookbook that runs the notebook in a virtualenv:

[program:ipynb]
command=/home/ipynb/.ipyvirt/bin/ipython notebook --profile=cooked
process_name=%(program_name)s
numprocs=1
numprocs_start=0
autostart=true
autorestart=true
startsecs=1
startretries=3
exitcodes=0,2
stopsignal=QUIT
stopwaitsecs=10
user=ipynb
redirect_stderr=false
stdout_logfile=AUTO
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10
stdout_capture_maxbytes=0
stdout_events_enabled=false
stderr_logfile=AUTO
stderr_logfile_maxbytes=50MB
stderr_logfile_backups=10
stderr_capture_maxbytes=0
stderr_events_enabled=false
environment=HOME="/home/ipynb",SHELL="/bin/bash",USER="ipynb",PATH="/home/ipynb/.ipyvirt/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games",VIRTUAL_ENV="/home/ipynb/.ipyvirt"
directory=/home/ipynb
serverurl=AUTO

上述主管配置还依赖于IPython笔记本配置(位于 /home/ipynb/.ipython/profile_cooked/ipython_notebook_config.py )。这使配置更容易(因为您还可以设置密码哈希和许多其他配置)。:

The above supervisor config also relies on an IPython notebook configuration (located at /home/ipynb/.ipython/profile_cooked/ipython_notebook_config.py). This makes configuration much easier (as you can also set up your password hash and many other configurables).:

c = get_config()

# Kernel config

# Make matplotlib plots inline
c.IPKernelApp.pylab = 'inline'

# The IP address the notebook server will listen on.
# If set to '*', will listen on all interfaces.
# c.NotebookApp.ip= '127.0.0.1'
c.NotebookApp.ip='*'

# Port to host on (e.g. 8888, the default)
c.NotebookApp.port = 8888 # If you want it on 80, I recommend iptables rules

# Open browser (probably want False)
c.NotebookApp.open_browser = False

重新阅读和更新,现在您已拥有配置文件

supervisorctl reread
supervisorctl update



现实



实际上,我曾经使用 Chef cookbook 来完成整个安装和配置。但是,使用像这样的小东西进行配置管理有点过分(除非你在自动化中编排这些内容)。

Reality

In reality, I used to use a Chef cookbook to do the entire installation and configuration. However, using configuration management with tiny stuff like this is a bit of overkill (unless you're orchestrating these in automation).

现在我将Docker镜像用于IPython笔记本,通过JupyterHub或tmpnb编排。

Nowadays I use Docker images for IPython notebook, orchestrating via JupyterHub or tmpnb.

这篇关于ipython笔记本远程服务器的特性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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