安装和配置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. Node.js 概述

    JavaScript 标准参考教程(alpha) 草稿二:Node.js Node.js 概述 GitHub TOP Node.js 概述 来自<JavaScript 标准参考教程(alpha) ...

  2. C++之error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘myString’

    先看代码(不想看代码可以直接看代码后的问题描述) //header.h #ifndef _HEADER_H #define _HEADER_H #define defaultSize 128 #inc ...

  3. 【Linux】【Basis】块存储,文件存储,对象存储

    1. 块存储: 定义:这种接口通常以QEMU Driver或者Kernel Module的方式存在,这种接口需要实现Linux的Block Device的接口或者QEMU提供的Block Driver ...

  4. When should we write our own assignment operator in C++?

    The answer is same as Copy Constructor. If a class doesn't contain pointers, then there is no need t ...

  5. AOP切入点的配置

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  6. java中的迭代器的含义

    可迭代是Java集合框架下的所有集合类的一种共性,也就是把集合中的所有元素遍历一遍.迭代的过程需要依赖一个迭代器对象,那么什么是迭代器呢? 迭代器(Iterator)模式,又叫做游标模式,它的含义是, ...

  7. 通过静态分析和持续集成 保证代码的质量 (Helix QAC)2

    续上.... 第二章 部署示例:Jenkins and Helix QAC工具 第一节 Jenkins 作为持续集成系统 现在有很多持续集成工具,既有免费的,也有商业的.最近的研究显示,Jenkins ...

  8. Istio在Rainbond Service Mesh体系下的落地实践

    两年前Service Mesh(服务网格)一出来就受到追捧,很多人认为它是微服务架构的最终形态,因为它可以让业务代码和微服务架构解耦,也就是说业务代码不需要修改就能实现微服务架构,但解耦还不够彻底,使 ...

  9. 【antd】form表单默认值设置

    问题: 在antd的form表单的api里面有个"initialValues"可以设置默认值.但是表单没有更新 <Form name="test" for ...

  10. String类源码分析

    1.String类注释说明 /** * The {@code String} class represents character strings. All * string literals in ...