前言
linux的虚拟化,用户间的系统是相互独立的,且可以分配给每个用户GPU。内网穿刺。
一、构建一个容器(一个独立的镜像)
- 所需掌握要点:
-
配置清华的镜像源
lxc remote add tuna-images https://mirrors.tuna.tinghua.edu.cn/lxc-images/ --protocol=simplestreams --public
-
查看ubuntu下18.04的镜像
lxc image list tuna-images:ubuntu/18.04
-
部署一个容器(镜像)
lxc launch tuna-images:700e8b63e231 (name) -c security.privileged=true
-
查看容器列表
lxc list
-
为容器添加权限
sudo lxc config device add (name) gpu gpu sudo lxc config device add (name) gpu-1 gpu id=1 # 指定gpu sudo lxc config device add (name) gpu-2 gpu id=2 sudo lxc config set (name) security.nesting true sudo lxc config set (name) security.privileged true
-
进入容器设置密码(镜像)
lxc exec (name) bash
设置普通用户密码
设置普通用户root权限
-
换清华源后更新
sudo apt update sudo apt upgrade
-
固定内核版本
sudo apt-mark hold linux-image-generic linux-headers-generic
-
参考博客:
- https://xungejiang.com/2022/07/14/lxd-new/#%E5%88%9B%E5%BB%BA%E5%AE%B9%E5%99%A8
- https://zhuanlan.zhihu.com/p/421271405
- https://www.bilibili.com/video/BV1DU4y1Q7nX/?spm_id_from=333.788.top_right_bar_window_history.content.click&vd_source=c34f231455b5673a561a40366e441052
二、安装和宿主机一致的显卡驱动
- 将驱动从宿主机传进容器
lxc file push ./NVIDIA-Linux-x86_64-510.85.02.run hym/home/NVIDIA-Linux-x86_64-510.85.02.run
- 安装显卡驱动
bash ./NVIDIA-Linux-x86_64-510.85.02.run --no-kernel-module
参考博客:
https://xungejiang.com/2022/07/14/lxd-new/#%E5%88%9B%E5%BB%BA%E5%AE%B9%E5%99%A8
三、修改镜像的端口及通过宿主机分发的端口
-
安装ssh服务
apt install openssh-server
-
修改镜像的分发端口及ssh权限
vim /etc/ssh/sshd_config
-
重启ssh服务
systemctl restart sshd
-
转发规则
sudo iptables -t nat -A PREROUTING -p tcp --dport 4949 -j DNAT --to (ip):4949
-
设置开机启动(rc.localk,自动启动端口映射)
https://blog.csdn.net/lk_luck/article/details/108361857
-
扩容存储池
https://butui.me/posts/how-to-properly-resize-lxd-storage-pool/
-
配置ZeroTier
https://www.jianshu.com/p/9f7691cb32d3
https://blog.csdn.net/weixin_43945453/article/details/106333696?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-106333696-blog-112016717.pc_relevant_multi_platform_whitelistv4&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-106333696-blog-112016717.pc_relevant_multi_platform_whitelistv4&utm_relevant_index=1
参考博客:
https://zhuanlan.zhihu.com/p/421271405
总结
例如:以上就是今天要讲的内容,本文列出了各个环节所需要掌握的知识点,遇到问题-找到问题-找解决方案-解决问题。