notebook

1、服务器端notebook后台启动

需要将jupyter notebook 在后台挂起,保证随时可以远程访问,同时也不能受到连接终端断开的影响,这里需要使用tmux命令
tmux安装方法:sudo apt-get install tmux
建立名为jupyter的会话窗口,跳转到这个session中: tmux new -s jupyter
后台启动notebook:nohup jupyter notebook --allow-root > jupyter.log 2>&1 &

1.1 tmux基本命令

退出(detach)当前会话窗口: ctrl+d / tmux detach
重新进入tmux: tmux attach -t target-session
使用命令来获取target-session:tmux ls
进入指定session: tmux attach -t neo4j-1

点击查看代码
jupyter-0: 1 windows (created Mon Mar 14 22:02:16 2022) (group jupyter) (attached)
neo4j-1: 1 windows (created Mon Mar 14 22:04:00 2022) (group neo4j)

关闭指定会话:tmux kill-session -t session-name
销毁所有会话:tmux kill-server

2、conda 建立新环境,设置到notebook

创建: conda create -n d2l python=3.8
删除: conda remove -n d2l --all
克隆:conda create -n tf --clone d2l
python -m ipykernel install --user --name d2l --display-name "Python(d2l)"

2.1 conda 配置

一般conda配置文件路径为 ~/.condarc,如果没有,运行下面命令,生成配置文件
conda config --set show_channel_urls yes
清华镜像源说明

点击查看代码
channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
清华大学的这些镜像地址,也不是万能的,必须再添加一个镜像地址conda-forge,才能安装某些包 `conda config --append channels conda-forge` 最终配置文件
点击查看代码
channels:
  - conda-forge
  - defaults
ssl_verify: true
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

3、notebook 设置远程访问

3.1、生成配置文件

在~/.jupyter 目录下 jupyter notebook --generate-config

3.2、生成配置密钥

ipython

点击查看代码
In [1]: from IPython.lib import passwd
In [2]: passwd()
Enter password: 
Verify password: 
Out[2]: 'sha1:0e422dfccef2:84cfbcbb3ef95872fb8e23be3999c12fdfs62d856' 
### 3.3、编辑配置文件 `vim ~/.jupyter/jupyter_notebook_config.py`
点击查看代码
c.NotebookApp.notebook_dir = '期望的默认目录 '
c.NotebookApp.ip='*'
c.NotebookApp.password = u'sha:ce...刚才复制的那个密文'
c.NotebookApp.open_browser = False
c.NotebookApp.port =8888 #随便指定一个端口
c.IPKernelApp.pylab = 'inline'

参考:
https://zhuanlan.zhihu.com/p/365985728

posted @ 2022-01-10 09:22  铁头强  阅读(830)  评论(0)    收藏  举报