本身自己机器上安装了太多东西,有点慢,本来也喜欢所有的东西搬到服务上,所以如果能安装一个远程的Jupyter 服务器,用起来就会很方便。
记录下自己的安装步骤

1. 安装ipython, jupyter

pip install ipython  
pip install jupyter 

2. 生成配置文件

[root@50eb5057baac /]# jupyter notebook --generate-config  
Writing default config to: /root/.jupyter/jupyter_notebook_config.py 

3. 生成密码

root@50eb5057baac /]# ipython  
Python 3.5.1 (default, Oct 21 2016, 21:37:19)   
Type 'copyright', 'credits' or 'license' for more information  
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.  
  
In [1]: from notebook.auth import passwd  
  
In [2]: passwd()  
Enter password:   
Verify password:   
Out[2]: 'sha1:43b95b731276:5d330ee6f6054613b3ab4cc59c5048ff7c70f549'  
  
In [3]:   

4. 修改默认配置文件

vi /root/.jupyter/jupyter_notebook_config.py 

c.NotebookApp.ip=’*’ #设置访问notebook的ip,*表示所有IP,这里设置ip为都可访问
c.NotebookApp.password = u’sha1:5df252f58b7f:bf65d53125bb36c085162b3780377f66d73972d1’ #填写刚刚生成的密文
c.NotebookApp.open_browser = False # 禁止notebook启动时自动打开浏览器(在linux服务器一般都是ssh命令行访问,没有图形界面的。所以,启动也没啥用)
c.NotebookApp.port =8889 #指定访问的端口,默认是8888。

5.启动jupyter notebook

[root@346086094cbe /]# jupyter notebook --allow-root  
[W 17:17:04.106 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.  
[I 17:17:04.111 NotebookApp] Serving notebooks from local directory: /  
[I 17:17:04.112 NotebookApp] 0 active kernels  
[I 17:17:04.112 NotebookApp] The Jupyter Notebook is running at:  
[I 17:17:04.112 NotebookApp] http://[all ip addresses on your system]:8889/  
[I 17:17:04.112 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).  

6. 在浏览器中查看

然后你就可以在浏览器里敲入你的地址 http://yourip:8889/, 看到如下界面。
在这里插入图片描述
启动Jupyter的开发窗口,点击右上角的new 按钮

7、注意阿里云服务器的安全组配置

如果用的是阿里云服务器,需要去安全组配置中开发8888端口,否则还是会打开不了浏览器

8、远程连接docker容器中的jupyter notebook

如果是启动linux中docker容器中的jupyter notebook,原理大致和上面步骤是一样的,进入docker容器中,配置docker容器中的jupyter notebook,就和上面步骤一致,但是有一点不同的就是在启动docker容器时候要指定一下端口:

docker run --name lin -p 10000:8888 -it  [镜像名称]:[tag] /bin/bash

其中8888是jupyter notebook的默认端口,如果jupyter notebook配置中修改此端口,此处也响应改变,其中10000是docker映射到linux系统环境的端口,用一个空闲的端口即可。

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