Ubuntu虚拟机部署配置

news2024/10/5 15:23:17

目录

虚拟机镜像下载

VirtualBox7下载

VirtualBox7安装镜像流程

创建虚拟机

虚拟机挂单独硬盘

网络设置

检查虚拟机配置

 启动虚拟机

ubuntu配置

查询虚拟机IP地址

修改ROOT密码

 更新apt

NTP同步

挂载磁盘&关闭swap


虚拟机镜像下载

目前国内操作系统镜像源非常完备,下载速度也非常快:

镜像源地址
清华大学https://mirrors.tuna.tsinghua.edu.cn/
中科大http://mirrors.ustc.edu.cn/ubuntu-releases/20.04/
浙江大学http://mirrors.zju.edu.cn/ubuntu-releases/20.04/

目前最新的版本是23.04,保险起见我们使用22.10版本使用。

注意:

  • 如果只是为了尝鲜,可以选择最新的版本安装
  • 如果是后续还需要各种操作,不建议选择非常新的版本,否则出现问题都没处找
  • 镜像选择一般来说centos要更好一下,主要是习惯了Ubuntu的操作

VirtualBox7下载

下载地址:https://www.virtualbox.org/wiki/Downloads

说明:

  • 一定要安装virtualBox7,irtualBox7比virtualBox6多了很多功能,基本和VMWare差不多了

VirtualBox7安装镜像流程

创建虚拟机

说明:

  • 需要选中“跳过自动安装”

虚拟机挂单独硬盘

网络设置

说明:

  • 一般来说使用NAT网络就可以,NAT网络的效果是虚拟机可以使用HOST的网络,出去是没问题的,但是外部没法访问
  • NAT网络,NAT网络和NAT差不多,最大的区别是多个虚拟机可以共享一张网络,这样这些虚拟机可以互通,在virtualbox我就使用NAT网络,NAT网络对外使用NAT端口映射出22端口,这样就可以从外部访问
  • 桥接网卡:桥接网卡就是直接使用网卡资源,这时候最直接的效果就是路由器会DHCP分配一个IP地址
  • 我的实验环境如下图,我希望在我的笔记本上直接SSH连接虚拟机,所以我采用桥接网卡

检查虚拟机配置

 

 启动虚拟机

说明:

  • 不要更新,直接跳过配置,一路往下走
  • 记得需要安装SSH,不用认证,怎么简单怎么来
  • 在设置apt源地址可以将地址的域名改成aaa,避免在安装过程中下载文件导致时长太长

 

点击重启就算是安装完成了,启动虚拟机很快,目前三分钟可以拉一个虚拟机出来。

ubuntu配置

查询虚拟机IP地址

虚拟机已经安装好了,我们需要SSH登录到这台机器,但是新安装的虚拟机是没有ifconfig命令,所以我们需要ip addr查询到虚拟机IP地址:

可以查询到虚拟机IP地址:192.168.0.104

修改ROOT密码

sudo su root
passwd

 更新apt

阿里云:

root@ubuntu:/home/xuanchi# cat /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

中科大:

deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

阿里云的源不给力推荐中科大的apt源,速度非常快,更新apt:

apt update
apt upgrade

遇到错误:

Err:4 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
Get:5 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease [83.3 kB]
Err:5 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
Reading package lists... Done
W: GPG error: http://mirrors.aliyun.com/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
E: The repository 'http://mirrors.aliyun.com/ubuntu bionic InRelease' is not signed.

 公钥认证,我们把公钥加上,重试即可:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32

 此时会报出下面的告警:

root@ubuntu:/home/xuanchi# apt update
Hit:1 https://mirrors.ustc.edu.cn/ubuntu bionic InRelease
Hit:2 https://mirrors.ustc.edu.cn/ubuntu bionic-updates InRelease
Hit:3 https://mirrors.ustc.edu.cn/ubuntu bionic-backports InRelease
Hit:4 https://mirrors.ustc.edu.cn/ubuntu bionic-security InRelease
Hit:5 https://mirrors.ustc.edu.cn/ubuntu bionic-proposed InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
8 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: https://mirrors.ustc.edu.cn/ubuntu/dists/bionic/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: https://mirrors.ustc.edu.cn/ubuntu/dists/bionic-updates/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: https://mirrors.ustc.edu.cn/ubuntu/dists/bionic-backports/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: https://mirrors.ustc.edu.cn/ubuntu/dists/bionic-security/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: https://mirrors.ustc.edu.cn/ubuntu/dists/bionic-proposed/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.

