【VirtualBox】Centos8通过命令行管理VirtualBox

背景

因业务需求安装应用程序在低配置(2H4G)服务器上,并且不能装有其他容器等,或者修改服务器IP、mac地址、增减或者减少容器、网络变化等环境变动,否则会造成授权失效。
那么公司的服务器配置都比较高,单独买台低配的服务器又没必要,就考虑到可以通过虚拟化进行处理。

X11vnc

可视化是必不可少的一步,安装操作系统需要使用到。
X11vnc安装文档

Viritulbal安装与使用

VirtualBox 官网下载地址

# 更新内核
sudo dnf update kernel -y
# 安装需要的kernel-headers等软件包,否则会报错
#vboxdrv.sh: failed: Look at /var/log/vbox-setup.log to find out what went wrong.
#
#There were problems setting up VirtualBox.  To re-start the set-up process, run
#  /sbin/vboxconfig
#  as root.  If your system is using EFI Secure Boot you may need to sign the
#  kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) before you can load
#  them. Please see your Linux system's documentation for more information.
sudo dnf install kernel-headers kernel-devel gcc make elfutils-libelf-devel -y
#安装vbox,该版本为我安装时的最新版本,如安装官网最新版本需要去官网获取链接自行下载即可。
[  ! -f VirtualBox-6.1-6.1.30_148432_el8-1.x86_64.rpm ] && wget https://download.virtualbox.org/virtualbox/6.1.30/VirtualBox-6.1-6.1.30_148432_el8-1.x86_64.rpm
#启动vbox
sudo /sbin/vboxconfig
# 以安装Centos8为例,创建虚拟机centos8VMServer1运行目录
mkdir -p /data/VirtualBox/centos8VMServer1
mkdir -p /data/VirtualBox/disk
mkdir -p /data/VirtualBox/images
# 创建虚拟机centos8VMServer1
VBoxManage createvm --name centos8VMServer1 --ostype Linux_64 --register --basefolder /data/VirtualBox/centos8VMServer1
# 创建虚拟机centos8VMServer1存储目录
VBoxManage createvdi --filename /data/VirtualBox/disk/centos8VMServer1.vdi --size 40000
#  创建虚拟机centos8VMServer1的存储控制器
cd /data/VirtualBox/disk/  && VBoxManage storagectl centos8VMServer1 --name centos8VMServer_controller_1 --add ide
#  创建虚拟机centos8VMServer1 挂载虚拟硬盘和虚拟光驱
VBoxManage storageattach centos8VMServer1 --storagectl centos8VMServer_controller_1 --type hdd --port 0 --device 0 --medium /data/VirtualBox/disk/centos8VMServer1.vdi
# 上传并在虚拟机centos8VMServer1导入centos8镜像 
VBoxManage storageattach centos8VMServer1 --storagectl centos8VMServer_controller_1 --type dvddrive --port 1 --device 0 --medium /data/VirtualBox/images/CentOS-8.3.2011-x86_64-minimal.iso
# 设置启动顺序
VBoxManage modifyvm centos8VMServer1 --boot1 dvd
VBoxManage modifyvm centos8VMServer1 --boot2 disk

# 根据宿在使用的主机网卡,我这边是做了链路聚合的虚拟网卡team0 ,为centos8VMServer1创建桥接网络
VBoxManage modifyvm centos8VMServer1 --nic1 bridged --cableconnected1 on --nictype1 82540EM --bridgeadapter1 team0 --intnet1 brigh1 --macaddress1 auto
# 调整系统参数CPU、内存等参数
VBoxManage modifyvm centos8VMServer1 --memory 4096
VBoxManage modifyvm centos8VMServer1 --cpus 4
# 启动虚拟机
VBoxHeadless -startvm centos8VMServer1

管理命令

# 查看当前运行的虚拟机
VBoxManage list runningvms
# 关闭虚拟机
VBoxManage controlvm centos8VMServer1 poweroff
# 休眠
VBoxManage controlvm centos8VMServer1 savestate
#后台运行
VBoxManage startvm centos8VMServer1  --type headless

启动后可以通过客户端VNC view远程连接服务端X11vnc进行图形化管理,安装操作系统等。

问题记录

通过vnc安装系统系统过程中出现花屏,将系统安装时,语言选择成英文即可避免。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大锅霍皮久

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值