安装和配置Jupyter Notebook

安装jupyter notebook

conda

conda install -c conda-forge notebook

pip

pip install notebook

安装好之后,运行:

jupyter notebook

看是否能成功运行

配置Jupyter notebook

  1. 首先生成配置文件:sudo jupyter notebook --generate-config
  2. 然后修改位于~/.jupyter/jupyter_notebook_config.py处的配置文件:
    1. notebook文件根目录:
      ## The directory to use for notebooks and kernels.
      # Default: ''
      c.NotebookApp.notebook_dir = '<PATH_TO_DIR>'
    2. notebook文件根目录:
      ## The port the notebook server will listen on (env: JUPYTER_PORT).
      # Default: 8888
      c.NotebookApp.port = 51234
  3. 运行命令:
    jupyter notebook --no-browser --config=<ABSPATH_TO_CONFIG>/.jupyter/jupyter_notebook_config.py

把jupyter notebook的启动合成到一个命令

为启动notebook的命令设置别名:

alias jlremote='jupyter notebook --no-browser --config=<ABSPATH_TO_CONFIG>/.jupyter/jupyter_notebook_config.py'

然后将这句命令添加到~/.bashrc和~/.bash_profile,如果是Mac OS则添加到~/.zshrc

之后运行:

jlremote

即可。为了使notebook能在后台运行,可以用screen命令为其单开一个screen运行。

把jupyter notebook作为linux service运行

sudo vim /etc/systemd/system/jupyter.service

在这个文件里填入

[Unit]
Description=Jupyter Notebook [Service]
WorkingDirectory=<PATH_TO_DIR>
ExecStart=<ABSPATH_TO_CMD>/jupyter notebook --no-browser --config=<ABSPATH_TO_CONFIG>/.jupyter/jupyter_notebook_config.py
Restart=always
RestartSec=10
SyslogIdentifier=jupyter-notebook
User=<USER NAME> [Install]
WantedBy=multi-user.target

然后安装并运行该服务:

sudo systemctl enable jupyter.service
sudo systemctl start jupyter.service
sudo systemctl status jupyter.service

远程连接jupyter

使用SSH隧道

在~/.bashrc和~/.bash_profile,如果是Mac OS则在~/.zshrc添加:

function jllocal {
port=YOUR PORT
remote_username=USERNAME
remote_hostname=HOSTNAME
url="http://localhost:$port"
echo "Opening $url"
open "$url"
cmd="ssh -CNL localhost:"$port":localhost:"$port" $remote_username@$remote_hostname"
echo "Running '$cmd'"
eval "$cmd"
}

在本地机里直接运行jllocal即可。

使用nginx反向代理

首先直接安装nginx:

sudo apt install nginx

我们需要把本地访问URL<YOUR DOMAIN NAME/IP>:<YOUR PORT>/jupyter时重定向到远程服务器访问localhost:<YOUR_PORT>/jupyter。

配置文件在:/etc/nginx里,可以在conf.d文件夹下新建jupyter.conf,写入配置:

upstream notebook {
server localhost:<YOUR PORT>;
}
server{
listen 80;
server_name <YOUR DOMAIN NAME/IP>;
location /jupyter {
proxy_pass http://notebook;
proxy_set_header Host $host;
} location ~ /jupyter/api/kernels/ {
proxy_pass http://notebook;
proxy_set_header Host $host;
# websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "Upgrade";
proxy_read_timeout 86400;
}
location ~ /jupyter/terminals/ {
proxy_pass http://notebook;
proxy_set_header Host $host;
# websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "Upgrade";
proxy_read_timeout 86400;
}
}

然后也需要修改jupyter的配置~/.jupyter/jupyter_notebook_config.py:

#  Local IP addresses (such as 127.0.0.1 and ::1) are allowed as local, along
# with hostnames configured in local_hostnames.
# Default: False
c.NotebookApp.allow_remote_access = True ## DEPRECATED use base_url
# Default: '/'
c.NotebookApp.base_project_url = '/jupyter/'

修改完配置之后重启两个服务:

sudo systemctl restart jupyter.service
sudo systemctl restart nginx.service

然后可以在本地浏览器里输入<YOUR DOMAIN NAME/IP>:<YOUR PORT>/jupyter访问notebook server,第一次可能需要登录token。

如果把jupyter放到服务里运行的话,token可以从以下log里找到:

sudo systemctl status jupyter.service

