MacOS系统基于VMware Fusion配置Ubuntu 22.04LTS环境

本文涉及的产品
全局流量管理 GTM,标准版 1个月
公共DNS(含HTTPDNS解析),每月1000万次HTTP解析
云解析 DNS,旗舰版 1个月
简介: 这篇文章介绍了如何在MacOS系统上使用VMware Fusion虚拟化软件配置Ubuntu 22.04 LTS环境,包括自定义VMware Fusion网段、Ubuntu系统安装、配置root用户登录、设置静态IP地址、修改默认网卡名称、配置PS1变量、设置登录界面为字符界面、修改软件源和进行vim基础优化等步骤。

                                              作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.VMware Fusion自定义网段

1.什么是VMware Fusion

VMware Fusion是VMware公司推出MacOS的虚拟化解决方案,熟悉"VMware Workstation"的小伙伴使用起来很友好。

因为这两个产品均出自一家公司,很多设计套路几乎是一致的。MacOS的用户仅需要个别配置注意下。

2.自定义VMware Fusion网段

    1.停止vm网络服务
sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --stop 


    2.修改网段配置
# sudo vim /Library/Preferences/VMware\ Fusion/networking
...
# 仅需要修改VNET的网段,比如我将网段和子网掩码作如下修改。
answer VNET_8_HOSTONLY_NETMASK 255.255.255.0
answer VNET_8_HOSTONLY_SUBNET 10.0.0.0

    3.应用配置生效,会覆盖现有的网络配置文件
sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --configure
...

温馨提示:
    此步骤,会自动生成"/Library/Preferences/VMware\ Fusion/vmnet8/nat.conf"和"/Library/Preferences/VMware\ Fusion/vmnet8/dhcpd.conf"的配置文件,如果之前修改过的话会直接覆盖哟~



    4.启动vm网络服务
sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --start

二.Ubuntu 22.04LTS基本配置

1.安装ubuntu系统

基于VMware Fusion或者"VMware Workstation"软件环境安装Ubuntu 22.04LTS版本可参考我之前的笔记。

参考链接:

2.配置root用户登陆

    1.更新软件源
sudo apt update
sudo apt -y install gdm3 net-tools iputils-ping


    2.修改"gdm-password"配置文件
sudo vim /etc/pam.d/gdm-password 
...
# auth  required        pam_succeed_if.so user != root quiet_success


    3.修改"gdm-autologin"配置文件
sudo vim /etc/pam.d/gdm-autologin
...
# auth  required        pam_succeed_if.so user != root quiet_success


    4.修改sshd服务的配置文件
sudo vim /etc/ssh/sshd_config
...
PermitRootLogin yes


    5.重启sshd服务
sudo systemctl restart sshd


    6.配置root的密码
sudo passwd root

3.配置静态IP地址

    1.修改网卡的配置文件
root@yinzhengjie:~# cat /etc/netplan/00-installer-config.yaml 
# This is the network config written by 'subiquity'
network:
  ethernets:
    ens33:
      dhcp4: false
      addresses:
        - 10.0.0.99/24
      routes:
        - to: default
          via: 10.0.0.2
      nameservers:
        addresses:
            # 114 DNS
          - 114.114.114.114
          - 114.114.115.115
            # 阿里云DNS
          - 223.5.5.5
          - 223.6.6.6
            # 腾讯云DNS
          - 119.29.29.29
          - 119.28.28.28
            # 百度DNS
          - 180.76.76.76
            # Google DNS
          - 8.8.8.8
          - 4.4.4.4
  version: 2
root@yinzhengjie:~# 


    2.应用配置
root@yinzhengjie:~# netplan apply 
WARNING:root:Cannot call Open vSwitch: ovsdb-server.service is not running.
root@yinzhengjie:~# 

    3.测试登陆
