栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

在linux环境非UI界面搭建虚拟机

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在linux环境非UI界面搭建虚拟机

在linux环境非UI界面搭建虚拟机 手动创建虚拟机

virtualBox的安装教程可以自行百度

1、创建虚拟机,centos是红帽出品,所以选择RedHat_64,可以使用 --basefolder /home/virtualbox/来指定目录

VBoxManage createvm --name k8s1 --ostype RedHat_64 --register

可以用命令 VBoxManage list ostypes(查看支持的操作系统类型)

2、创建磁盘

VBoxManage createvdi --filename /root/VirtualBox VMs/k8s1/k8s1.vdi --size 40000

3、创建硬盘控制器

VBoxManage storagectl k8s1 --name storage_controller_1 --add ide

4、挂载虚拟硬盘

VBoxManage storageattach k8s1 --storagectl storage_controller_1 --type hdd --port 0 --device 0 --medium /root/VirtualBox VMs/k8s1/k8s1.vdi

5、挂载虚拟光驱,需要保证 iso在硬盘中有

VBoxManage storageattach k8s1 --storagectl storage_controller_1 --type dvddrive --port 1 --device 0 --medium /home/CentOS-7-x86_64-Minimal-2009.iso

6、设置启动顺序,光驱第一,硬盘第二

VBoxManage modifyvm k8s1 --boot1 dvd
VBoxManage modifyvm k8s1 --boot2 disk

7、查看网卡,命令 ip addr,选择要桥接的网卡,我的网卡为team

VBoxManage modifyvm k8s1 --nic1 bridged --cableconnected1 on --nictype1 82540EM --bridgeadapter1 team --intnet1 brigh1 --macaddress1 auto

8、设置内存和CPU

VBoxManage modifyvm k8s1 --memory 8192
VBoxManage modifyvm k8s1 --cpus 2

9、远程桌面操作

# 设置远程桌面连接(可以使用VNC通过5540端口访问虚拟机桌面)
VBoxManage modifyvm k8s1 --vrdeport 5540 --vrdeaddress ""
VBoxManage modifyvm k8s1 --vrde on
VBoxManage modifyvm k8s1 --vrde off

9、启动虚拟机

VBoxManage startvm k8s1 -type headless
脚本批量创建

完整的shell命令如下,可以进行批量操作

#!/bin/bash
# createvm.sh
# 使用命令: sh createvm.sh k8s2 '/home/CentOS-7-x86_64-Minimal-2009.iso' team 5569
VMNAME="$1"
ISOPATH="$2"
NETCARD="$3"
VRDEPORT="$4"
echo "创建vm"
VBoxManage createvm --name "$VMNAME" --ostype RedHat_64 --register
echo "创建vdi"
VBoxManage createvdi --filename /root/VirtualBox VMs/"$VMNAME"/"$VMNAME".vdi --size 80000
echo "创建storagectl"
VBoxManage storagectl "$VMNAME" --name storage_controller_1 --add ide
echo "进行关联"
VBoxManage storageattach "$VMNAME" --storagectl storage_controller_1 --type hdd --port 0 --device 0 --medium /root/VirtualBox VMs/"$VMNAME"/"$VMNAME".vdi
echo "关联DVD"
VBoxManage storageattach "$VMNAME" --storagectl storage_controller_1 --type dvddrive --port 1 --device 0 --medium "$ISOPATH"
echo "设置启动顺序"
VBoxManage modifyvm "$VMNAME" --boot1 dvd
VBoxManage modifyvm "$VMNAME" --boot2 disk
echo "设置网卡"
VBoxManage modifyvm "$VMNAME" --nic1 bridged --cableconnected1 on --nictype1 82540EM --bridgeadapter1 "$NETCARD" --intnet1 brigh1 --macaddress1 auto
echo "设置内存和CPU"
VBoxManage modifyvm "$VMNAME" --memory 8192
VBoxManage modifyvm "$VMNAME" --cpus 2
echo "设置远程桌面连接"
VBoxManage modifyvm "$VMNAME" --vrdeport "$VRDEPORT"  --vrdeaddress ""
VBoxManage modifyvm "$VMNAME" --vrde on
echo "开机啦"
VBoxManage startvm "$VMNAME" -type headless

执行如下命令批量操作

sh createvm.sh k8s2 '/home/CentOS-7-x86_64-Minimal-2009.iso' team 5569
善后工作

点击windows电脑的远程桌面连接,输入宿主机的地址+vrde的端口,进入到linux安装界面。

修改网络配置,使IP和宿主机在同一网段

部分配置如下,之前有重复的配置进行修改,没有的添加

BOOTPROTO=static
onBOOT=yes
PREFIX=24
GATEWAY=192.168.80.254
DNS1=223.5.5.5
IPADDR=192.168.80.67

修改完成之后重启服务器即可

其他命令

虚拟机的信息

VBoxManage -v
VBoxManage list vms
VBoxManage list runningvms
VBoxManage showvminfo UbuntuRDHome
VBoxManage list hdds
VBoxManage list dvds

虚拟机的其他命令

# 关机
VBoxManage controlvm k8s1 poweroff
# 启动
VBoxManage startvm k8s1 --type headless
# 删除虚拟机,谨慎操作
VBoxManage unregistervm --delete k8s1

参考文章

[centos6.7 安装 virtualBox 再安装 centos 7]

VirtualBox命令行VBoxManage创建与管理虚拟机教程

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/741299.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号