配置服务器(anaconda + jupyter + R)

总结一下整体的流程:

1. 服务器安装anaconda

  首先清华镜像站下载anaconda3。

2. 将下载好的文件用scp命令传入服务器

  注意:指定端口用-P命令 p大写

1 ssh -P 65532 本机地址 用户名@服务器IP:传输目标地址

  如果要传输文件夹请用如下命令:

1 ssh -P 65532 -r 本机地址 用户名@服务器IP:传输目标地址

3. 安装

1 bash AnaXXXX.sh

如果需要重装请用

1 bash AnanXXX.sh -u

这里遇到一个坑,就是服务器的一个节点坏掉了,所以要进入到另外的节点

1 ssh -p 65532 [email protected]   //这个节点坏掉了,要进去以后重新指定节点
2 ssh g03    // 指定进入g03节点    

4. 安装好了以后要配置路径才可以用

输入命令打开配置文件
vim ~/.bashrc

在最后添加语句
export PATH=/home/XXX/anaconda3/bin:$PATH

XXX为你的用户名

注意

linux配置文件执行顺序为:
/etc/profile→ (~/.bash_profile | ~/.bash_login | ~/.profile)→ ~/.bashrc →/etc/bashrc → ~/.bash_logout

假如在~/.bash_profile文件中没有下面的代码:

1 if [ -f ~/.bashrc ] ; then
2         source .bashrc
3 fi 

那么linux就不会自动执行~/.bashrc文件,所以你每次登陆的时候都要手动输入source ~/.bashrc。
所以需要vim ~/.bash_profile 添加代码块中的内容,当然如果不嫌麻烦就每次都source吧!

source之后就可以看到python 可以显示anaconda安装的对应版本

conda也可以用了

先构建环境:

1 conda update -n base conda        //update最新版本的conda
2 conda create -n xxxx python=3.5   //创建python3.5的xxxx虚拟环境
3 conda activate xxxx               //开启xxxx环境
4 conda deactivate                  //关闭环境
5 conda env list                    //显示所有的虚拟环境

5. jupyter 配置远程链接

我个人是不太推荐用网上常见的配置密码的操作,因为如果不配置,打开jupyter每次也会分配一个token把这个复制到密码就可以了

jupyter 也可以指定端口

1 jupyter notebook --port 9995

然后在本机建立通道监听远程服务器的9995端口,即可在自己的浏览器中访问了

建立通道:

1 ssh -p 65532 xxx@xx.xxx.xx.xxx -L 127.0.0.1:9995:localhost:9995

前面的127.0.0.1是为了指定进入g03节点,如果没有开始的节点坏掉就直接用下面的

1 ssh -p 65532 [email protected] -L 9995:localhost:9995

 6. jupyter 关联R

先在某个建好的anaconda环境下面安装r,建议把源换成清华的

 1 #加源与库
 2   conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
 3     conda config --set show_channel_urls yes
 4 
 5 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
 6 
 7 conda config --add channels conda-forge
 8 conda config --add channels defaults
 9 conda config --add channels r
10 conda config --add channels bioconda
11 
12 #升级conda版本
13 conda update conda
14 conda install R

然后,启动R控制台,运行下面的语句::

1 install.packages(c('repr', 'IRdisplay', 'crayon', 'pbdZMQ', 'devtools'))
2 devtools::install_github('IRkernel/IRkernel')
3 IRkernel::installspec()  # to register the kernel in the current R installation

然后再重启jupyter就可以了

猜你喜欢

转载自www.cnblogs.com/shanyr/p/11276755.html