美文网首页
通过Jupyter Notebook 访问服务器

通过Jupyter Notebook 访问服务器

作者: 21b162136419 | 来源:发表于2019-06-25 12:51 被阅读0次

安装Jupyter

首先登录服务器,输入jupyter notebook检查是否有安装过jupyter。若没有则通过以下指令安装:

pip install jupyter

生成Jupyter配置文件

安装完Jupyter之后,输入以下指令生成jupyter配置文件:

jupyter notebook --generate-config

配置文件默认会放置在Writing default config to:/root/.jupyter/jupyter_notebook_config.py

生成密钥

命令行输入ipython。

$ ipython

import passwd包,使用改包生成密钥

In[1]: from notebook.auth import passwd
In[2]: passwd()
Enter password: 
Verify password: 
Out[2]: 'sha1:0000000000000000000000000000000000000000000000000'

编辑jupyter配置文件

输入以下指令,编辑配置文件

vim ~/.jupyter/jupyter_notebook_config.py 

i进入编辑模式
该文件的所有配置初始时都是被注释的。需要修改以下的配置,将每一行配置前的去掉

c.NotebookApp.allow_remote_access = True
c.NotebookApp.allow_root = True   ## 表示是否允许jupyter使用root权限
c.NotebookApp.ip = '*'
c.NotebookApp.port = 8888  ##根据自己情况指定
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:00000000....' ## 刚刚设置密码时生成的密钥

编辑完成后按esc退出编辑模式,输入‘:wq’退出编辑。

后台运行jupyter[后台运行参考]

完成以上步骤以后,只需要在后台将jupyter运行起来就OK啦:

nohup jupyter notebook &

Note: 注意以上运行jupter指令所在的目录,该目录会作为访问时的根目录。

这时当前目录下会生成一个nohup.out文件,运行jupyter notebook的所有标准输出都会重定向至该文件内。可使用

jobs

查看后台作业的情况。
若目录不正确可以使用kill中止掉后台进程,进入到期望的目录下后再次运行

kill %使用jobs查询到的作业代号

访问远程服务器的Jupyter

在自己的浏览器上输入

服务器ip:端口号

即可进入jupyter的登录页面,如下所示


image.png

接下来输入刚刚设置的密码,即可通过jupyter访问服务器啦!

相关文章

网友评论

      本文标题:通过Jupyter Notebook 访问服务器

      本文链接:https://www.haomeiwen.com/subject/ktjtcctx.html