在线教育网站项目第四步:deepseek骗我, WSL2不能创建两个独立的Ubuntu,但我们能实现实例互访及外部访问

一、说明

上一章折腾了半天,搞出不少问题,今天我们在deepseek的帮助下,完成多个独立ubuntu24.04实例的安装,并完成固定ip,实践证明,deepseek不靠谱,浪费我2个小时时间,我们将在下面实现,其实网上有很多信息比较旧

计划安装实例已经端口IP分配表

服务器顺序 服务器名 IP地址 端口 主机名 说明
1 mysql 192.168.1.15 3306; ssh:2221 mysql 关系型数据库
2 redis 192.168.1.15 6379; ssh:2222 非关系型数据库
3 kkfileview 192.168.1.15 8012; ssh:2223 kkfileview 在线文件预览
4 elasticsearch 192.168.1.15 9200; ssh:2224 elasticsearch 搜索和数据分析模型
4 kibana 192.168.1.15 5601; ssh:2224 kibana Kibana 是为Elasticsearch设计的开源分析和可视化平台
5 minio 192.168.1.15 服务端口:9000 控制台:9001 ; ssh:2225 minio 对象存储
6 nacos 192.168.1.15 注册中心:8848 控制台:9848 ; ssh:2226 nacos 动态服务发现、配置管理和服务管理平台
7 xxl-job-admin 192.168.1.15 8080; ssh:2227 xxl-job-admin 分布式任务调平台
8 seata 192.168.1.15 ; ssh:2228 seata 分布式事务
9 roncoo-education-gateway 192.168.1.15 7700; ssh:2229 roncoo-education-gateway 在线教育网关服务
9 roncoo-education-system 192.168.1.15 7710; ssh:2229 roncoo-education-system 在线教育系统服务
9 roncoo-education-user 192.168.1.15 7720; ssh:2229 roncoo-education-user 在线教育用户服务
9 roncoo-education-course 192.168.1.15 7730; ssh:2229 roncoo-education-course 在线教育课程服务
一共9台服务器
[服务器配置表]

推荐使用WSLMan 管理工具

Release v0.1.1.0 · jet2jet/WSLMan

二、安装Ubuntu-24.04

1、建立配置文件.wslconfig

在宿主机win11的登录用户目录下,建立文件.wslconfig,添加内容:

experimental

autoMemoryReclaim=gradual

networkingMode=mirrored

dnsTunneling=true

firewall=true

autoProxy=true

boot

systemd=true

2、选择安装新的分发

3、选择ubuntu24.04

4、安装

安装过程

安装完成

5、启动,添加用户密码

ip地址很有意思,192.168.1.15 是我主机的ip,也就是win11的地址,我们在上一篇文章中可不是这样的, 刚才我们建立的9台虚拟机ip地址都是一样,据说宿主机可以通过localhost访问所有的机器,这个就是添加了全局的.wslconfig有的效果,具体配置可以查资料,上面我们已经添加了

6、安装ssh

bash 复制代码
修改默认登录用户为x58win
sudo vi /etc/wsl.conf
添加内容
[user]
default=x58win
[boot]
systemd=true

重启wsl

bash 复制代码
# 安装
sudo apt-get update
sudo apt-get install openssh-server


##有错误,ssh.socket 是 systemd 的套接字单元,用于按需启动 SSH 服务(当有连接时启动)
Could not execute systemctl:  at /usr/bin/deb-systemd-invoke line 148.
dpkg: error processing package openssh-server (--configure):
 installed openssh-server package post-installation script subprocess returned error exit status 1

##解决方案
sudo systemctl stop ssh.socket      # 停止套接字
sudo systemctl disable ssh.socket   # 禁用开机启动

## 修改端口
sudo vi /etc/ssh/sshd_config
#Port 22 改为
Port 2220


sudo systemctl start ssh
sudo systemctl status ssh
sudo systemctl enable ssh

x58win@x58:~$ sudo vi /etc/ssh/sshd_config

x58win@x58:~$

x58win@x58:~$ sudo systemctl start ssh

x58win@x58:~$ sudo systemctl status ssh

