windows安装centos8子系统

[toc]

参考:在 Windows 10 上安装 CentOS 系统

参考:https://github.com/mishamosher/CentOS-WSL

众所周知,windows商店里面官方没有退出centos子系统,目前的都是个人版的,还是收费的,我们不能要。

测试情况:centos7可以正常使用并正常使用docker;centos8能正常使用,但是docker不能正常使用,解决办法暂时没找到。所以,还是用centos7吧

[toc]

一、快速开启windows的linux子系统功能

管理员身份运行powershell,执行下面命令

$ Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

然后重启电脑

二、安装centos系统

CentOS 镜像的 Github 地址:https://github.com/mishamosher/CentOS-WSL
适用于 CentOS 7 的地址:CentOS 7.9.2009
适用于 CentOS 8 的地址:CentOS 8.3.2011
适用于 CentOS 8 Stream 的地址:CentOS 8 Stream

将下载好的压缩包解压到D盘的centos8目录下面(想解压到E盘也没关系,路径内不能包含中文字符)

以管理员身份运行这个exe文件

完成安装,任意键退出

发现多了一个ext4.vhdx文件,没错,和ubuntu子系统一样了

双击运行exe文件就可以以root身份进入centos8系统了,而且是可以联网的

三、其他配置

启动ssh服务

#生成系统的私钥可key文件
ssh-keygen -t dsa -P "" -f /etc/ssh/ssh_host_dsa_key
ssh-keygen -t rsa -P "" -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t ecdsa -P "" -f /etc/ssh/ssh_host_ecdsa_key
ssh-keygen -t ed25519 -P "" -f /etc/ssh/ssh_host_ed25519_key
#修改root用户密码
[root@DESKTOP-R8CAT9L ~]# echo "admin" | passwd --stdin root
#修改sshd配置文件的监听端口,并允许root登陆
[root@DESKTOP-R8CAT9L ~]# sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config
[root@DESKTOP-R8CAT9L ~]# sed -i "s/#Port.*/Port 3333/g" /etc/ssh/sshd_config
#启动sshd
[root@DESKTOP-R8CAT9L ~]# /usr/sbin/sshd -D &
[1] 128
[root@DESKTOP-R8CAT9L ~]# ss -ltn | grep 3333
LISTEN 0      128          0.0.0.0:3333       0.0.0.0:*
LISTEN 0      128             [::]:3333          [::]:*

连接测试

安装docker

#repo文件
~]# curl -o /etc/yum.repos.d/docker-ce.repo  https://repo.huaweicloud.com/docker-ce/linux/centos/docker-ce.repo
~]# sed -i 's+download.docker.com+repo.huaweicloud.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
~]# yum makecache
~]# yum install docker-ce
#centos8启动不起来,centos7是可以启动起来的,暂时没查到解决办法
~]# /usr/bin/dockerd -p /var/run/docker.pid &

四、卸载

管理员运行powershell

$ D:\centos8\CentOS8.exe clean