先拿到账号密码
内网:ssh root@12.34.56.78 -p 2212
外网:ssh root@12.34.56.78 -p 32212
密码654321
居然是root…不过实验室师姐说这是用docker实现的(具体我也不知道),每个人的账号互不干扰,那也就无所谓了
很好,上来发现一片空白
root@16ffc2fac0e4:~# ls
root@16ffc2fac0e4:~# python
-bash: python: command not found
root@16ffc2fac0e4:~# python3
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
root@16ffc2fac0e4:~# conda
-bash: conda: command not found
root@16ffc2fac0e4:~# git
-bash: git: command not found
root@16ffc2fac0e4:~#
先安装anaconda
上https://www.anaconda.com/products/distribution#Downloads查看Linux下的下载选项
有四种:
64-Bit (x86) Installer (737 MB)
64-Bit (Power8 and Power9) Installer (360 MB)
64-Bit (AWS Graviton2 / ARM64) Installer (534 MB)
64-bit (Linux on IBM Z & LinuxONE) Installer (282 MB)
查看系统信息的命令
# 查看系统是多少位
root@16ffc2fac0e4:~# getconf LONG_BIT
64
# Linux内核版本
root@16ffc2fac0e4:~# cat /proc/version
Linux version 5.4.0-124-generic (buildd@lcy02-amd64-089) (gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)) #140-Ubuntu SMP Thu Aug 4 02:23:37 UTC 2022
(AMD和x86并不是两个完全不同的东西!不知道哪里来的错觉)那就暂且选择第一个吧。
下载不需要挂梯子。
把sh脚本传上服务器
scp -P 2212 Downloads/Anaconda3-2022.10-Linux-x86_64.sh root@12.34.56.78:/root
# 不支持断点续传有点麻烦
# rsync有空再看一下
在服务器上安装Anaconda
# 运行脚本
sh Anaconda3-2022.10-Linux-x86_64.sh
安装完重启shell就有conda命令了,前面出现了(base),python命令现在也有了
配置一下免密登录和端口映射
免密登录
-
在本地机器上生成公钥与私钥
- 进入用户主目录下的.ssh目录cd ~/.ssh
- 执行 ssh-keygen -t rsa,敲下回车后会有3个交互,第一个是文件名,默认是id_rsa,如需修改,自己输入一个文件名便可。第二与第三是密码与确认密码,是以后使用该公钥时要输入的密码,一般不设置,如有强烈的安全需求,自己设置便可。最后会生成两个文件id_rsa,id_rsa.pub。以.pub结尾的是公钥,另一个是私钥。
-
把公钥加入到服务器的.ssh/authorized_keys 文件中
- 服务器没有.ssh文件夹和authorized_keys文件的话自己新建一个就行
-
配置本地config文件
Host server-in # 一个便于你区别这是哪台机器的名字 HostName 12.34.56.78 # 目的机器的ip User root # ssh登陆时候的用户名 Port 2212 # ssh所使用的端口,默认是22 IdentityFile /Users/apple/.ssh/id_rsa # 本地私钥文件路径 # 外网还配置了一个server-out,类似
现在可以用
ssh server-in
登录了配置过.ssh/config后,此时已经可以用
scp <local_file_path> server-in:<remote_file_path>
命令了,即省去了用户名、ip、登录端口。
端口映射
方便你在本地用jupyter lab/jupyter notebook访问服务器上的资源,能直观一点的地方就别用命令行了,是吧hhhh。
以前我的方法是ssh username@host -p port -L local_ip:local_port:remote_ip:remote_port
,然后我会把这一串命令在bash里用alias存一个简单名称
现在可以用.ssh/config配置
Host server-in # 一个便于你区别这是哪台机器的名字
HostName 12.34.56.78 # 目的机器的ip
User root # ssh登陆时候的用户名
Port 2212 # ssh所使用的端口,默认是22
IdentityFile /Users/apple/.ssh/id_rsa # 本地私钥文件路径
LocalForward 127.0.0.1:4321 127.0.0.1:8894 # 端口映射(端口转发)
运行jupyter lab/jupyter notebook
我安好anaconda后,现在已有jupyter命令
jupyter lab --port 8894
# 没跑起来(没出现那个http://127.0.0.1/token=xxx)
# 报错信息让我加上--allow-root
jupyter lab --allow-root --port 8894
# 成功
本地访问http://127.0.0.1:4321/lab?token=xxxxxx,成功
安装tmux
tmux让你在logout服务器时,正在跑的代码不会终止。
现在还没有tmux:
(base) root@16ffc2fac0e4:~# tmux
-bash: tmux: command not found
查到了两个“在线安装”的方法:
# centos
sudo yum install tmux
# ubuntu
sudo apt-get install tmux
结果sudo: command not found(原来sudo也是可以not found的?)
在绕了一大圈弯路后,查阅https://blog.csdn.net/SH_ke/article/details/118496704发现:
开门见山,Ubuntu的包管理工具是apt-get,所以不必再安装yum。如果要安装其他包需要使用apt-get命令。
直接apt-get安装tmux
所以直接apt-get install tmux
,成功。
给conda环境安装深度学习常用包
pytorch
老规矩,看https://pytorch.org/的install部分。
唯一的问题是cuda版本。
查看服务器上的GPU配置
-
有没有gpu?
nvidia-smi
命令(base) root@16ffc2fac0e4:~/yum-3.2.28# nvidia-smi Wed Oct 19 17:17:04 2022 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 510.47.03 Driver Version: 510.47.03 CUDA Version: 11.6 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 NVIDIA GeForce ... On | 00000000:1A:00.0 Off | N/A | | 0% 37C P8 29W / 350W | 1MiB / 24576MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ | 1 NVIDIA GeForce ... On | 00000000:89:00.0 Off | N/A | | 0% 35C P8 23W / 370W | 1MiB / 24576MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ | 2 NVIDIA GeForce ... On | 00000000:B1:00.0 Off | N/A | | 38% 34C P8 19W / 350W | 1MiB / 24576MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ | 3 NVIDIA GeForce ... On | 00000000:B2:00.0 Off | N/A | | 38% 35C P8 23W / 350W | 1MiB / 24576MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | No running processes found | +-----------------------------------------------------------------------------+
-
cuda版本?
还是上面那个命令,表格第一行写了,
CUDA Version: 11.6
。
获取安装命令
ok,现在pytorch官网给出了我们需要运行的命令:
NOTE: 'conda-forge' channel is required for cudatoolkit 11.6
conda install pytorch torchvision torchaudio cudatoolkit=11.6 -c pytorch -c conda-forge
(base) root@16ffc2fac0e4:~/yum-3.2.28# conda install pytorch torchvision torchaudio cudatoolkit=11.6 -c pytorch -c conda-forge
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): /
# 有点慢,但是多等等好歹能collecting上,不想用pip。
# cudatoolkit安装尤其慢。可能是我没换
# 累了,Ctrl+C断了。cudatoolkit和pytorch两个包太大了
给conda设置国内源
-
现在有哪些channel
# conda info channel URLs : https://repo.anaconda.com/pkgs/main/linux-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/linux-64 https://repo.anaconda.com/pkgs/r/noarch
-
添加清华源(https://zhuanlan.zhihu.com/p/47663391)
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ # 以上两条是Anaconda官方库的镜像 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ # 以上是Anaconda第三方库 Conda Forge的镜像 # for linux conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ # for legacy win-64 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/ # 以上两条是Pytorch的Anaconda第三方镜像 conda config --set show_channel_urls yes
-
重新安装:
conda install pytorch torchvision torchaudio cudatoolkit=11.6 # 可能我没设置实际用什么源?还是很慢,好在有tmux
一直
CondaHTTPError: HTTP 000 CONNECTION FAILED for url [https://repo.anaconda.com/pkgs/main/linux-64/current_repodata.json](https://repo.anaconda.com/pkgs/main/linux-64/current_repodata.json) Elapsed: -
-
去掉默认channel(-default)
解决方案参考https://zhuanlan.zhihu.com/p/260034241
安装成功。
其他常用包
- tqdm(进度条)
- to be added