说明:认证公钥之前是放在 /etc/apt/trusted.gpg,后面版本不在支持这种方式,而是一个公钥一个文件夹方式存放,搞一下:

root@ubuntu:/home/xuanchi# apt-key list
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
/etc/apt/trusted.gpg
--------------------
pub   rsa4096 2012-05-11 [SC]
      790B C727 7767 219C 42C8  6F93 3B4F E6AC C0B2 1F32
uid           [ unknown] Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com>

/etc/apt/trusted.gpg.d/ubuntu-keyring-2012-cdimage.gpg
------------------------------------------------------
pub   rsa4096 2012-05-11 [SC]
      8439 38DF 228D 22F7 B374  2BC0 D94A A3F0 EFE2 1092
uid           [ unknown] Ubuntu CD Image Automatic Signing Key (2012) <cdimage@ubuntu.com>

/etc/apt/trusted.gpg.d/ubuntu-keyring-2018-archive.gpg
------------------------------------------------------
pub   rsa4096 2018-09-17 [SC]
      F6EC B376 2474 EDA9 D21B  7022 8719 20D1 991B C93C
uid           [ unknown] Ubuntu Archive Automatic Signing Key (2018) <ftpmaster@ubuntu.com>

只需要重新导出一份然后再把老文件删掉就可以,注意那一串C0B2132指的是公钥序列号的后八位:

apt-key export C0B21F32 | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/ubuntu-me.gpg

 再执行apt upgrade会抛出下面错误:

The following packages have unmet dependencies:
 dpkg : Breaks: libapt-pkg5.0 (< 1.7~b) but 1.6.17 is to be installed
E: Broken packages

说明:执行下面的命令然后按照提示重新执行apt update就可以了

 sudo apt remove ubuntu-advantage-tools

NTP同步

Ubuntu不知道从什么版本开始,NTP同步使用timedatectl命令管理,查看当前NTP同步状态:

root@ubuntu-2:/home/xuanchi# timedatectl status
               Local time: Sat 2023-07-22 16:22:45 UTC
           Universal time: Sat 2023-07-22 16:22:45 UTC
                 RTC time: Sat 2023-07-22 16:22:45
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no
timedatectl set-ntp false
timedatectl set-ntp true

 此时再查询NTP状态:

root@ubuntu-2:/home/xuanchi# timedatectl status
               Local time: Sat 2023-07-22 16:24:37 UTC
           Universal time: Sat 2023-07-22 16:24:37 UTC
                 RTC time: Sat 2023-07-22 16:24:36
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

 重启系统出测试效果状态也是yes,那说明没问题了。

挂载磁盘&关闭swap

先看一下那个Disk可以使用:

root@ubuntu-2:/home/xuanchi# lsblk
NAME                      MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0                       7:0    0  63.3M  1 loop /snap/core20/1822
loop1                       7:1    0 111.9M  1 loop /snap/lxd/24322
loop2                       7:2    0  49.8M  1 loop /snap/snapd/18357
sda                         8:0    0    25G  0 disk
├─sda1                      8:1    0     1M  0 part
├─sda2                      8:2    0     2G  0 part /boot
└─sda3                      8:3    0    23G  0 part
  └─ubuntu--vg-ubuntu--lv 253:0    0  11.5G  0 lvm  /
sdb                         8:16   0    25G  0 disk
sr0                        11:0    1  1024M  0 rom

分区:

root@ubuntu-2:/home/xuanchi# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x71ed7307.

Command (m for help):


Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-52428799, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-52428799, default 52428799):

Created a new partition 1 of type 'Linux' and of size 25 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

root@ubuntu-2:/home/xuanchi# sudo mkfs.ext4 /dev/sdb
mke2fs 1.46.5 (30-Dec-2021)
Found a dos partition table in /dev/sdb
Proceed anyway? (y,N) y
Creating filesystem with 6553600 4k blocks and 1638400 inodes
Filesystem UUID: 1263fb1b-96a7-499a-bbc3-335002bb4675
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

写入/etc/fstab:

#/swap.img      none    swap    sw      0       0
/dev/sdb   /opt   ext4   defaults   0   0

