wsl2折腾笔记
背景: 学生机上配置好了Hadoop跑WordCount的demo时出现内存不足的问题,尝试解决没有成功。因此只能从本地虚拟机上跑。但是VM挂了,而且体验不是很好,所以打算试试wsl2 + docker的方案迁移过去。
安装
主要参考 ms的文档: https://docs.microsoft.com/zh-cn/windows/wsl/install-win10 (ms的文档其实很棒,步骤清晰并且有常见问题解答)
- 运行中输入
winver
查看版本,如果运行的是 Windows 10 版本1903 或 1909,请在 Windows 菜单中打开“设置”,导航到“更新和安全性”,然后选择“检查更新”。 内部版本号必须是 18362.1049+ 或 18363.1049+,次要内部版本号需要高于 .1049。 - 以管理员身份打开 PowerShell 并依次运行以下2条命令:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
- 下载并安装升级包.【如果下载慢可以尝试迅雷等其它方案,如果安装失败重启可能有帮助】
- 将 WSL 2 设置为默认版本: powershell中 –>
wsl --set-default-version 2
- 安装Linux 分发版 https://aka.ms/wslstore
其它说明(重要)
每次你可以通过在 power shell中运行 bash
命令来打开wsl2
当你停止使用时在power shell中输入 wsl --shutdown
关闭相关进程。
你可以通过 wsl –help查看帮助,借助 wsl的export/import等指令你可以完成快照或将wsl中的操作系统移动到非系统盘。
补充
Ubuntu为例的一些常用操作
配置SSH
#1. 重装SSH
sudo apt-get purge openssh-server
sudo apt-get install openssh-server
# 如果需要配置远程开发环境sudo apt-get install openssh-client openssh-server openssh-sftp-server
#2. 设置root密码
passwd root
#3. 配置SSHD
#打开 /etc/ssh/sshd_config文件
Port 2222 #默认的是22,但是windows有自己的ssh服务,也是监听的22端口,所以这里要改一下
PermitRootLogin yes #如果你希望以root用户登录
PasswordAuthentication yes #如果你希望通过密码的方式登录。
AllowUsers yourname #你可登录的用户名
service ssh restart/start #重启/启动 sshd服务
配置apt源
https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11HbnMV3
安装docker
https://www.runoob.com/docker/ubuntu-docker-install.html
目前体验:
(wsl2真香,docke真香,ms NB,另外vscode 安装remote wsl插件也真香}
10.18 再更:自动安装go,rust等的一些shell
https://github.com/lonely-root-number2/wslInitShell
tips:
参考的对象类型不支持尝试的操作【目前发现tp可能导致】
管理员cmd执行:netsh winsock reset 再重启
- Author: DY
- Link: http://4fan.top/posts/wsl2%E6%8A%98%E8%85%BE%E7%AC%94%E8%AE%B0/
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.