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

本文涉及的产品
容器服务 Serverless 版 ACK Serverless,952元额度 多规格
容器服务 Serverless 版 ACK Serverless,317元额度 多规格
云解析 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搭建和管理企业级网站应用
目录
相关文章
|
12天前
|
Ubuntu Linux 网络安全
Ubuntu 22.04 LTS有哪些新特性
Ubuntu 22.04 LTS有哪些新特性
|
1月前
|
Ubuntu 虚拟化
软件安装(二):VMware ubuntu20.04 安装步骤
这篇文章是关于如何在VMware Workstation 16 Player上安装Ubuntu 20.04桌面版的详细步骤指南。
169 2
软件安装(二):VMware ubuntu20.04 安装步骤
|
1月前
|
Ubuntu Linux 编译器
Linux/Ubuntu下使用VS Code配置C/C++项目环境调用OpenCV
通过以上步骤,您已经成功在Ubuntu系统下的VS Code中配置了C/C++项目环境,并能够调用OpenCV库进行开发。请确保每一步都按照您的系统实际情况进行适当调整。
275 3
|
1月前
|
Ubuntu
Ubuntu学习笔记(七):ubuntu下jupyter指定虚拟环境
本文介绍了如何在Ubuntu系统下使用Anaconda和Jupyter Notebook指定并切换不同的虚拟环境。
82 0
Ubuntu学习笔记(七):ubuntu下jupyter指定虚拟环境
|
1月前
|
Web App开发 Ubuntu 前端开发
【踩坑记】Ubuntu 20.04.6 LTS下编译安装gcc 4.4.0
【踩坑记】Ubuntu 20.04.6 LTS下编译安装gcc 4.4.0
|
2月前
|
Ubuntu 应用服务中间件 网络安全
Ubuntu 22.04环境下为Odoo开启80端口的方法
通过以上步骤,你应该能够在Ubuntu 22.04环境下为Odoo开启80端口。访问你的域名时,Nginx会将请求代理到Odoo,允许你通过80端口访问Odoo应用。
84 1
|
2月前
|
存储 Kubernetes Ubuntu
Ubuntu 22.04LTS版本二进制部署K8S 1.30+版本
这篇文章详细介绍了在Ubuntu 22.04 LTS系统上使用VMware Fusion虚拟化软件部署Kubernetes 1.30+版本的完整过程,包括环境准备、安装containerd、配置etcd、生成证书、部署高可用组件、启动Kubernetes核心组件以及网络插件的部署和故障排查。
145 4
|
2月前
|
Ubuntu Oracle 关系型数据库
Oracle VM VirtualBox之Ubuntu 22.04LTS双网卡网络模式配置
这篇文章是关于如何在Oracle VM VirtualBox中配置Ubuntu 22.04LTS虚拟机双网卡网络模式的详细指南,包括VirtualBox网络概述、双网卡网络模式的配置步骤以及Ubuntu系统网络配置。
248 3
|
3月前
|
关系型数据库 MySQL 数据库
【Mac os系统】安装MySQL数据库
本文详细介绍了在Mac OS系统上安装MySQL数据库的步骤,包括下载、安装、配置环境变量、启动服务、授权设置以及解决常见问题,并提供了一些常用的MySQL命令。
199 0
【Mac os系统】安装MySQL数据库
|
4月前
|
Linux 虚拟化 iOS开发
部署06--MacOS安装VMware Fusion安装
部署06--MacOS安装VMware Fusion安装