Ubuntu 16.04远程配置Jupyter Notebook的更多相关文章

  1. Ubuntu 16.04 LTS 配置 Jupyter notebook 为服务器

    原材料: Ubuntu 16.04 LTS 64bit 已经配置好 IPython 和 Jupyter (安装步骤可以参照:http://www.cnblogs.com/McKean/p/619497 ...

  2. [eShopOnContainers 学习系列] - 03 - 在远程 Ubuntu 16.04 上配置开发环境

    直接把 md 粘出来了,博客园的富文本编辑器换成 markdown,没啥效果呀 ,先凑合吧.实在不行换地方   # 在远程 Ubuntu 16.04 上配置开发环境 ## 零.因 为什么要用这么麻烦的 ...

  3. Ubuntu 16.04修改配置静态IP和DNS

    Ubuntu 16.04修改配置静态IP和DNS 1.修改interfaces 文件 sudo gedit /etc/network/interfaces 2.添加 例如: auto enp0s25 ...

  4. Ubuntu 16.04 Bridge配置

    Ubuntu 16.04 Bridge配置 一.安装网桥拓展包 bridge-utils root@ubuntu:~# apt-get install bridge-utils 二.创建网桥设备 // ...

  5. 【转】Ubuntu 16.04安装配置TensorFlow GPU版本

    之前摸爬滚打总是各种坑,今天参考这篇文章终于解决了,甚是鸡冻\(≧▽≦)/,电脑不知道怎么的,安装不了16.04,就安装15.10再升级到16.04 requirements: Ubuntu 16.0 ...

  6. Ubuntu 16.04下配置 Nginx 与 Node.js 以及服务的部署

    第一步:安装nginx sudo apt-get update sudo apt-get install nginx 如果遇到依赖问题,尝试执行sudo apt-get -f install命令 第二 ...

  7. VMware 15安装Ubuntu 16.04并配置环境

    VMware(虚拟机)是指通过软件模拟的具有完整硬件系统功能的.运行在一个完全隔离环境中的完整计算机系统,它能在Windows系统上虚拟出多个计算机,每个虚拟计算机可以独立运行,可安装各种软件与应用等 ...

  8. Ubuntu 16.04 orb-slam2配置

    说明:Ubuntu 16.04以及必要的基础软件安装完成之后进行: 1.OpenNI2安装(可选) 安装依赖项: sudo apt--dev freeglut3-dev doxygen graphvi ...

  9. Ubuntu 16.04简单配置备忘录

    1.几个安装包的地址 1.Linux QQ:https://im.qq.com/linuxqq/index.html 2.网易云音乐:http://s1.music.126.net/download/ ...

随机推荐

  1. Vue 前端配置多级目录实践(基于Nginx配置方式)

    前情提要 有阵子没更新博客了,因为快年结了工作比较多,这不,最近公司的对外演示环境出现问题这个活儿也落到了我的头上-- 事情是这样的,原来演示环境有很多服务,每个服务都是对外单独开一个端口,比如 ht ...

  2. three.js很好玩

    能用鼠标拉着转. https://files.cnblogs.com/files/blogs/714801/%E7%A9%BA%E9%97%B4%E5%87%A0%E4%BD%95.7z var po ...

  3. Thymeleaf+layui+jquery复选框回显

    一.Thymeleaf+layui+jquery复选框回显 基于Thymeleaf模板下的layui+jquery复选框回显,主要是jquery.大致意思是:把数组转成JSON传到前台,再在前台转回数 ...

  4. 【Spark】【RDD】从本地文件系统创建RDD

    练习作业 完成任务从文件创建三个RDD(math bigdata student) cd ~ touch math touch bigdata touch student pwd 启动Spark-sh ...

  5. <转>Java NIO API

    Java NIO API详解 NIO API 主要集中在 java.nio 和它的 subpackages 中: java.nio 定义了 Buffer 及其数据类型相关的子类.其中被 java.ni ...

  6. CF946B Weird Subtraction Process 题解

    Content 有两个数 \(a,b\),执行如下操作: 如果 \(a,b\) 中有一个数是 \(0\),结束操作,否则跳到操作 \(2\). 如果 \(a\geqslant 2b\),那么 \(a\ ...

  7. LuoguP7041 [NWRRC2016]King's Heir 题解

    Content 给出现在的日期,请从 \(n\) 个人当中选出一个人,使得他是所有成年人(\(\geqslant 18\) 岁的人)中年龄最小的. 数据范围:设日期为 \(yy/mm/dd\),则有 ...

  8. CF1494B Berland Crossword 题解

    Content 有一种叫做 Berland crossword 的拼图游戏.这个拼图由 \(n\) 行 \(n\) 列组成,你可以将里面的一些格子涂成黑色.现在给出 \(T\) 个这样的拼图,每个拼图 ...

  9. 如何把maven项目转为eclipse项目

    如何把maven项目转为eclipse项目,按照如下操作便可. 在cmd窗口, 载cmd窗口进入到maven项目所在目录下,输入如下命令: mvn eclipse:eclipse 这样便可.

  10. 移动端点击a标签拨打电话、发送短信

    拨打电话 <a href="tel:88888888">888888</a> 发送短信 <a href="sms:电话号码"> ...