1.安装wsl2
Enable-WindowsOptionalFeature -Online -FeatureName $("Microsoft-Windows-Subsystem-Linux","VirtualMachinePlatform")
2.设置版本
wsl --set-default-version 2
3.更新wsl内核
wsl --update
4.重启wsl
wsl --shutdown
5.安装centos7
下载地址
6.设置默认
wsl --set-default CentOS7
7.移动位置
wsl --manage CentOS7 --move E:/wsl
8.进入wsl
wsl
9.安装yum加速地址
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum clean all
yum repolist
10.安装1panel
curl https://install.1panel.live/docker-install -o docker-install && sudo bash ./docker-install && rm -f ./docker-install
rm -rf /usr/bin/systemctl
curl http://res.a.hebei9.cn/safeware/systemctl.py > /usr/bin/systemctl
chmod +x /usr/bin/systemctl
11.修改docker配置
vi /lib/systemd/system/docker.service
#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd
12.启动docker
systemctl start docker
systemctl enable docker
systemctl status docker
curl -sSL https://resource.fit2cloud.com/1panel/package/quick_start.sh -o quick_start.sh && sh quick_start.sh
13.运行php容器
docker pull hyperf/hyperf:8.3-alpine-v3.19-swoole
docker run -d --name mineadmin --restart=always -v /mnt/e/www:/www -p 9501:9501 -p 9502:9502 -p 9503:9503 -it hyperf/hyperf:8.3-alpine-v3.19-swoole
14.安装nodejs
nvm install 22.11.0
nvm use 22.11.0
npm config set registry https://registry.npmmirror.com
15.安装yarn
npm install -g yarn
yarn config set registry https://registry.npmmirror.com
16.centos 开机自启
在centos7下运行
cd ~
vi start.sh
按i键修改,加入下面内容
#!/bin/sh
systemctl start 1panel.service
systemctl start docker
nohup /usr/sbin/sshd -D &
执行保存 esc键 然后 :wq 保存
赋予执行权限
chmod +x /root/start.sh
在window下加入开机自启动,快捷键win+R,输入以下命令打开的startup文件夹:
shell:startup
创建一个文件wsl-d.vbs
Set ws = WScript.CreateObject("WScript.Shell")
ws.run "wsl -d CentOS7",vbhide
ws.run "wsl -d CentOS7 -u root /root/start.sh", vbhide
17.sshd
ssh-keygen -A
修改sshd服务启动配置文件
vi /etc/ssh/sshd_config
#允许root用户登录
PermitRootLogin yes
#服务端口,为了不和windows及其它wsl子系统冲突,手动指定一个
Port 12308
#监听地址,如果需要远程机器连接
ListenAddress 0.0.0.0
启动sshd,查看服务已经启动
nohup /usr/sbin/sshd -D &
ps -ef|grep ssh
ln -s /mnt/e/www /opt/1panel/apps/openresty/openresty/www
虚拟平台异常:
dism.exe /Online /Enable-Feature /FeatureName:VirtualMachinePlatform /All
评论区