Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

VMware Workstation 安裝 Ubuntu Server 完整指南:網絡 NAT 模式、SSH 遠程與常用服務部署

編輯:Linux 教學

安裝介質選擇

  • 推薦 Ubuntu Server LTS 版本(如 22.04/24.04),無桌面環境,ISO 約 1GB,安裝快、資源佔用低
  • 下載地址:https://ubuntu.com/download/server
  • 避免下載 Desktop 版(4GB+)或舊版本(7.04 等已停止維護)

VMware 虛擬機創建要點

# 硬件配置建議 (開發/測試環境)
CPU: 2 vCPU
內存: 2-4 GB
硬盤: 20-50 GB (SCSI 控制器,精簡置備)
網絡: NAT 模式 (vmnet8)
顯示: 自動檢測
聲音/USB/打印機: 移除 (節省資源)

安裝流程關鍵步驟

  1. 語言選擇 English(避免控制台中文亂碼)
  2. 鍵盤佈局:English (US)
  3. 網絡配置:DHCP 自動獲取(NAT 模式下 vmnet8 提供)
  4. 鏡像源:保持默認或選擇中國鏡像 (mirrors.aliyun.com/mirrors.tuna.tsinghua.edu.cn)
  5. 磁盤分區:Use entire disk + LVM(彈性擴容)
  6. 用戶創建:username: admin,勾選安裝 OpenSSH Server
  7. 等待安裝完成,重啟登錄

NAT 模式網絡深度配置

VMware 虛擬網絡結構

宿主機 (Windows/Linux)
├── VMnet8 (NAT)  192.168.83.0/24
│   ├── 宿主機適配器: 192.168.83.1
│   ├── NAT 設備(網關): 192.168.83.2  <-- 虛擬機默認網關
│   ├── DHCP 池: 192.168.83.128-254
│   └── 虛擬機 eth0: 192.168.83.x (DHCP 獲取)
└── VMnet1 (Host-Only) 192.168.19.0/24 (可選)

靜態 IP 配置 (推薦固定 IP 便於 SSH)

# Ubuntu 20.04+ 使用 Netplan
sudo vim /etc/netplan/00-installer-config.yaml

network:
  version: 2
  ethernets:
    ens33:           # 接口名 ip link 確認
      dhcp4: false
      addresses: [192.168.83.200/24]
      routes:
        - to: default
          via: 192.168.83.2        # NAT 網關
      nameservers:
        addresses: [192.168.83.2, 8.8.8.8, 114.114.114.114]

# 生效
sudo netplan apply

# 驗證
ip addr show ens33
ping -c 3 8.8.8.8
ping -c 3 www.baidu.com

宿主機訪問虛擬機

  • NAT 模式下宿主機可直接訪問虛擬機 IP (192.168.83.200)
  • 虛擬機訪問外網經由 NAT 設備 (192.168.83.2) 轉發
  • 若需外部訪問虛擬機,配置 VMware "虛擬網絡編輯器" -> NAT 設置 -> 端口轉發

Root 賬號啟用與 SSH 強化

# 1. 設置 root 密碼
sudo passwd root

# 2. 允許 root SSH 登錄 (生產環境建議禁用,改用 sudo)
sudo vim /etc/ssh/sshd_config
PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication yes  # 建議改為 no,強制密鑰登錄
# 重啟
sudo systemctl restart sshd

# 3. 生成密鑰對 (宿主機操作)
ssh-keygen -t ed25519 -C "vm-ubuntu"
ssh-copy-id root@192.168.83.200

# 4. 禁用密碼登錄 (驗證密鑰登錄成功後)
sudo vim /etc/ssh/sshd_config
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no
sudo systemctl restart sshd

基礎系統優化與軟件源

# 1. 切換阿里雲/清華源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vim /etc/apt/sources.list
# 參考 https://mirrors.aliyun.com/help/ubuntu

# 2. 更新系統
sudo apt update && sudo apt upgrade -y
sudo apt autoremove -y

# 3. 安裝常用工具
sudo apt install -y vim git curl wget htop net-tools tree unzip \
                    build-essential linux-headers-$(uname -r) \
                    zsh tmux ncdu iotop iftop

常用服務快速部署

Docker 容器引擎

# 官方便捷腳本
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
sudo usermod -aG docker $USER
newgrp docker

# 驗證
docker run --rm hello-world

Nginx 反向代理/靜態服務

sudo apt install -y nginx
sudo systemctl enable --now nginx
# 配置: /etc/nginx/sites-available/default

MySQL/PostgreSQL 數據庫

# MySQL 8.0
sudo apt install -y mysql-server
sudo mysql_secure_installation

# PostgreSQL 14+
sudo apt install -y postgresql postgresql-contrib
sudo -u postgres psql -c "CREATE USER dev WITH PASSWORD 'pass'; CREATE DATABASE devdb OWNER dev;"

Redis 緩存

sudo apt install -y redis-server
sudo systemctl enable --now redis-server
# 配置: /etc/redis/redis.conf (bind 0.0.0.0, requirepass)

VSFTPD 文件傳輸

sudo apt install -y vsftpd
sudo vim /etc/vsftpd.conf
# 關鍵配置:
listen=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=40100
sudo systemctl restart vsftpd

防火牆與安全基線

# UFW 簡單防火牆
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp    # SSH
sudo ufw allow 80/tcp    # HTTP
sudo ufw allow 443/tcp   # HTTPS
sudo ufw allow 3306/tcp  # MySQL (僅信任 IP)
sudo ufw enable

# Fail2Ban 防暴力破解
sudo apt install -y fail2ban
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo vim /etc/fail2ban/jail.local
# [sshd] enabled=true, maxretry=3, bantime=3600
sudo systemctl enable --now fail2ban

快照與備份策略

  • VMware 快照:重大變更前(內核升級、配置調整)創建快照
  • 文件級備份:rsync -aHAX /etc /home /var/www /backup/ 定時同步
  • 數據庫備份:mysqldump/pg_dump 邏輯備份 + 物理備份 (xtrabackup/pg_basebackup)
  • 鏡像導出:定期導出 OVF 模板,異地存儲
Copyright © Windows教程網 All Rights Reserved