当前位置: 首页 > news >正文

win11中系统的WSL安装Centos以及必要组件

win11中系统的WSL安装Centos

一、配置windows

1、系统对应

如果系统版本在Windows 10 2004以下,请使用Centos7.X

2、打开虚拟化

打开控制面板 -> 程序 -> 启动或关闭windows功能 -> 确保以下选项打开:
在这里插入图片描述

3、重启windows

二、下载Centos镜像

1、根据自己win系统的版本,下载WSL-Centos,下载地址:

https://github.com/wsldl-pg/CentWSL/releases

2、处理文件

将下载得到的压缩包放到你想安装CentOS的位置,解压得到文件:
在这里插入图片描述
双击CentOS8.exe,出现DOS窗口:
在这里插入图片描述
当出现以下结果,按Enter,关闭DOS窗口
在这里插入图片描述

三、启动CentOS

1、打开DOS窗口,执行命令:

# 查看已安装镜像和运行状态
wsl -l -v

在这里插入图片描述
2、启动并进入Centos8

wsl -d CentOS8

在这里插入图片描述
3、由于 CentOS 8 和 CentOS 7 已经停止维护,所以有很多命令和数据源不能使用

错误一:

[root@localhost 64217]# yum update
CentOS-8 - AppStream                                                                    0.0  B/s |   0  B     00:00
Failed to download metadata for repo 'AppStream'
Error: Failed to download metadata for repo 'AppStream'

错误二:

Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorlist

原因:
查看阿里云官网上的说明:https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.66c71b11q4E0g4
可以看到centos8官方源已下线,需切换centos-vault源
解决方案:
① 备份文件

cp -rv /etc/yum.repos.d /etc/yum.repos.d_bak

② 执行切换命令,两个命令二选一:

命令1:
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
0
命令2:
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

③ 进入目录:

cd /etc/yum.repos.d/

④ 修改 centos 文件内容

sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

⑤ 生成缓存更新(第一次更新,速度稍微有点慢,耐心等待两分钟左右)

yum makecache

⑥ 完毕状态:
在这里插入图片描述
⑦ 最后,运行 yum update

yum update -y

四、这些做完如果还是有报错

1、彻底更换软件源

编辑网络配置文件

echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 114.114.114.114" >> /etc/resolv.conf

2、替换软件源

# 备份所有原有repo文件
mkdir /etc/yum.repos.d/bak && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/# 下载阿里云的CentOS 8 Vault源(使用curl,若curl也没有则手动创建文件)
cat > /etc/yum.repos.d/CentOS-Base.repo << EOF
[baseos]
name=CentOS-8 - BaseOS - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/BaseOS/\$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official[appstream]
name=CentOS-8 - AppStream - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/AppStream/\$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
EOF

3、清理缓存并重建

yum clean all
yum makecache

4、验证源是否正常

yum repolist

结果:
在这里插入图片描述

5、尝试安装passwd 包

# 安装
yum install passwd -y
# 检查 passwd 命令是否可用
which passwd  # 应该显示 /usr/bin/passwd
passwd --help  # 显示命令帮助信息,确认正常工作

五、配置SSH连接

正常情况下系统中应该缺失很多软件,包括ssh等

1、安装ssh

某些命令报错请自行百度安装/font>

yum install openssh-server -y

2、启动

/usr/sbin/sshd -d

报错:
在这里插入图片描述
这是因为 SSH 服务缺少必要的主机密钥文件导致的,使用命令生成:

# 生成主机密钥(会自动创建 /etc/ssh/ 目录下的密钥文件)
ssh-keygen -A
# 生成后检查 /etc/ssh/ 目录下是否存在相关密钥文件:
ls -l /etc/ssh/ssh_host_*_key# 正常情况下会显示类似以下文件:
-rw------- 1 root root 1675 Aug 25 16:30 /etc/ssh/ssh_host_rsa_key
-rw-r--r-- 1 root root  398 Aug 25 16:30 /etc/ssh/ssh_host_rsa_key.pub
-rw------- 1 root root  511 Aug 25 16:30 /etc/ssh/ssh_host_ecdsa_key
-rw-r--r-- 1 root root  174 Aug 25 16:30 /etc/ssh/ssh_host_ecdsa_key.pub
-rw------- 1 root root  387 Aug 25 16:30 /etc/ssh/ssh_host_ed25519_key
-rw-r--r-- 1 root root   92 Aug 25 16:30 /etc/ssh/ssh_host_ed25519_key.pub

再次启动

# 直接启动 sshd
/usr/sbin/sshd
# 检查是否启动成功
ps -ef | grep sshd | grep -v grep
# 验证端口监听
ss -tulpn | grep sshd

在这里插入图片描述
设置开机自启

vi /etc/rc.d/rc.local

在文件末尾添加启动 SSH 的命令:

# 启动 SSH 服务
/usr/sbin/sshd

确保 rc.local 具有可执行权限:

chmod +x /etc/rc.d/rc.local

http://www.xdnf.cn/news/1363303.html

相关文章:

  • nmcli命令详解
  • Docker:网络连接
  • SQL性能调优
  • 2025年8月25日-8月31日(qtopengl+ue独立游戏)
  • 告别“复制粘贴”式换肤:我用Adobe XD组件变体与CC库,构建多品牌设计系统架构
  • THM Bricks Heist靶机
  • 新的 macOS 安装程序声称能够快速窃取数据,并在暗网上销售
  • 文入门Ubuntu:从零到精通的Linux之旅
  • 【ARM】MDK在debug模式下断点的类型
  • 中介者模式及优化
  • 使用EasyExcel根据模板导出文件
  • imx586手册和相机寄存器部分解读
  • 【Springboot】依赖注入方式
  • Linux 离线安装lrzsz(rz、sz上传下载小插件)
  • IntelliJ IDEA 新手入门教程-Java、Web、Maven创建(带图解)
  • 疯狂星期四文案网第49天运营日记
  • 使用现代 <img> 元素实现完美图片效果(2025 深度实战版)
  • 【图像处理基石】基于Real-ESRGAN的实时图像超分辨率技术实现
  • MongoDB vs MySQL:NoSQL 和 SQL 的核心区别与适用场景
  • Portswigger靶场之Visible error-based SQL injection通关秘籍
  • ADQ3系列USB 3.2接口版本数字化仪隆重登场
  • 将本地jar包推到远程仓库
  • KeepAlived+Haproxy实现负载均衡(SLB)
  • 集成电路学习:什么是Caffe深度学习框架
  • 聊聊负载均衡架构
  • OpenGL 几何着色器
  • Linux学习-TCP网络协议(补充)
  • ViT系列网络系统性分析:从架构创新到未来趋势
  • [QMT量化交易小白入门]-八十四、LSTM模型对期货市场的秒级Tick数据进行预测
  • AI背后使用的技术