Jupyter notebook连接远程服务器和配置Anaconda环境操作笔记

Jupyter notebook连接远程服务器

这篇笔记的操作主要参考这篇博主的文章:https://blog.csdn.net/qq_33362102/article/details/109321066
在这里我的远程服务器是CentOS7,本地计算机是Windows7系统。

Linux 服务器端设置

首先在Linux服务器上安装Jupyter notebook。前提是已经安装好了Anaconda3:

用pip进行安装

pip install Jupyter

生成Jupyter notebook 配置文件

jupyter notebook --generate-config

配置Jupyter notebook密码

$jupyter notebook password
Enter password:  ****(自定义)
Verify password: ****

新版的Jupyter notebook只需要输入密码确认,然后它会自动帮你把生成含有密码的hash码输入进jupyter_notebook_config.json 文件。

还有一种操作是用ipython交互式shell来完成密码设置:

ipython
In [1]: from notebook.auth import passwd

In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'argon2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

In [3]: exit

然后将生成的hash存入jupyter_notebook_config.py文件最后:

c.NotebookApp.password = u'sha1:ceXXX‘

配置 jupyter_notebook_config.py 文件

vim ~/.jupyter/jupyter_notebook_config.py

在最后一行后加入如下配置信息:

c.NotebookApp.allow_remote_access = True
c.NotebookApp.open_browser = False
c.NotebookApp.ip = '*'
c.NotebookApp.allow_root = True
c.NotebookApp.port = 8888 #端口可以更改

如果想在特定文件夹打开则可加入一下行:

c.NotebookApp.notebook_dir = ''

保存退出vim即可。

本地连接设置

在完成服务器端设置后,首先在服务器上启动jupyter notebook:

jupyter notebook --no-browser --port=8889 --ip=127.0.0.1

这样启动jupyter之后会在服务器前台占据一个终端窗口,最好可以将它转为后台运行:

nohup jupyter notebook --no-browser --port=8889 --ip=127.0.0.1 &

然后在本地的cmd窗口打以下命令:

ssh -N -f -L localhost:8888:localhost:8889 -p 22 remote_user@remote_host

按照提示输入服务器密码即可。这里的-L参数为隧道转发,将本地机(客户机)的某个端口转发到远端指定机器的指定端口,其语法为:
-L host:port:host:port
因此这里的localhost可以直接写localhost,也可以写localhost的默认IP:127.0.0.1,8888端口为本地端口,即接下来用来在本地打开jupyter的端口,也是jupyter_notebook_config.py配置文件里设置的端口,8889为服务器开的端口,即服务器启动时设置的端口,不要搞混淆了。

-p参数后面的端口为ssh的连接端口,默认是22,如果服务器的ssh端口更改过,则需要填写更改的端口号。

接下来在本地浏览器网址栏输入http://127.0.0.1:8888,然后就可以看到jupyter-notebook登录界面了。输入设置好的密码即可。

由于我使用的是Win7系统,cmd没有自带ssh命令,因此需要安装OpenSSH软件来是cmd可以运行ssh命令,这一部分可以参考一下这篇文章:
https://blog.csdn.net/jerrygaoling/article/details/115308184

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值