把swap注释掉,同时把/dev/sdb加上,重启看看效果:

xuanchi@ubuntu-2:~$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                               97M  1.1M   96M   2% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   12G  4.8G  5.9G  45% /
tmpfs                              485M     0  485M   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/sdb                            25G   24K   24G   1% /opt
/dev/sda2                          2.0G  129M  1.7G   8% /boot
tmpfs                               97M  4.0K   97M   1% /run/user/1000

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/783539.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

2023-07-19力扣今日二题

链接&#xff1a; 2737. 找到最近的标记节点 题意&#xff1a; 给一个n节点有向图&#xff0c;求节点s和点集marked中的最短距离&#xff0c;没有可以的到达的点则返回-1 解&#xff1a; 摇了一题困难过了2/3&#xff0c;搞不定了 没有负权边的单源最短距离&#xff0c;迪…

代码-【2 单链表A、B交集存放到C】

1&#xff09;基本思想&#xff1a; A、B两个链表的元素均递增有序&#xff0c;所以可以按顺序&#xff0c;同时从A中和B中各取一个结点的值来对比&#xff1b;如果A中结点的值比较小&#xff0c;则A中的指针右移&#xff1b;如果B中的结点的值比较小&#xff0c;则B中的指针右…

优思学院|工程师学习六西格玛有什么用?

很久以前&#xff0c;世上没有当今盛行的各种简单易用的统计软件&#xff0c;那时复杂的统计分析只能依靠公司的统计顾问。而和他们在一起工作时&#xff0c;工程师必须知道怎样进行提问。 如果工程师缺乏对统计工具的认识&#xff0c;即使拿到正确的工具也于事无补。当顾问遇…

2. Makefile之目标、依赖(附示例)

一、本节概要 本专栏所有内容围绕Makefile官方文档进行刨析&#xff0c;给出详细具体示例做辅助理解手撕Makefile官方手册 二、Makefile中的目标和依赖 在一个简单的Makefile中&#xff0c;每条规则通常由以下几个部分组成&#xff1a; target ... : prerequisites ...rec…

修改虚拟机ip为静态ip

在使用虚拟机的时候&#xff0c;默认情况下使用的DHCP协议分配的动态IP地址&#xff0c;使得每次打开虚拟机后当前的IP地址都可能会发生变化&#xff0c;这样不方便管理。为了能够给当前虚拟机设置一个静态IP地址&#xff0c;方便后期使用XShell等连接工具进行连接&#xff0c;…

C/C++内存分布

C/C内存管理 1.C/C内存分布2.C语言中动态内存管理方法2.1 malloc/calloc/realloc/free 3.C内容管理方法3.1new/delete操作内置类型3.2 new和delete操作自定义类型 4.operator new与operator delete函数5.new和delete的实现原理5.1内置类型5.2自定义类型 6定位new表达式&#xf…

Libtorch 在x86_64的Linux 上部署时的版本问题

1. ubuntu 上安装了cuda12.1 和cuda 12.2 ,但是NVCC 指向的是10.1&#xff0c;但是10.1 又没有安装&#xff0c; 所以版本很混乱 ./usr/bin/nvcc -> 10.1./usr/lib/nvidia-cuda-toolkit/bin/nvcc-> 10.1./usr/local/cuda-12.1/bin/nvcc -> 12.1./usr/local/cuda-12.2…

RT-Thread快速入门-线程管理

在 RT-Thread 中&#xff0c;最基本的调度单位是线程&#xff0c;其他 RTOS 也叫任务。如果学习过或者了解过 RTOS&#xff0c;任务这种叫法是最为熟知的。 本篇文章来学习一下 RT-Thread 线程方面的内容。对于初学者来说&#xff0c;转换一下思维&#xff0c;建立多任务&…

Docker部署Redis集群详解【主从复制 + 哨兵模式】

前言 注意&#xff1a;该文章不会讲解Redis集群搭建的原理&#xff0c;只讲述如何通过Docker容器快速部署搭建Redis主从 哨兵模式的集群 准备工作&#xff1a; 一台云服务器 or 本地虚拟机&#xff08;CentOS和Ubuntu都可以&#xff09;安装好Docker环境&#xff08;Docker、…

ROS框架——发布者功能包和订阅者功能包进行bool类型数据结构的topic通讯

