想学Docker,但没有多余的服务器?云主机又贵又麻烦?别让环境和成本成为你学习的拦路虎!本系列将带你用最经济、最灵活的方式——本地虚拟机,从零开始,每天只需投入半小时,轻松开启你的Docker之旅。第一天,我们将亲手搭建坚实的学习地基:在VMware中安装Debian 12。
一、为什么选择“虚拟机+Debian”这条无忧之路?
打消顾虑: 明确点出读者可能面临的困境——无物理服务器、云服务成本高、怕搞坏本地环境。
我们的解决方案:
【零成本】 VMware + 开源的Debian系统 = 零资金投入。
【绝对安全】 一个隔离的沙箱环境,随便折腾,宿主机丝毫无损。
【高度还原】 虚拟机环境与真实服务器高度相似,学到的技能无缝迁移。
【灵活便捷】 随时创建快照,实验失败一键恢复,学习效率倍增。
二、准备工作
1、硬件要求
硬件 | 规格 |
---|---|
CPU | Intel Core i7-8850U 4核8线程 |
内存 | 16GB |
2、软件要求
软件 | 版本 |
---|---|
VMware Workstation Pro | 17.6.1 build-24319023 |
Xshell | 8 |
debian-12.8.0-amd64-netinst.iso | 12.8.0 |
三、核心实战——手把手安装Debian 12
1、安装VMware
- 通过VMware官网下载
2、创建虚拟机
在新建虚拟机过程中,出于简化篇幅的目的,对于各步骤中保持默认选项的,不在本文档中给出,直接
"下一步"
即可。
- 启动并进入新建虚拟机流程:启动 VMware Workstation Pro,选择菜单 “文件 -> 新建虚拟机”。
- 选择操作系统安装方式:在 “安装客户机操作系统” 页面,选择 “稍后安装操作系统(S)”。
- 指定客户机操作系统版本:在 “选择客户机操作系统” 页面,选择 “Debian 12.x 64 位”。
- 命名虚拟机:在 “命名虚拟机” 页面,输入虚拟机名称 。
- 设置磁盘容量:在 “指定磁盘容量” 页面,设置 “最大磁盘大小(GB)” 为 36.0。
- 完成创建并进入编辑设置:后续步骤均采用 VMware 默认配置即可。创建完成后,库中会显示创建的虚拟机,点击 “编辑虚拟机设置”。
- 配置 ISO 映像文件:在编辑设置界面,设置虚拟机的 ISO 映像文件,通过 “浏览” 按钮选择之前下载好的 “debian-12.8.0-amd64-netinst.iso” 文件。
- 禁用侧通道缓解:为虚拟机设置禁用侧通道缓解,在 “选项” 页面,将 “高级 -> 为启用了 Hyper-V 的主机禁用侧通道缓解 (S)” 置为开启状态。
3、Debian系统安装
在安装系统过程中,出于简化篇幅的目的,对于各步骤中保持默认选项的,不在本文档中给出,直接回车或点击 Continue 即可。
- 点击开启此虚拟机,启动之前创建的虚拟机 :
- 在开机引导菜单中,选择第一项 Graphical Install。
- 在 Set up users and passwords 页面,为便于学习与记忆,设置 Root password 为 123456:
- 在 Set up users and passwords 页面,创建新用户,设置用户名全称为 rz:
- 在 Set up users and passwords 页面,为之前创建的用户 rz 设置密码 123456:
- 在 Partition disks 页面,对是否将分区方案写入磁盘,选择 Yes:
- 在 Configure the package manager 页面,Debian 的安装源国家选择 China:
- 在 Configure the package manager 页面,Debian 安装源选择为清华安装源: 用户也可以根据实际情况选择其他安装源。
- 在 Software selection 页面,设置安装的软件,本系统采用最小化安装,因此仅需要 SSH server 与 standard system utilities 两个软件包即可:
- 在 Install the GRUB boot loader 页面,设置 boot loader 安装位置为 /dev/sda:
- 安装过程的最后,在 Finish the installation 页面,点击 Continue,重启系统:
- 重启系统后,在系统引导页面,默认第一项即可,直接回车
- 将虚拟机 Debian12.08_Base 关机,选择菜单虚拟机 (M)-> 电源 (P)-> 关闭客户机 (D):
- 至此,系统安装完成。点击菜单虚拟机 (M)-> 快照 (N)-> 拍摄快照 (T):
- 拍摄快照之后,在虚拟机详细信息的快照部分,则显示为刚刚拍摄的快照名称系统安装完成。至此 Debian 安装完成
四、首次登录与基础配置
- 启动虚拟机
- 用用户名 rz、密码 123456 登录:
- 使用 ip addr 命令查看虚拟机的 IP 地址,以获取远程登录的 IP 地址信息:ens33 所对应的 IP 地址即为虚拟机IP地址:
- 安装vim
切换root用户,安装vim
rz@172:~$ vim
-bash: vim: command not found
rz@172:~$ su
Password:
root@172:/home/rz#
root@172:/home/rz#apt update
Hit:1 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm InRelease
Hit:2 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm-updates InRelease
Hit:3 http://security.debian.org/debian-security bookworm-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
root@172:/home/rz# apt install vim
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:libgpm2 libsodium23 vim-runtime
Suggested packages:gpm ctags vim-doc vim-scripts
The following NEW packages will be installed:libgpm2 libsodium23 vim vim-runtime
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 8,770 kB of archives.
After this operation, 41.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 libgpm2 amd64 1.20.7-10+b1 [14.2 kB]
Get:2 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 libsodium23 amd64 1.0.18-1 [161 kB]
Get:3 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 vim-runtime all 2:9.0.1378-2+deb12u2 [7,027 kB]
Get:4 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 vim amd64 2:9.0.1378-2+deb12u2 [1,568 kB]
Fetched 8,770 kB in 2s (4,141 kB/s)
Selecting previously unselected package libgpm2:amd64.
(Reading database ... 33534 files and directories currently installed.)
Preparing to unpack .../libgpm2_1.20.7-10+b1_amd64.deb ...
Unpacking libgpm2:amd64 (1.20.7-10+b1) ...
Selecting previously unselected package libsodium23:amd64.
Preparing to unpack .../libsodium23_1.0.18-1_amd64.deb ...
Unpacking libsodium23:amd64 (1.0.18-1) ...
Selecting previously unselected package vim-runtime.
Preparing to unpack .../vim-runtime_2%3a9.0.1378-2+deb12u2_all.deb ...
Adding 'diversion of /usr/share/vim/vim90/doc/help.txt to /usr/share/vim/vim90/doc/help.txt.vim-tiny by vim-runtime'
Adding 'diversion of /usr/share/vim/vim90/doc/tags to /usr/share/vim/vim90/doc/tags.vim-tiny by vim-runtime'
Unpacking vim-runtime (2:9.0.1378-2+deb12u2) ...
Selecting previously unselected package vim.
Preparing to unpack .../vim_2%3a9.0.1378-2+deb12u2_amd64.deb ...
Unpacking vim (2:9.0.1378-2+deb12u2) ...
Setting up libsodium23:amd64 (1.0.18-1) ...
Setting up libgpm2:amd64 (1.20.7-10+b1) ...
Setting up vim-runtime (2:9.0.1378-2+deb12u2) ...
Setting up vim (2:9.0.1378-2+deb12u2) ...
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto mode
Processing triggers for man-db (2.11.2-2) ...
Processing triggers for libc-bin (2.36-9+deb12u13) ...
root@172:/home/rz#
- 配置sshd服务允许root远程登录
sshd
服务默认不允许root
用户远程登录,需要进行单独的配置设置允许root
远程登录
# 打开配置文件
vim /etc/ssh/sshd_config
# 修改值
#PermitRootLogin prohibit-password
PermitRootLogin yes
# 重启sshd服务
systemctl daemon-reload
systemctl restart sshd
systemctl status sshd
● ssh.service - OpenBSD Secure Shell serverLoaded: loaded (/lib/systemd/system/ssh.service; enabled; preset: enabled)Active: active (running) since Mon 2025-09-29 09:19:35 EDT; 6s agoDocs: man:sshd(8)man:sshd_config(5)Process: 1337 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)Main PID: 1338 (sshd)Tasks: 1 (limit: 2257)Memory: 1.4MCPU: 19msCGroup: /system.slice/ssh.service└─1338 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
Sep 29 09:19:35 172 systemd[1]: Starting ssh.service - OpenBSD Secure Shell server...
Sep 29 09:19:35 172 sshd[1338]: Server listening on 0.0.0.0 port 22.
Sep 29 09:19:35 172 sshd[1338]: Server listening on :: port 22.
Sep 29 09:19:35 172 systemd[1]: Started ssh.service - OpenBSD Secure Shell server.
# 可以通过root用户登录到服务器
[C:\~]$ ssh root@192.168.3.56
Connecting to 192.168.3.56:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Linux 172 6.1.0-40-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.153-1 (2025-09-20) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
/usr/bin/xauth: file /root/.Xauthority does not exist
root@172:~#
- bash配置
Debian 12
最小化安装bash
不支持ll
等列表别名,也不支持命令Tab
补全。为bash
配置列表别名,以及命令Tab
补全。
# ls命令配置,使用vim编辑~/.bashrc,修改内容如下:
root@172:~# vim ~/.bashrc
# 复制以下内容替换您的 ~/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022
# You may uncomment the following lines if you want `ls' to be colorized:
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
if [ -n "$force_color_prompt" ]; thenif [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then# We have color support; assume it's compliant with Ecma-48# (ISO/IEC-6429). (Lack of such support is extremely rare, and such# a case would tend to support setf rather than setaf.)color_prompt=yeselsecolor_prompt=fi
fi
# 保存文件后执行 生效
source ~/.bashrc
常用工具batcat、tree、curl、wrk安装
安装本教程后续拟使用的
batcat
、tree
、curl
与wrk
apt install bat tree curl wrk -y
- 系统时区设置
# US时区
root@172:~# timedatectlLocal time: Mon 2025-09-29 09:39:16 EDTUniversal time: Mon 2025-09-29 13:39:16 UTCRTC time: Mon 2025-09-29 13:39:16Time zone: US/Eastern (EDT, -0400)
System clock synchronized: yesNTP service: activeRTC in local TZ: no
root@172:~# timedatectl set-timezone Asia/Shanghai
# 上海时区
root@172:~# timedatectlLocal time: Mon 2025-09-29 21:39:49 CSTUniversal time: Mon 2025-09-29 13:39:49 UTCRTC time: Mon 2025-09-29 13:39:49Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yesNTP service: activeRTC in local TZ: no
root@172:~#
五、总结与预告
1、今日完成系统安装和环境准备,建议进行快照设置
- 服务器关机
poweroff
- 创建快照