Starter

Summary: Author: 张亚飞 | 阅读时间: 2 minute read | Published: 2016-05-17
Filed under Categories: LinuxTags: Note,

VirtualBox 使用教程

本文使用 VirtualBox:6.1

下载 VirtualBox:6.1 并安装

wget https://download.virtualbox.org/virtualbox/6.1.10/VirtualBox-6.1.10-138449-OSX.dmg

配置 CentOS-8

下载官方系统镜像

mirror.centos.org

http://mirrors.aliyun.com/centos/8.2.2004/isos/x86_64/CentOS-8.2.2004-x86_64-minimal.iso
  • 附配置启动流程:

选择安装镜像文件

系统安装完后,需要关机并调整系统硬盘启动顺序,不然又会启动光驱从进入系统安装流程

  • 注意系统安装过程中可以设置 root 密码,并新建了用户 coam.

系统安装完后发现无法连接外部网络,需要配置开机启动网络服务

查看网络地址为: 10.0.2.15

[coam@localhost ~]$ ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::741a:d69a:a4ae:813  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:ff:11:3f  txqueuelen 1000  (Ethernet)
        RX packets 282  bytes 26169 (25.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 243  bytes 23979 (23.4 KiB)
        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 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 修改系统默认网络配置 /etc/sysconfig/network-scripts

/etc/sysconfig/network-scripts

[coam@localhost network-scripts]$ cat ifcfg-enp0s3
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s3
UUID=ab7b60d5-4eaa-4aa6-b5d4-568c591eed47
DEVICE=enp0s3
ONBOOT=no
  • 改成为下

/etc/sysconfig/network-scripts

[coam@localhost network-scripts]$ cat ifcfg-enp0s3
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s3
UUID=ab7b60d5-4eaa-4aa6-b5d4-568c591eed47
DEVICE=enp0s3
ONBOOT=yes

按教程重启 systemctl restart NetworkManager 发现无效,重启系统后才后发现可以连网了

yum install -y wget telnet

使用主机 SSH 连接网络

检测并配置端口转发

现在可以通过 SSH 连接虚拟主机了

ssh -p 6022 coam@127.0.0.1

本机终端SSH连接VirtualBox中的Linux虚拟机

  • 将普通用户 coam 加入 sudo 权限
#visudo
coam	ALL=(ALL:ALL) ALL

/var/lib/libvirt/boot

sudo wget http://mirrors.aliyun.com/centos/8.2.2004/isos/x86_64/CentOS-8.2.2004-x86_64-boot.iso
virt-install \
--virt-type=kvm \
--name centos8-vm \
--memory 1024 \
--vcpus=1 \
--os-variant=rhel8.1 \
--cdrom=/var/lib/libvirt/boot/CentOS-8.2.2004-x86_64-boot.iso \
--network=bridge=br0,model=virtio \
--graphics vnc \
--disk path=/var/lib/libvirt/images/centos8.qcow2,size=20,bus=virtio,format=qcow2

Comments

Cor-Ethan, the beverage → www.iirii.com