ROS框架——发布者功能包和订阅者功能包进行bool类型数据结构的topic通讯 code review! 文章目录 ROS框架——发布者功能包和订阅者功能包进行bool类型数据结构的topic通讯零.同时运行两个功能包一.发布者功能包1.1.文件结构1.2.bool\_publisher\_node.cpp1.3.CMakeLists.txt…

SpringBoot实战(二十一)集成 TLog 日志

目录 一、简介二、Maven依赖三、启动类集成四、测试1.服务简介2.服务A代码DemoController.javaDemoFeignClient.java 3.服务B代码4.测试结果 补充一&#xff1a;自定义日志标签模板补充二&#xff1a;SpanId的生成规则补充三&#xff1a;业务标签1.打印入参2.指定连接符3.打印常…

【深度学习-卷积神经网络CNN-基础】

文章目录 发展历史卷积神经网络的应用领域卷积的原理和作用卷积和传统的神经网络的区别 卷积网络的整体架构输入层卷积层池化层全连接层卷积和池化叠加多层卷积可以处理什么类型的数据卷积的超参数卷积最大的优势 卷积的细节卷积的原理卷积的参数卷积的次数步长 卷积核尺寸 边缘…

成为UI设计高手:如何规划和创建UI设计组件库!

今天给大家分享一篇关于组件化设计的总结&#xff0c;希望可以带给大家更多设计思考。 什么是组件化 组件化化是构成界面的最基础元素和重复出现控件的集合体&#xff0c;也就是常说的组件库。通过对基础元素和控件的规范命名与排列组合&#xff0c;最终形成一个可快速调用与便…

每日一题——地下迷宫(迷宫问题II)

迷宫问题&#xff08;地下迷宫&#xff09;——II 题目链接 前言&#xff1a; 这题是在昨天迷宫问题——I的基础上进行的变形&#xff0c;因此&#xff0c;如果昨天的题目没看或者对迷宫问题不怎么了解&#xff0c;建议先看看昨天的解析。 迷宫问题——I源代码&#xff1a; …

安装redis,适配阿里云服务器,Liunx安装redis

下载redis以及编译安装 下载redis文件 wget http://download.redis.io/releases/redis-6.0.8.tar.gz #下载redis压缩文件 tar xzf redis-6.0.8.tar.gz #解压缩 cd redis-6.0.8 make 查看是否安装了gcc编译输入gcc --version如果没有…

AtcoderABC236场

A - chukodaiA - chukodai 题目大意 题目要求交换字符串S中第a个字符和第b个字符的位置&#xff0c;并输出结果。 思路分析 借用临时变量t&#xff0c;进行记录交换。 时间复杂度 O(∣S∣) 输出交换后的字符串的时间复杂度为O(∣S∣)&#xff0c;其中∣S∣表示字符串SS的…

autohotkey实战:窗口透明化

文章目录 实现方法代码讲解WinGet和WinSet 注 本文采用的是V1版本语法 实现方法 窗口透明不仅实用性强&#xff0c;关键是非常炫酷&#xff0c;如果用AHK实现一个实时调节窗口透明度的工具&#xff0c;那么就可以一边敲代码&#xff0c;一边透过半透明的IDE&#xff0c;愉快地…

vue 3.0 如何实现 文本框只能输入数字 避免文字和符号

<input v-model.number"form.payTime" :min"0" type"number" οninput"valuevalue.replace(/[^0-9.]/g,)" type"text" /> v-model 后面的.numer 一定要加上不然没效果 οninput"valuevalue.replace(/[^0-9.]/g…

Pdb蛋白质数据库网址!+30蛋白质数据库网站!

蛋白质数据库是指专门存储蛋白质相关信息的数据库。它们收集、整理和存储大量的蛋白质数据&#xff0c;包括蛋白质序列、结构、功能、互作关系、表达模式、疾病关联等信息。蛋白质数据库提供了对这些数据的检索、查询和分析功能&#xff0c;为科学研究人员、生物信息学家和药物…

为什么deferred probe将设备挂入延迟链表而不是将驱动挂入延迟链表

1. 代码流程(drivers/base/dd.c) 可以看到在probe失败的时候(驱动返回-EPROBE_DEFER)是把设备挂到deferred_probe_pending_list上面的。 这就带来了一个疑问: 我当前明明是驱动加载的过程(driver_attach()->bus_for_each_dev()), 为什么要将设备挂到pending list上面而不是…