利用模板直接创建

1 利用已有虚拟机 制作配置文件模板文件

[root@kvm-server ~]# cat centos7-mod.xml
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:virsh edit centos7
or other application using the libvirt API.
--><domain type='kvm'><name>vm-name</name>  <!--这里修改了--><uuid>vm-uuid</uuid>  <!--这里修改了--><memory unit='KiB'>vm-mem</memory>  <!--这里修改了--><currentMemory unit='KiB'>vm-mem</currentMemory>  <!--这里修改了--><vcpu placement='static'>2</vcpu><os><type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type><boot dev='hd'/></os><features><acpi/><apic/></features><cpu mode='custom' match='exact' check='partial'><model fallback='allow'>SandyBridge-IBRS</model><feature policy='require' name='md-clear'/><feature policy='require' name='spec-ctrl'/><feature policy='require' name='ssbd'/></cpu><clock offset='utc'><timer name='rtc' tickpolicy='catchup'/><timer name='pit' tickpolicy='delay'/><timer name='hpet' present='no'/></clock><on_poweroff>destroy</on_poweroff><on_reboot>restart</on_reboot><on_crash>destroy</on_crash><pm><suspend-to-mem enabled='no'/><suspend-to-disk enabled='no'/></pm><devices><emulator>/usr/libexec/qemu-kvm</emulator><disk type='file' device='disk'><driver name='qemu' type='qcow2'/><source file='vm-disk-path'/>  <!--这里修改了--><target dev='vda' bus='virtio'/><address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/></disk><disk type='file' device='cdrom'><driver name='qemu' type='raw'/><target dev='hda' bus='ide'/><readonly/><address type='drive' controller='0' bus='0' target='0' unit='0'/></disk><controller type='usb' index='0' model='ich9-ehci1'><address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/></controller><controller type='usb' index='0' model='ich9-uhci1'><master startport='0'/><address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/></controller><controller type='usb' index='0' model='ich9-uhci2'><master startport='2'/><address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/></controller><controller type='usb' index='0' model='ich9-uhci3'><master startport='4'/><address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x2'/></controller><controller type='pci' index='0' model='pci-root'/><controller type='ide' index='0'><address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/></controller><controller type='virtio-serial' index='0'><address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/></controller><interface type='network'><mac address='52:54:00:vm-mac'/>  <!--这里修改了--><source network='default'/><model type='virtio'/><address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/></interface><serial type='pty'><target type='isa-serial' port='0'><model name='isa-serial'/></target></serial><console type='pty'><target type='serial' port='0'/></console><channel type='unix'><target type='virtio' name='org.qemu.guest_agent.0'/><address type='virtio-serial' controller='0' bus='0' port='1'/></channel><channel type='spicevmc'><target type='virtio' name='com.redhat.spice.0'/><address type='virtio-serial' controller='0' bus='0' port='2'/></channel><input type='tablet' bus='usb'><address type='usb' bus='0' port='1'/></input><input type='mouse' bus='ps2'/><input type='keyboard' bus='ps2'/><graphics type='spice' autoport='yes'><listen type='address'/><image compression='off'/></graphics><video><model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/><address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/></video><memballoon model='virtio'><address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/></memballoon><rng model='virtio'><backend model='random'>/dev/urandom</backend><address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/></rng></devices>
</domain>

创建虚拟磁盘

qemu-img create -f qcow2 /home/kvm/data/kube-master.qcow2 50G

创建新虚拟机的配置文件
vm_name=centos7-1
vm_uuid=uuidgen
vm_mem=1048576
vm_disk_path=/home/centos7-1.qcow2
vm_mac=openssl rand -hex 3 | sed -r 's/..\B/&:/g'
导入配置
root@kvm-server ~]# sed -r \

-e s%vm-name%vmname−esvm_name% \ -e s%vm-uuid%vmn​ame−esvm_uuid%
-e s%vm-mem%vmmem−esvm_mem% \ -e s%vm-disk-path%vmm​em−esvm_disk_path%
-e s%vm-mac%$vm_mac%
centos7-mod.xml > centos7-1.xml

自定义虚拟机

** virsh define centos7-1.xml**


利用kvm图形化 创建虚拟机

创建磁盘

qemu-img create -f qcow2 /home/kvm/data/kube-master.qcow2 50G

安装工具包,定制并获取到 ks.cfg 文件

yum -y install system-config-kickstart
system-config-kickstart

利用 virt-install 创建虚拟机

virt-install -v
–arch x86_64 --virt-type kvm
–name ${VM_NAME}
–memory ${MEM_SIZE}
–vcpus ${VCPUS}
–os-type ${OS_TYPE}
–location ${KVM_ISO}
–network default
–graphics none
–os-variant KaTeX parse error: Undefined control sequence: \ at position 14: {OS_VARIANT} \̲ ̲ --initrd-i…{KVM_KS_FILE}"
–extra-args “ks=file:/ks.cfg
console=tty0 console=ttyS0,115200n8
hostname=${HOST_NAME}”
–disk ${new_disk},cache=writeback,io=threads,bus=virtio
参数
–arch 指定平台架构

–virt-type 虚拟化类型 kvm 是最佳选择

–name 虚拟机名称

–memory 内存大小

–vcpus cpu 核心数

–os-type 操作系统类型

–os-variant 发行版本,必须是 virt-install 规定好的