yinzhengjie@bogon ~ % ssh root@10.0.0.128
ssh: connect to host 10.0.0.128 port 22: Host is down
yinzhengjie@bogon ~ % 
yinzhengjie@bogon ~ % ssh root@10.0.0.99 
The authenticity of host '10.0.0.99 (10.0.0.99)' can't be established.
ED25519 key fingerprint is SHA256:0nx8FS4qKOmN/qeKLRFMrY/MlyqRKzHGi6zmiMhS/1Q.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:1: 10.0.0.128
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.0.0.99' (ED25519) to the list of known hosts.
root@10.0.0.99's password: 
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-112-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

  System information as of Sat Jun  8 05:47:16 AM UTC 2024

  System load:  0.24853515625      Processes:              224
  Usage of /:   33.1% of 22.94GB   Users logged in:        2
  Memory usage: 14%                IPv4 address for ens33: 10.0.0.99
  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

Expanded Security Maintenance for Applications is not enabled.

24 updates can be applied immediately.
To see these additional updates run: apt list --upgradable

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


*** System restart required ***
Last login: Sat Jun  8 05:30:29 2024 from 10.0.0.1
root@yinzhengjie:~#

4.修改默认的网卡为ens33

    1.修改前查看网卡信息
root@yinzhengjie:~# ifconfig 
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.0.99  netmask 255.255.255.0  broadcast 10.0.0.255
        inet6 fe80::20c:29ff:fe7c:3446  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:7c:34:46  txqueuelen 1000  (Ethernet)
        RX packets 183808  bytes 254335961 (254.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 27678  bytes 2825913 (2.8 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 177  bytes 16580 (16.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 177  bytes 16580 (16.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

root@yinzhengjie:~# 

    2.修改配置文件
root@yinzhengjie:~# vim /etc/default/grub
...
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"


    3.用"grub-mkconfig"工具重新生成新的配置文件
root@yinzhengjie:~# grub-mkconfig -o /boot/grub/grub.cfg 
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.0-112-generic
Found initrd image: /boot/initrd.img-5.15.0-112-generic
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done
root@yinzhengjie:~# 


    4.查看网卡的配置信息
root@yinzhengjie:~# cat /etc/netplan/00-installer-config.yaml 
# This is the network config written by 'subiquity'
network:
  ethernets:
    eth0:
      dhcp4: false
      addresses:
        - 10.0.0.99/24
      routes:
        - to: default
          via: 10.0.0.2
      nameservers:
        addresses:
            # 114 DNS
          - 114.114.114.114
          - 114.114.115.115
            # 阿里云DNS
          - 223.5.5.5
          - 223.6.6.6
            # 腾讯云DNS
          - 119.29.29.29
          - 119.28.28.28
            # 百度DNS
          - 180.76.76.76
            # Google DNS
          - 8.8.8.8
          - 4.4.4.4
  version: 2
root@yinzhengjie:~# 


    5.重启虚拟机
root@yinzhengjie:~# reboot 
Connection to 10.0.0.99 closed by remote host.
Connection to 10.0.0.99 closed.
yinzhengjie@bogon ~ % 

    6.连接测试,观察网卡是否变更成功
yinzhengjie@bogon ~ % ssh root@10.0.0.99
root@10.0.0.99's password: 
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-112-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

  System information as of Sat Jun  8 06:42:43 AM UTC 2024

  System load:  0.59033203125      Processes:             296
  Usage of /:   33.2% of 22.94GB   Users logged in:       0
  Memory usage: 15%                IPv4 address for eth0: 10.0.0.99
  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

Expanded Security Maintenance for Applications is not enabled.

24 updates can be applied immediately.
To see these additional updates run: apt list --upgradable

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


Last login: Sat Jun  8 05:47:16 2024 from 10.0.0.1
root@yinzhengjie:~# 
root@yinzhengjie:~# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.0.99  netmask 255.255.255.0  broadcast 10.0.0.255
        inet6 fe80::20c:29ff:fe7c:3446  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:7c:34:46  txqueuelen 1000  (Ethernet)
        RX packets 265  bytes 303006 (303.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 118  bytes 17912 (17.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 115  bytes 9607 (9.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 115  bytes 9607 (9.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

root@yinzhengjie:~#

5.配置PS1变量

cat <<EOF >>  ~/.bashrc 
PS1='[\[\e[34;1m\]\u@\[\e[0m\]\[\e[32;1m\]\H\[\e[0m\]\[\e[31;1m\] \W\[\e[0m\]]# '
EOF
source ~/.bashrc

6.设置登陆界面为字符界面

    1.切换到字符界面
[root@yinzhengjie ~]# systemctl set-default multi-user.target
Created symlink /etc/systemd/system/default.target → /lib/systemd/system/multi-user.target.
[root@yinzhengjie ~]# 


    2.重启操作系统
[root@yinzhengjie ~]# reboot 
Connection to 10.0.0.99 closed by remote host.
Connection to 10.0.0.99 closed.
yinzhengjie@bogon ~ % 



温馨提示:
    我的环境默认安装的Ubuntu系统,对于VMware Fusion虚拟机打开发现是图形化界面,还没有终端可以操作。
    因此建议配置完成后,一定要将默认级别设置为字符界面,如果你真的很想用图形化界面,可以使用如下命令。
    方法一:
    systemctl set-default graphical.target

    方案二:
    startx

    方法三:
    init 5

7.修改软件源

    1.清华源 22.04 LTS为例:(**/etc/apt/sources.list**)
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse



    2.阿里源 ubuntu 22.04 LTS (jammy) 为例:(**/etc/apt/sources.list**)
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse



参考链接:
    https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
    https://developer.aliyun.com/mirror/ubuntu

8.vim基础优化

   1.定义vim文件模板【可自行修改】
[root@yinzhengjie ~]# cat .vimtpl 
#!/bin/bash
# Filename: %FILENAME%
# email: y1053419035@qq.com
# Author: 尹正杰(yinzhengjie) Jason Yin
# CurrentUser:  %USER%
# Date: %DATE%
# Version: %VERSION%
# Blog: https://www.cnblogs.com/yinzhengjie
# Description:  


[root@yinzhengjie ~]# 

    2.配置vim配置并引用模板
[root@yinzhengjie ~]# cat .vimrc 
" 设置字符编码为: utf-8
set encoding=utf-8

" 设置行号
set number

" 设置制表符宽度为4个空格
set tabstop=4
set shiftwidth=4

" 设置自动缩进和智能缩进
set autoindent
set smartindent

" 显示匹配的括号
set showmatch

" 开启自动换行
set wrap

" 开启搜索时忽略大小写
set ignorecase

" 高亮显示当前行
set cursorline

" 搜索时自动高亮匹配
set hlsearch

" 启用文件类型检测
filetype plugin on
filetype indent on

" 设置原样粘贴,避免粘贴变行之类的 
autocmd BufRead,BufNewFile * set paste

" 获取当前用户名                                                                                                                    
let s:current_user = $USER
" 设定默认版本号
let s:default_version = "v0.0.1"

" function! ReplaceTemplateVariables(timer_id)
function! YinZhengJieTpl(timer_id)
    let l:current_date = strftime("%Y-%m-%d")
    let l:current_filename = expand('%:t')

    " 替换对应的占位符
    execute "%s/%DATE%/" . l:current_date . "/g"
    execute "%s/%FILENAME%/" . l:current_filename . "/g"
    execute "%s/%User%/" . s:current_user . "/g"
    execute "%s/%VERSION%/" . s:default_version . "/g"
    " 设置光标位置
    call cursor(9, 20)
endfunction

" 安装 Timer 插件(如果尚未安装)
if !exists('g:loaded_timer') && !exists('g:did_timer_plugin')
    silent! timer defer timer_start 1
    let g:did_timer_plugin = 1 
endif

" 调用模板
autocmd BufNewFile *.sh 0r ~/.vimtpl | call timer_start(100, 'YinZhengJieTpl')

[root@yinzhengjie ~]# 


   3.测试效果,如上图所示
[root@yinzhengjie ~]# vim yinzhengjie-autoinstall-docker.sh
相关实践学习
通过Ingress进行灰度发布
本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
容器应用与集群管理
欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
目录
相关文章
|
1月前
|
固态存储 虚拟化 iOS开发
VMware ESXi 8.0U3c macOS Unlocker & OEM BIOS NVMe 驱动特殊定制版 (集成驱动版)
VMware ESXi 8.0U3c macOS Unlocker & OEM BIOS NVMe 驱动特殊定制版 (集成驱动版)
269 33
VMware ESXi 8.0U3c macOS Unlocker & OEM BIOS NVMe 驱动特殊定制版 (集成驱动版)
|
1月前
|
Ubuntu 计算机视觉 C++
Ubuntu系统下编译OpenCV4.8源码
通过上述步骤,你可以在Ubuntu系统上成功编译并安装OpenCV 4.8。这种方法不仅使你能够定制OpenCV的功能,还可以优化性能以满足特定需求。确保按照每一步进行操作,以避免常见的编译问题。
79 43
|
1月前
|
Ubuntu 计算机视觉 C++
Ubuntu系统下编译OpenCV4.8源码
通过上述步骤,你可以在Ubuntu系统上成功编译并安装OpenCV 4.8。这种方法不仅使你能够定制OpenCV的功能,还可以优化性能以满足特定需求。确保按照每一步进行操作,以避免常见的编译问题。
70 30
|
2月前
|
虚拟化 数据中心 iOS开发
VMware ESXi 8.0U3c macOS Unlocker & OEM BIOS xFusion (超聚变) 定制版
VMware ESXi 8.0U3c macOS Unlocker & OEM BIOS xFusion (超聚变) 定制版
115 12
VMware ESXi 8.0U3c macOS Unlocker & OEM BIOS xFusion (超聚变) 定制版
|
1月前
|
Ubuntu 计算机视觉 C++
Ubuntu系统下编译OpenCV4.8源码
通过上述步骤,你可以在Ubuntu系统上成功编译并安装OpenCV 4.8。这种方法不仅使你能够定制OpenCV的功能,还可以优化性能以满足特定需求。确保按照每一步进行操作,以避免常见的编译问题。
37 12
|
2月前
|
Kubernetes Linux 虚拟化
VMware Fusion 13.6.2 发布下载,现在完全免费无论个人还是商业用途
VMware Fusion 13.6.2 发布下载,现在完全免费无论个人还是商业用途
663 13
VMware Fusion 13.6.2 发布下载,现在完全免费无论个人还是商业用途
|
2月前
|
Ubuntu 芯片 开发者
Ubuntu 25 ARM 桌面系统抢先版发布:第一个Ubuntu ARM桌面系统
Ubuntu 25.04 将于2025年发布,首次支持ARM Desktop桌面版系统,为ARM架构设备如Mac M系列芯片、Raspberry Pi等带来全新的桌面体验。用户可通过虚拟机或双系统安装在Mac上运行Ubuntu ARM,抢先体验版已开放下载:[链接](https://www.baihezi.com/ubuntu/arm/desktop)。此版本不仅扩展了Ubuntu的硬件兼容性,还提供了丰富的功能和流畅的操作体验,适合开发者和技术爱好者尝试。
456 9
|
3月前
|
Ubuntu Linux 网络安全
linux系统ubuntu中在命令行中打开图形界面的文件夹
在Ubuntu系统中,通过命令行打开图形界面的文件夹是一个高效且实用的操作。无论是使用Nautilus、Dolphin还是Thunar,都可以根据具体桌面环境选择合适的文件管理器。通过上述命令和方法,可以简化日常工作,提高效率。同时,解决权限问题和图形界面问题也能确保操作的顺利进行。掌握这些技巧,可以使Linux操作更加便捷和灵活。
98 3
|
4月前
|
Ubuntu Linux 测试技术
Linux系统之Ubuntu安装cockpit管理工具
【10月更文挑战第13天】Linux系统之Ubuntu安装cockpit管理工具
343 4
Linux系统之Ubuntu安装cockpit管理工具
|
4月前
|
Ubuntu 编译器 计算机视觉
Ubuntu系统编译OpenCV4.8源码
【10月更文挑战第17天】只要三步即可搞定,第一步是下载指定版本的源码包;第二步是安装OpenCV4.8编译需要的编译器与第三方库支持;第三步就是编译OpenCV源码包生成安装文件并安装。