● ssh.service - OpenBSD Secure Shell server

Loaded: loaded (/usr/lib/systemd/system/ssh.service; enabled; preset: enabled)

Active: active (running) since Wed 2025-03-19 18:19:16 CST; 10s ago

Docs: man:sshd(8)

man:sshd_config(5)

Process: 409 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)

Main PID: 411 (sshd)

Tasks: 1 (limit: 9510)

Memory: 1.2M (peak: 1.6M)

CPU: 48ms

CGroup: /system.slice/ssh.service

└─411 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

Mar 19 18:19:16 x58 systemd[1]: Starting ssh.service - OpenBSD Secure Shell server...

Mar 19 18:19:16 x58 sshd[411]: Server listening on 0.0.0.0 port 2220.

Mar 19 18:19:16 x58 sshd[411]: Server listening on :: port 2220.

Mar 19 18:19:16 x58 systemd[1]: Started ssh.service - OpenBSD Secure Shell server.

x58win@x58:~$ sudo systemctl enable ssh

Synchronizing state of ssh.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.

Executing: /usr/lib/systemd/systemd-sysv-install enable ssh

x58win@x58:~$

x58win@x58:~$ sudo ss -tulpn | grep ':2220'

tcp LISTEN 0 128 0.0.0.0:2220 0.0.0.0:* users:(("sshd",pid=411,fd=3))

tcp LISTEN 0 128 [::]:2220 [::]:* users:(("sshd",pid=411,fd=4))

测试

在win11 测试

bash 复制代码
ssh x58win@localhost -p 2220

PS C:\Windows\system32> ssh x58win@localhost -p 2220

The authenticity of host '[localhost]:2220 ([127.0.0.1]:2220)' can't be established.

ED25519 key fingerprint is SHA256:OvWuU6KZCq7AyIGzUwvNGsBwbnr3MlmnQ6knrTs9lwE.

This key is not known by any other names.

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Warning: Permanently added '[localhost]:2220' (ED25519) to the list of known hosts.

x58win@localhost's password:

Welcome to Ubuntu 24.04.2 LTS (GNU/Linux 6.6.75.1-microsoft-standard-WSL2 x86_64)

* Documentation: https://help.ubuntu.com

* Management: https://landscape.canonical.com

* Support: https://ubuntu.com/pro

System information as of Wed Mar 19 18:23:50 CST 2025

System load: 0.0 Processes: 29

Usage of /: 0.1% of 1006.85GB Users logged in: 1

Memory usage: 5% IPv4 address for eth0: 192.168.1.15

Swap usage: 0%

* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s

just raised the bar for easy, resilient and secure K8s cluster deployment.

https://ubuntu.com/engage/secure-kubernetes-at-the-edge

x58win@x58:~$ ls

在其它局域网,非宿主机win11

bash 复制代码
ssh x58win@192.168.1.15 -p 2220
# 就这样是不能连接的,有防火墙

打开2220转发
New-NetFirewallRule -DisplayName "WSL2 x58 ssh" -Direction Inbound -LocalPort 2220 -Action Allow -Protocol TCP
netsh interface portproxy show v4tov4

C:\Users\x230win10>ssh x58win@192.168.1.15 -p 2220

The authenticity of host '[192.168.1.15]:2220 ([192.168.1.15]:2220)' can't be established.

ED25519 key fingerprint is SHA256:OvWuU6KZCq7AyIGzUwvNGsBwbnr3MlmnQ6knrTs9lwE.

This key is not known by any other names.

Are you sure you want to continue connecting (yes/no/[fingerprint])? y

Please type 'yes', 'no' or the fingerprint: yes

Warning: Permanently added '[192.168.1.15]:2220' (ED25519) to the list of known hosts.

x58win@192.168.1.15's password:

Welcome to Ubuntu 24.04.2 LTS (GNU/Linux 6.6.75.1-microsoft-standard-WSL2 x86_64)

* Documentation: https://help.ubuntu.com

* Management: https://landscape.canonical.com

* Support: https://ubuntu.com/pro

System information as of Wed Mar 19 18:36:44 CST 2025

