一、說明
上一章折騰了半天,搞出不少問題,今天我們在deepseek的幫助下,完成多個獨立ubuntu24.04實例的安裝,并完成固定ip,實踐證明,deepseek不靠譜,浪費我2個小時時間,我們將在下面實現,其實網上有很多信息比較舊
計劃安裝實例已經端口IP分配表
服務器順序 | 服務器名 | IP地址 | 端口 | 主機名 | 說明 |
---|---|---|---|---|---|
1 | mysql | 192.168.1.15 | 3306; ssh:2221 | mysql | 關系型數據庫 |
2 | redis | 6379;?ssh:2222 | 非關系型數據庫 | ||
3 | kkfileview | 8012;?ssh:2223 | kkfileview | 在線文件預覽 | |
4 | elasticsearch | 9200;?ssh:2224 | elasticsearch | 搜索和數據分析模型 | |
4 | kibana | 5601;?ssh:2224 | kibana | Kibana?是為Elasticsearch設計的開源分析和可視化平臺 | |
5 | minio | 服務端口:9000 控制臺:9001 ;?ssh:2225 | minio | 對象存儲 | |
6 | nacos | 注冊中心:8848 控制臺:9848 ;?ssh:2226 | nacos | 動態服務發現、配置管理和服務管理平臺 | |
7 | xxl-job-admin | 8080;?ssh:2227 | xxl-job-admin | 分布式任務調平臺 | |
8 | seata | ;?ssh:2228 | seata | 分布式事務 | |
9 | roncoo-education-gateway | 7700;?ssh:2229 | roncoo-education-gateway | 在線教育網關服務 | |
9 | roncoo-education-system | 7710;?ssh:2229 | roncoo-education-system | 在線教育系統服務 | |
9 | roncoo-education-user | 7720;?ssh:2229 | roncoo-education-user | 在線教育用戶服務 | |
9 | roncoo-education-course | 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
修改默認登錄用戶為x58win
sudo vi /etc/wsl.conf
添加內容
[user]
default=x58win
[boot]
systemd=true
?重啟wsl
?
# 安裝
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 2220sudo 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 測試
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
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、修改主機名
sudo vi /etc/wsl.conf[network]
hostname = mysql # 替換為你想要的主機名
generateHosts = false # 阻止 WSL 自動生成 hosts 文件
更新?/etc/hosts
?添加互相解析
sudo vi /etc/hosts
將x58 改為mysql
4、修改ssh端口
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
# 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,7730netsh 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 Allownetsh interface portproxy show v4tov4
# 在win11 管理員ps命令行下?
powershell.exe -ExecutionPolicy Bypass -File "D:\wsl\Script\MakeWslPort.ps1"