在服务器搭建Jupyter notebook
2018-02-18 18:54
621 查看
安装 Jupyter Notebook (这里虽然是对centos和Python2的,但是在Ubuntu16.04,Python3同样可以照着弄)
Jupyter Notebook 简介Jupyter Notebook 是一个开源的 Web 应用程序,可以用来创建和共享包含动态代码、方程式、可视化及解释性文本的文档。
其应用于包括:数据整理与转换,数值模拟,统计建模,机器学习等等。
更多信息请见 官网 。
检查 Python 环境
CentOS 7.2 中默认集成了 Python 2.7,可以通过下面命令检查 Python 版本:
python --version
安装 pip
pip 是一个 Python 包管理工具,我们使用 yum 命令来安装该工具:
yum -y install python-pip
使用下面命令升级 pip 到最新版本:
pip install --upgrade pip
安装相关依赖
安装 Jupyter 过程中还需要其他一些依赖,我们使用以下命令安装他们:
yum -y groupinstall "Development Tools" yum -y install python-devel
配置虚拟环境
安装 virtualenv
我们将为 Jupyter 创建一个独立的虚拟环境,与系统自带的 Python 隔离开来。为此,先安装 virtualenv 库:pip install virtualenv
创建虚拟环境
创建一个专门的虚拟环境,并直接激活进入该环境:virtualenv venv source venv/bin/activate
使用 pip 安装 Jupyter
我们使用 pip 命令安装 Jupyter:
pip install jupyter
配置 Jupyter Notebook
建立项目目录我们先为 Jupyter 相关文件准备一个目录:
mkdir /data/jupyter cd /data/jupyter
再建立一个目录作为 Jupyter 运行的根目录:
mkdir /data/jupyter/root
准备密码密文
由于我们将以需要密码验证的模式启动 Jupyter,所以我们要预先生成所需的密码对应的密文。
生成密文
使用下面的命令,创建一个密文的密码:python -c "import IPython;print IPython.lib.passwd()"
执行后需要输入并确认密码,然后程序会返回一个
'sha1:...'的密文,我们接下来将会用到它。
修改配置
生成配置文件
我们使用--generate-config来参数生成默认配置文件:
jupyter notebook --generate-config --allow-root
生成的配置文件在
/root/.jupyter/目录下,可以点此编辑配置。
修改配置
然后在配置文件最下方加入以下配置:c.NotebookApp.ip = '*' c.NotebookApp.allow_root = True c.NotebookApp.open_browser = False c.NotebookApp.port = 8888 c.NotebookApp.password = u'刚才生成的密文(sha:...)' c.ContentsManager.root_dir = '/data/jupyter/root'
其中:
c.NotebookApp.password请将上一步中密文填入此项,包括 sha: 部分。
你也可以直接配置或使用
Nginx将服务代理到 80 或 443 端口。
启动 Jupyter Notebook
直接启动使用以下指令启动 Jupyter Notebook:
jupyter notebook
此时,访问 http://115.159.91.170:8888 即可进入 Jupyter 首页。
创建 Notebook
进入
【首页】首先需要输入前面步骤中设置的密码。
然后点击右侧的
【 new 】,选择 Python2 新建一个 notebook,这时跳转至编辑界面。
现在我们可以看到 /data/jupyter/root/ 目录中出现了一个
Untitled.ipynb文件,这就是我们刚刚新建的 Notebook 文件。我们建立的所有 Notebook 都将默认以该类型的文件格式保存。
后台运行
直接以
jupyter notebook命令启动 Jupyter 的方式在连接断开时将会中断,所以我们需要让 Jupyter 服务在后台常驻。
先按下
Ctrl + C并输入
y停止 Jupyter 服务,然后执行以下命令:
nohup jupyter notebook > /data/jupyter/jupyter.log 2>&1 &
该命令将使得 Jupyter 在后台运行,并将日志写在 /data/jupyter/jupyter.log 文件中。
准备后续步骤的 Notebook
为了后面实验中实验室的步骤检查器能够更好的工作,此时我们使用以下命令预先创建几份 ipynb 文件:
cd /data/jupyter/root cp Untitled.ipynb first.ipynb cp Untitled.ipynb matplotlib.ipynb cp Untitled.ipynb tensorflow.ipynb rm -f Untitled.ipynb
相关文章推荐
- 使用ssh搭建jupyter notebook服务器
- 搭建 Jupyter Notebook 服务器
- 使用pelican搭建一个Jupyter Notebook数据科学博客
- 阿里云ECS搭建Jupyter Notebook
- 在服务器上配置jupyter notebook
- win7系统 深度学习环境 anaconda+tensorflow+jupyter notebook轻松搭建
- CentOS7服务器安装Jupyter Notebook
- <Jupyter Notebook>如何用一台服务器给多个 Jupyter 用户提供服务
- 深度学习环境搭建:linux下 Ubuntu16.04+cuda8.0+cudnn+anaconda+tensorflow并配置远程访问jupyter notebook
- 本地远程访问Ubuntu16.04.3服务器上的Jupyter notebook
- centos7 和ubuntu下搭建 jupyter notebook,配置R环境
- jupyter notebook + pyspark 环境搭建
- Docker: 使用jupyter notebook基础镜像搭建自己的 pytorch 开发环境
- 实验教程1:如何在阿里云服务器ECS上安装anaconda,配置远程访问的jupyter notebook
- 服务器 配置 Jupyter notebook 远程访问 (Ubuntu 14.04)
- Mac 远程运行 服务器 jupyter notebook
- windows远程连接服务器中的jupyter notebook
- mac 下在服务器上运行 Jupyter notebook
- 【手把手教你】如何在Linux系统搭建jupyter notebook
- 在centos7服务器上安装anaconda和jupyter notebook