CentOS7

安装

  • 官方没有提供 CentOS7,可以在下面这个 CentOS-WSL 仓库下载,选择对用的版本下载,也可以使用其他的 CentOS 版本
  • 下载完成后解压是两个文件,注意此时放在哪个目录下则会在对应的目录下创建 ext4.vhdx 虚拟磁盘,不建议放到 C 盘,这个文件随着时间增长会变得很大, 双击 CentOS7.exe 即可安装。

YUM 源修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
# 备份源
cd /etc/yum.repos.d
mkdir repo_bak
mv /etc/yum.repos.d/*.repo repo_bak/

# 更新源 wget
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

# 或者 curl
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo


sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

# 清除系统所有的yum缓存
yum clean all
# 生成yum缓存
yum makecache
# 安装基础软件包
yum install -y lsof wget net-tools nfs-utils lrzsz gcc gcc-c++ make cmake libxml2-devel openssl-devel curl curl-devel unzip sudo ntp libaio-devel wget vim ncurses-devel autoconf automake zlib-devel python-devel epel-release openssh-server socat ipvsadm conntrack ntpdate

#查看进程树 pstree -ap
yum -y install psmisc htop

# 查看repo info
yum repolist
yum grouplist

# 安装命令语言包
dnf install langpacks-en glibc-all-langpacks -y
# 中文支持
dnf install langpacks-zh_CN -y
echo 'LANG="zh_CN.UTF-8"' > /etc/locale.conf
echo 'LANG="zh_CN.UTF-8"' >> /etc/profile

Ubuntu22.04

安装

  • 在 D://wsl 目录下打开 powershell,执行

    1
    2
    3
    4
    5
    6
    7
    8
    9
    Invoke-WebRequest -Uri https://wsldownload.azureedge.net/Ubuntu_2004.2020.424.0_x64.appx -OutFile Ubuntu20.04.appx -UseBasicParsing

    Rename-Item .\Ubuntu20.04.appx Ubuntu.zip

    Expand-Archive .\Ubuntu.zip -Verbose

    cd .\Ubuntu\

    .\ubuntu2004.exe
  • 安装会弹出一个黑框框等几分钟这样,然后输你想要的入用户名和密码就行

  • root 用户登录

    1
    2
    3
    wsl --user root
    # 修改密码 passwd username
    passwd root

换 APT 源

  • 一般是会换成清华源,另外请注意,wsl 的 Ubuntu 证书是过期的,如果你想手动还源的话请记得先更新证书

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    #备份原来的源
    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    #编辑源
    sudo vim /etc/apt/sources.list
    #输入如下
    deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

    #再次运行
    sudo apt-get update
    sudo apt-get upgrade

sudo 免密

  • sudo adduser user root

  • sudo visudo

    1
    2
    # Append a line
    # youruser ALL=(ALL) NOPASSWD:ALL

wsl.conf

  • 执行 vi /etc/wsl.conf 命令创建以文件内容:

    1
    2
    3
    4
    5
    6
    7
    [network]
    # 设置虚拟主机的名称,默认的不好看
    hostname = ubuntu

    [user]
    # 启动的默认用户
    default = root