远程服务器配置docker环境Ubuntu16.04+CUDA10.1以及端口映射+conda环境+远程本地访问jupyter notebook
远程服务器配置docker环境Ubuntu16.04+CUDA10.1以及端口映射+conda环境+jupyter notebook1、搭建docker虚拟环境先看下服务器上docker的镜像创建带服务器主机到docker端口映射的TF2环境2、ubuntu16.04更换国内源`apt-get update`来更新下源以便安装编辑器vim`apt-get install vim`来安装vim编辑器
远程服务器配置docker环境Ubuntu16.04+CUDA10.1以及端口映射+conda环境+jupyter notebook
1、搭建docker虚拟环境
先看下服务器上docker的镜像
其中有一个是想要的环境,包含CUDA10.1-cudnn7-devel-ubuntu16.04的版本,用来适配TF2.2.0,记住其ID为2a4a6c5be8ce
创建带服务器主机到docker端口映射的TF2环境
TF2的环境,images为2a4a6c5be8ce,使用如下docker指令创建
docker run -it --gpus all -v /mnt/data0/liqiang/:/home/liqiang/ -p 1111:11 -p 2222:22 -p 80:8080 -p 8888:88 2a4a6c5be8ce /bin/bash
其中
-it --gpus all
表明docker容器可以使用服务器的所有GPU资源
/mnt/data0/user/:/home/user/
冒号前为你服务器保存你文件的实际地址,冒号后面为你docker里Ubuntu16.04映射的地址
-p 1111:11 -p 2222:22 -p 80:8080 -p 8888:88
冒号前为服务器对应端口号,冒号后为docker容器对应映射的端口号
2a4a6c5be8ce
表示镜像对应的ID
/bin/bash
表示以命令行的方式启动创建的docker
之后就可以用下面的指令直接打开已经创建好的docker环境
docker exec -i -t ae8990d427e4 /bin/bash
2、ubuntu16.04更换国内源
apt-get update
来更新下源以便安装编辑器vim
apt-get install vim
来安装vim编辑器
更新源
1.备份原始源文件source.list
桌面打开终端,执行命令:
cp /etc/apt/sources.list /etc/apt/sources.list.bak
2.修改源文件sources.list
(1)终端执行命令: chmod 777 /etc/apt/sources.list
更改文件权限使其可编辑;
(2)执行命令: vim /etc/apt/sources.list
打开文件进行编辑;
(3)删除原来的文件内容,复制下面的任意一个到其中并保存(常用的是阿里源和清华源,推荐阿里源);
阿里源:
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
清华源:
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
3.更新源
桌面终端执行命令:apt update
更新软件列表,换源完成。
可以看到用的是阿里的网站
3、搭建conda虚拟环境:
1、下载
wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
2、添加权限然后安装
chmod 777 bash Anaconda3-4.4.0-Linux-x86_64.sh*
bash Anaconda3-4.4.0-Linux-x86_64.sh*
提前写好的安装conda的路径粘贴上去:/home/liqiang/NLP/conda
安装过程中,提示阅读用户许可协议,需要按“Enter”继续,并输入 “yes”继续安装,并列出conda安装的具体路径,这个路径保存一下。
export PATH=/home/liqiang/NLP/conda/bin:$PATH //之前设定的路径地址
source ~/.bashrc //生效
3、创建conda虚拟环境:
conda create -n you_env_name python=3.6
4、激活虚拟环境
source activate you_env_name
查看Conda环境下所有的虚拟环境
conda info --env
退出虚拟环境
source deactivate
4、在虚拟环境里安装jupyter并添加接口映射
1、在虚拟环境里下载jupyter notebook
pip install jupyter notebook
2、配置远程访问jupyter
2.1、生成密码
在ubuntu的命令行里输入ipython打开ipython,(没有的话,输入python也可以)
ipython
在python命令行里分别输入:
from notebook.auth import passwd
passwd()
输完之后,设定一个密码,会生成一个sha1的秘钥会有如下的结果:
这时候把sha1秘钥'argon2:$argon2id$v=19$m=10240,t=10,p=8$TDmQowJ6RaWI83qHDgpJMg$0piqJqoRszSa+g0cy0VCnQ'
保存下来,然后退出ipython命令行:
quit()
2.2、生成jupyter notebook的配置文件
使用命令
jupyter notebook --generate-config
这时候会生成配置文件,在 ~/.jupyter/jupyter_notebook_config.py
2.3、修改配置文件
修改要用到vim,若是没有,先运行:
apt-get update
apt-get install vim
安装好vim之后,运行一下程序打开配置文件:
vim ~/.jupyter/jupyter_notebook_config.py
加入如下内容,其中sha1那一串秘钥是上面生成的那一串,然后保存退出
c.NotebookApp.ip='*'
c.NotebookApp.password = u'argon2:$argon2id$v=19$m=10240,t=10,p=8$TDmQowJ6RaWI83qHDgpJMg$0piqJqoRszSa+g0cy0VCnQ'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 11
这里
c.NotebookApp.ip='*'
表示任何IP都可以访问服务器上运行的jupyter服务器,方便后面远程在本地连接
c.NotebookApp.password
表示设置对应的jupyter notebook密码
c.NotebookApp.open_browser
表示设置运行jupyter notebook时候不需要打开浏览器,因为命令行状态也用不了浏览器
c.NotebookApp.port = 1111
表示表示jupyter服务器对外开放的访问端口
2.3、打开jupyter notebook
jupyter notebook --allow-root
虽然在这里看到,要求我们输入 服务器IP:11来连接jupyter,但是输入以上网址后发现找不到网页。
这是因为docker产生的container是一个新的环境,而我们连接的是服务器的端口,在第一步时我们把服务器的1111端口和container的11端口绑定在一起了,所以我们需要连接的是服务器的1111端口。
所以在本地浏览器输入
服务器IP:服务器上映射的端口
输入密码就可以连接到服务器端的jupyter notebook了。

欢迎来到由智源人工智能研究院发起的Triton中文社区,这里是一个汇聚了AI开发者、数据科学家、机器学习爱好者以及业界专家的活力平台。我们致力于成为业内领先的Triton技术交流与应用分享的殿堂,为推动人工智能技术的普及与深化应用贡献力量。
更多推荐
所有评论(0)