阿里雲配置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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章