System load: 0.03 Processes: 34

Usage of /: 0.1% of 1006.85GB Users logged in: 1

Memory usage: 5% IPv4 address for eth0: 192.168.1.15

Swap usage: 0%

* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s

just raised the bar for easy, resilient and secure K8s cluster deployment.

https://ubuntu.com/engage/secure-kubernetes-at-the-edge

Last login: Wed Mar 19 18:23:51 2025 from 127.0.0.1

x58win@x58:~$

好,OK,搞了不少时间,那个ssh.socket的错误,在ubuntu 22上直接显示是这个错误,而ubuntu24上没有指名,ssh是必须安装的所以我们先装了

7、安装docker和docker-compose

按照前面的文章安装就行

在线教育网站项目第二步 :学习Vue3 + Nuxt3+springcloud,服务器为ubuntu24.04-CSDN博客https://blog.csdn.net/jiangkp/article/details/145995259

8、导出发行版

先expert出来,然后再import

选个目录,如果启动了,需要shutdown WSL

点击ok开始expert ,abort是停止运行

最后变为close,直接关闭即可

9、注销Ubuntu-24.04

注销掉就都没了,可以回去看看那个appdata目录下的东西都没有

原来安装的发行版没有了

目录下了也没有东西了

二、安装9台的服务器

mysql

redis

kkfileview

elasticsearch

minio

nacos

xxl-job-admin

seata

roncoo-education

选择上面导出的虚拟机,分发名字自己要安装虚拟机名字,自己要安装的地址

开始安装

完成

下面再建立8个,完全为了测试

三、配置各个实例

1、进入实例

先选下用户

比方说进入redis,看下面

2、查点想查的东西

x58win@x58:~$ docker --version

Docker version 28.0.1, build 068a01e

x58win@x58:~$ docker-compose --version

Docker Compose version v2.33.1

x58win@x58:~$ sudo systemctl status ssh

sudo\] password for x58win: ● ssh.service - OpenBSD Secure Shell server Loaded: loaded (/usr/lib/systemd/system/ssh.service; enabled; preset: enabled) Active: active (running) since Wed 2025-03-19 19:16:44 CST; 49s ago Docs: man:sshd(8) man:sshd_config(5) Process: 198 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS) Main PID: 214 (sshd) Tasks: 1 (limit: 9510) Memory: 2.1M (peak: 2.5M) CPU: 91ms CGroup: /system.slice/ssh.service └─214 "sshd: /usr/sbin/sshd -D \[listener\] 0 of 10-100 startups" Mar 19 19:16:44 x58 systemd\[1\]: Starting ssh.service - OpenBSD Secure Shell server... Mar 19 19:16:44 x58 sshd\[214\]: Server listening on 0.0.0.0 port 2220. Mar 19 19:16:44 x58 sshd\[214\]: Server listening on :: port 2220. Mar 19 19:16:44 x58 systemd\[1\]: Started ssh.service - OpenBSD Secure Shell server.

3、修改主机名

bash 复制代码
sudo vi /etc/wsl.conf

[network]
hostname = mysql  # 替换为你想要的主机名
generateHosts = false           # 阻止 WSL 自动生成 hosts 文件

更新 /etc/hosts 添加互相解析

sudo vi /etc/hosts

将x58 改为mysql

4、修改ssh端口

bash 复制代码
sudo sed -i 's/Port 2220/Port 2221/' /etc/ssh/sshd_config

对应端口在这里,22开头的就是ssh地址
"mysql8" = 2221,3306
"redis" = 2222,6379
"kkfileview" = 2223,8012
"elasticsearch" = 2224,9200,5601
"minio" = 2225,9000,9001
"nacos" = 2226,8848,9848
"xxl-job-admin" = 2227,8080
"seata" = 2228,8091
"roncoo-education" = 2229,7700,7710,7720,7730

重启

PS C:\Windows\system32> ssh x58win@192.168.1.15 -p 2221

The authenticity of host '[192.168.1.15]:2221 ([192.168.1.15]:2221)' can't be established.

ED25519 key fingerprint is SHA256:OvWuU6KZCq7AyIGzUwvNGsBwbnr3MlmnQ6knrTs9lwE.

