阿里云配置Jupyter_notebook

安装Anaconda

mkdir anaconda
cd anaconda
wget https://repo.continuum.io/archive/Anaconda3-4.4.0-Linux-x86_64.sh
#还可以用清华源
#sudo wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.0.1-Linux-x86_64.sh
bash Anaconda3-4.4.0-Linux-x86_64.sh

接受协议,安装位置确认,之后需要等待安装一些默认的包,会让你选择一次bashrc.选yes。

Do you wish the installer to prepend the Anaconda3 install location
to PATH in your /home/bamboo/.bashrc ? [yes|no]
[no] >>> yes

配置环境变量

sudo vim /etc/environment

将自己的安装路径加到最后面

:/home/root/anaconda3/bin

环境变量生效

source /etc/environment
检查安装是否成功
conda --version

更新conda install的源

conda config --add channels 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/'
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes
#更新conda
conda update conda

安装Jupyter notebook

1.创建jupyter notebook运行环境

创建jupyter notebook运行环境,可以方便管理各类库

conda create -n jupyter_notebook python=3
#激活环境
source activate jupyter_notebook
#退出环境
source deactivate
2.安装jupyter notebook
conda install jupyter notebook
#root用户测试
jupyter notebook --allow-root --ip=127.0.0.1

运行结果
在这里插入图片描述

3.配置jupyter notebook远程访问

主要配置一下内容:

  • 设置可访问ip,全局访问
  • 设置远程访问密码
  • 禁用服务器端启动浏览器
  • 服务器端口
#生成配置文件
jupyter notebook --generate-config
#打开配置文件
sudo vi /home/root/.jupyter/jupyter_notebook_config.py
#修改jupyter_notebook_config.py文件
c.NotebookApp.ip = '*'
c.NotebookApp.password = u'sha1:替换成密码的hash值'
c.NotebookApp.open_browser = False
c.NotebookApp.port =8888

生成密码hash值得方法

conda
ipython

In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password: 
Verify password: 
Out[2]: 'sha1:xxxxxxxxxxxxxxxxxxxxx'
#将这里生成得密钥加入jupyter_notebook_config.py
4.启动jupyter notebook
jupyter notebook --allow-root
#或者使用nohup,nohup 就是让程序在后台运行,否则关闭putty后,jupyter在外面就无法访问了。
nohup jupyter notebook --allow-root

启动成功界面
在这里插入图片描述
在网页中输入:公网IP:8888,就可以访问(密码就是生成hash值所用得字符串,如果提示密码错误,请重启服务。)

输入密码:
在这里插入图片描述
进入界面在这里插入图片描述


配置阿里云安全组

如果不配置,远端网页输入IP+port后无法打开界面
实例->安全组规则在这里插入图片描述
阿里云安全组配置

参考资料:

  1. https://zhuanlan.zhihu.com/p/29505612
  2. http://xcx1024.com/ArtInfo/805468.html
  3. https://yq.aliyun.com/articles/98527
  4. https://help.aliyun.com/document_detail/25471.html
  5. https://jupyter-notebook.readthedocs.io/en/stable/public_server.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章