–network 网络类型 default 是 NAT 类型的网络

–graphics 是否使用 vnc 这个的 none 意思是不使用

–location ISO 镜像文件路径

–initrd-inject 内核注入,指定一个 ks.cfg 文件的路径,会把此文件主人到跟目录下

–extra-args 额外的参数

ks=file:/ks.cfg 这个值不要变
console=ttyS0 表示使用 console 口控制服务器
–disk 指定虚拟硬盘文件路径

调整变量 创建虚拟机

kvm 上部署虚拟机两种方法相关推荐

  1. JavaBean实现多个文件上传的两种方法

    JavaBean实现多个文件上传的两种方法 王新芳        刘杰 北京工商大学计算机学院 摘要:本文介绍了JavaBean实现多个文件上传的两种方法,分别是使用http协议和ftp协议实现.首先 ...

  2. web自动化测试图片上传的两种方法

    web自动化测试图片上传的两种方法: 通过input标签的,如: <!DOCTYPE html> <html lang="en"> <head> ...

  3. 浏览器访问云服务器上图片的两种方法

    浏览器访问云服务器上图片的两种方法 1. Tomcat方式 打开tomcat的conf目录下配置文件server.xml 添加以下内容: <Context docBase="/home ...

  4. 提取图片上文字的两种方法

    目前我整理出两种方法: 第一种是利用onenote 插入照片-->点击图片右键,选择"复制图片中的文本"选项-->在当前onenote的空白处选择粘贴就好了(在其他地方 ...

  5. Yolo模型部署的两种方法

    目录 1 需求描述 第1种:封装darknet框架 第2种:weights模型转pb模型 2 weights模型转pb模型方法 3 重要备注 (1)关于预处理: (2)关于模型输入输出的数据结构和节点 ...

  6. Typora+PicGo+又拍云实现图片快速上传的两种方法

    Typora+PicGo+又拍云实现图片快速上传 第一步:注册个又拍云账户,加入又拍云联盟 又拍云 官网注册地址:又拍云联盟 - 开发者帮助计划,为开发者加速 - 又拍云 注册认证后有 10G 永久免 ...

  7. github东西无法下载_下载GitHub上文件的两种方法

    新进公司的时候,可能会遇到这样的情况:经理不会把项目文件复制拷贝给你,而是给你一个地址,自己去下载.今天我就来简单说几种如何在GitHub上下载文件的方法. 方法一 1.打开浏览器,进入github首 ...

  8. Centos7上安装Nginx两种方法

    源码编译安装 http://nginx.org/en/download.html 到官网下载,然后用XFTP上传到root目录 把文件解压出来 tar -zxvf nginx-1.16.0.tar.g ...

  9. 如何在文字上划横线_word怎么在字上划线的两种方法

    有时候在做笔记的时候,我们需要对一些暂时不需要的文字进行标记,用横线杠掉,那么应该怎样实现呢?在下面就由学习啦小编给大家分享下word在字上加横线的技巧,希望能帮助到您. word在字上划线方法一: ...

  10. 一百二十二、Git——Git上传代码两种方法,一是用IDEA,二是用小乌龟

    方式一.用IDEA (一)用IEDA   clone拉项目 File--New--Project from Version Control--Git 输入URL,选择Directory,点击clone ...

最新文章

  1. BeautifulSoup总结
  2. json格式的字符串序列化和反序列化的一些高级用法
  3. DNS 错误事件4000 4013
  4. snapchat_我刚刚在Snapchat获得开发人员职位。
  5. 0923接口——练习题作业
  6. babyion 加载obj模型_在vue中使用babylonjs引入3d模型,打印mesh数据正常且无报错,但未在场景中显示,请问是什么环节出现了问题?...
  7. No modules named ‘tensorflow.compat.v2‘
  8. shell基础--字符串和变量的操作
  9. ubuntu安装redis_在Ubuntu上安装Redis
  10. 开课吧:MySQL索引的使用知识有哪些?
  11. Juniper MIP
  12. 串联和并联拓扑PI控制器
  13. 基于 AWS 的一站式分布式数据库测试体系,简单易上手|TiDB Hackathon 2020 优秀项目分享
  14. 体验Solaris 中文斥地者x86版装置
  15. 服务器显示ping不通,服务器ping不通的原因
  16. Session/Cookie/Token还傻傻分不清?
  17. 学习笔记(05):【中国PHP教育大牛高洛峰】亲授php教程-PHP常量的介绍
  18. 贝叶斯推断应用:垃圾邮件过滤
  19. 重磅!瑞泰信息发布中国企业数字化增长行业实践白皮书——《数字化平台造就企业增长新引擎》
  20. C# / VB 获取PDF文档的数字签名信息

热门文章

  1. 【技巧】屏蔽百度搜索热点和相关软件推荐等(提高注意力)
  2. 数据仓库技术(Data Warehouse Technologien) 第三章节 多维数据模型(3)
  3. 计算机清除服务命令,快速清理电脑垃圾用什么命令
  4. pythonplotting,Sympy and plotting
  5. channel java_Java Channel
  6. Google Earth Engine简介
  7. win 10系统语言栏不见了怎么办?
  8. Linux学习笔记(1)--Linux的发展史
  9. 小皮面板安装以及pikachu环境搭建
  10. RS BCH级联编译码的性能仿真