WSL

文章目录
  1. 1. 入坑
  2. 2. 安装
  3. 3. 问题
    1. 3.1. 连接不上WSL
    2. 3.2. 宿主机卡死
    3. 3.3. ip不固定
    4. 3.4. 接口 CONNECTION_REFUSED

入坑

要特别注意小程序、安卓、pc客户端类的项目跑在WSL中会有坑,目前只适合用来跑一些http协议的web项目;如果只是单纯想用linux命令行,可以考虑cygwin

安装

xxx

问题

连接不上WSL

宿主机卡死

通过C:\Users\xxxx\.wslconfig合力分配资源,避免和宿主机发生资源冲突,通常设置为90%的内存和CPU资源;

[wsl2]
# kernel=<path> # An absolute Windows path to a custom Linux kernel.
memory=10GB # How much memory to assign to the WSL2 VM.
processors=14 # How many processors to assign to the WSL2 VM.
swap=8GB # How much swap space to add to the WSL2 VM. 0 for no swap file.
# swapFile=<path> # An absolute Windows path to the swap vhd.
# localhostForwarding=<bool> # Boolean specifying if ports bound to wildcard or localhost in the WSL2 VM should be connectable from the host via localhost:port (default true).

# <path> entries must be absolute Windows paths with escaped backslashes, for example C:\\Users\\Ben\\kernel
# <size> entries must be size followed by unit, for example 8GB or 512MB

ip不固定

xxx

接口 CONNECTION_REFUSED

curl尝试是否能通

  • 重启wsl

  • localhost:3000替换为127.0.0.1:3000[::1]:3000

  • 更换端口

  • 防火墙

  • 调试工具?可以查看中间链路哪里出错了