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

                                              作者:尹正杰

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

一.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版本可参考我之前的笔记。

参考链接:
	https://www.cnblogs.com/yinzhengjie/p/18253463

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


posted @ 2024-06-19 23:29  尹正杰  阅读(644)  评论(0编辑  收藏  举报