1. 程式人生 > 其它 >vscode+remote ssh搭建《dive into deep learning》所需環境

vscode+remote ssh搭建《dive into deep learning》所需環境

vscode+remote ssh搭建《dive into deep learning》所需環境

1.vscode+remote ssh安裝

2.remote ssh連線伺服器

3.伺服器環境搭建

#大致思路:首先伺服器中的容器與其內部的jupyter notebook先形成埠對映,之後容器與本地之間的埠進行對映,使得本地的瀏覽器可以對伺服器上的.ipynb進行展示與編輯

#拉nvidia官方容器
#此處-p 7777:8888的意思是伺服器本身的7777埠會對映到container裡面的8888埠,前面的7777可以更改為別的數字,只要別和伺服器自身已經使用的埠產生衝突就好,後邊的8888最好別更改,因為8888是jupyter notebook的預設埠,若是這裡改動了8888,就要相對應更改。
docker run -p 7777:8888 -it --gpus=all --name=d2l nvidia/cuda:11.2.0-devel-ubi7
#對容器進行初始化
yum install zip bzip2 unzip wget vim #安裝必要的包
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh#安裝minianaconda,以便進行後期虛擬環境的安裝
bash Miniconda3-latest-Linux-x86_64.sh
bash#進入conda base環境
conda create -y -n d2l python=3.8 pip#建立專案所需環境
conda activate d2l#啟用
pip install jupyter d2l torch torchvision#為環境安裝所需要的包
wget https://zh-v2.d2l.ai/d2l-zh.zip#下載課件
unzip d2l-zh.zip
cd pytorch#進入對應的語言資料夾
jupyter notebook --generate-config#生成配置檔案,對其中屬性進行修改
vim /root/.jupyter/jupyter_notebook_config.py
#修改
        c.NotebookApp.ip='*'
        c.NotebookApp.password = u'密文密碼'
        #密文密碼生成
        #from notebook.auth import passwd
			#passwd()
		#輸入自己的密碼,並將產生的密文複製貼上至對應位置
        c.NotebookApp.open_browser = False
        c.NotebookApp.port =8888	
 jupyter notebook --allow-root#執行jupyter notebook
 #終端輸出日誌
 [I 11:22:17.503 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[W 11:22:17.663 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 11:22:17.664 NotebookApp] Serving notebooks from local directory: /pytorch
[I 11:22:17.664 NotebookApp] Jupyter Notebook 6.4.3 is running at:
[I 11:22:17.664 NotebookApp] http://030d0d648e9c:888/#此連結即為本地訪問jupyter的連結
[I 11:22:17.665 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
#在本地開啟終端即cmd
C:\Users\16344>ssh -L7777:localhost:7777 yourname@ssh ip#此處即將本地電腦的7777埠與伺服器7777埠對映
#之後在本地瀏覽器輸入http://127.0.0.1:7777,輸入我們之前設定的密碼即可訪問jupyter notebook