This host key is known by the following other names/addresses:

C:\Users\x230win10/.ssh/known_hosts:1: [192.168.1.15]:2220

Are you sure you want to continue connecting (yes/no/[fingerprint])? y

Please type 'yes', 'no' or the fingerprint: yes

Warning: Permanently added '[192.168.1.15]:2221' (ED25519) to the list of known hosts.

x58win@192.168.1.15's password:

Welcome to Ubuntu 24.04.2 LTS (GNU/Linux 6.6.75.1-microsoft-standard-WSL2 x86_64)

* Documentation: https://help.ubuntu.com

* Management: https://landscape.canonical.com

* Support: https://ubuntu.com/pro

System information as of Wed Mar 19 19:55:45 CST 2025

System load: 0.23 Processes: 31

Usage of /: 0.2% of 1006.85GB Users logged in: 1

Memory usage: 5% IPv4 address for eth0: 192.168.1.15

Swap usage: 0%

* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s

just raised the bar for easy, resilient and secure K8s cluster deployment.

https://ubuntu.com/engage/secure-kubernetes-at-the-edge

Last login: Wed Mar 19 18:51:19 2025 from 192.168.1.8
x58win@mysql:~$ hostname
mysql

5、每个ubuntu24.04实例都要来一遍

四、配置Windows防火墙和端口转发

创建脚本 MakeWslPort.ps1

bash 复制代码
# powershell.exe -ExecutionPolicy Bypass -File "D:\wsl\Script\MakeWslPort.ps1"

# 脚本功能:为WSL实例分配固定IP并配置端口转发
$wslInstances = @("mysql", "redis","kkfileview","elasticsearch","minio","nacos","xxl-job-admin","seata","roncoo-education")
$ports = 80,443,2221,2222,2223,2224,2225,2226,2227,2228,2229,3306,6379,8012,9200,5601,9000,9001,8848,9848,8080,7700,7710,7720,7730

netsh interface portproxy reset # 清除所有端口转发规则

# 这里不需要添加
#foreach ($port in $ports) {
#	echo $port
#	netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=$port #connectaddress= 192.168.1.15 connectport=$port 
	# netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=443 #connectaddress=192.168.1.100 connectport=443
}

# 开放 TCP 端口 
New-NetFirewallRule -DisplayName "WebServer" -Direction Inbound -Protocol TCP -LocalPort 80,443,2221-2229,3306,6379,8012,9200,5601,9000,9001,8848,9848,8080,7700,7710,7720,7730 -Action Allow

netsh interface portproxy show v4tov4

在win11 管理员ps命令行下

powershell.exe -ExecutionPolicy Bypass -File "D:\wsl\Script\MakeWslPort.ps1"

相关推荐
七夜zippoe3 小时前
CANN Runtime任务描述序列化与持久化源码深度解码
大数据·运维·服务器·cann
盟接之桥4 小时前
盟接之桥说制造:引流品 × 利润品,全球电商平台高效产品组合策略(供讨论)
大数据·linux·服务器·网络·人工智能·制造
Fcy6485 小时前
Linux下 进程(一)(冯诺依曼体系、操作系统、进程基本概念与基本操作)
linux·运维·服务器·进程
袁袁袁袁满5 小时前
Linux怎么查看最新下载的文件
linux·运维·服务器
代码游侠5 小时前
学习笔记——设备树基础
linux·运维·开发语言·单片机·算法
主机哥哥5 小时前
阿里云OpenClaw部署全攻略,五种方案助你快速部署!
服务器·阿里云·负载均衡
Harvey9035 小时前
通过 Helm 部署 Nginx 应用的完整标准化步骤
linux·运维·nginx·k8s
珠海西格电力科技7 小时前
微电网能量平衡理论的实现条件在不同场景下有哪些差异?
运维·服务器·网络·人工智能·云计算·智慧城市
释怀不想释怀7 小时前
Linux环境变量
linux·运维·服务器
zzzsde7 小时前
【Linux】进程(4):进程优先级&&调度队列
linux·运维·服务器