前言 该方式为刚去suning的时候物理机创建虚机的方式,块存储建虚机刚开始也是借鉴这个。
1.准备镜像和配置文件 1 2 3 4 准备好rhel63镜像文件rhel63.qcow2和配置文件rhel63.xml,放在/mnt/ data1/moban目录 curl -O -u vuser: suning@123 ftp: curl -O -u vuser: suning@123 ftp:
2.创建虚机系统盘镜像文件 1 cp /mnt/ data1/moban/ rhel63.qcow2 /mnt/ [data1|data2]/[主机名].qcow2
3.创建配置文件 1 cp /mnt/ data1/moban/ rhel63.xml /etc/ libvirt/qemu/ [主机名].xml
4.创建虚机数据盘镜像文件 1 qemu -img create -f qcow2 rhel63-data .qcow2 100G
5.修改配置文件
6.启动虚机 1 2 virsh define /etc/libvirt/qemu/[主机名].xml virsh start [主机名]
7.其它命令 (1) virsh命令 1 2 3 4 5 virsh list --all virsh shutdown [主机名] virsh destory [主机名] virsh undefine [主机名] virsh vncdisplay [主机名]
(2) 虚机需要做的事情 // 修改主机名

// 配置网络,重启网络

// 删除cloud相关的rpm包
1 rpm -qa |grep cloud |xargs rpm -e --nodeps
// 修改ssh为永不超时
1 2 3 4 5 6 vim /etc/init.d/network 注释如下两行 重启sshd服务 service sshd restart
(3) centos73-34.xml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 <domain type ='kvm' > <name > centos73-34</name > <uuid > e12767b1-290d-8149-d1fb-477da52bfadc</uuid > <memory unit ='KiB' > 2097152</memory > <currentMemory unit ='KiB' > 2097152</currentMemory > <vcpu placement ='static' > 2</vcpu > <os > <type arch ='x86_64' machine ='rhel6.5.0' > hvm</type > <boot dev ='hd' /> </os > <features > <acpi /> <apic /> <pae /> </features > <clock offset ='utc' /> <on_poweroff > destroy</on_poweroff > <on_reboot > restart</on_reboot > <on_crash > restart</on_crash > <devices > <emulator > /usr/libexec/qemu-kvm</emulator > <disk type ='file' device ='disk' > <driver name ='qemu' type ='qcow2' cache ='none' /> <source file ='/mnt/data1/centos73-34.qcow2' /> <target dev ='vda' bus ='virtio' /> <address type ='pci' domain ='0x0000' bus ='0x00' slot ='0x05' function ='0x0' /> </disk > <disk type ='file' device ='disk' > <driver name ='qemu' type ='qcow2' cache ='none' /> <source file ='/mnt/data1/centos-data-34.qcow2' /> <target dev ='vdb' bus ='virtio' /> <address type ='pci' domain ='0x0000' bus ='0x00' slot ='0x07' function ='0x0' /> </disk > <controller type ='usb' index ='0' > <address type ='pci' domain ='0x0000' bus ='0x00' slot ='0x01' function ='0x2' /> </controller > <controller type ='pci' index ='0' model ='pci-root' /> <interface type ='bridge' > <mac address ='52:54:00:bb:61:70' /> <source bridge ='br0' /> <model type ='e1000' /> <address type ='pci' domain ='0x0000' bus ='0x00' slot ='0x03' function ='0x0' /> </interface > <serial type ='pty' > <target port ='0' /> </serial > <console type ='pty' > <target type ='serial' port ='0' /> </console > <input type ='tablet' bus ='usb' /> <input type ='mouse' bus ='ps2' /> <input type ='keyboard' bus ='ps2' /> <graphics type ='vnc' port ='-1' autoport ='yes' listen ='0.0.0.0' > <listen type ='address' address ='0.0.0.0' /> </graphics > <sound model ='ich6' > <address type ='pci' domain ='0x0000' bus ='0x00' slot ='0x04' function ='0x0' /> </sound > <video > <model type ='cirrus' vram ='9216' heads ='1' /> <address type ='pci' domain ='0x0000' bus ='0x00' slot ='0x02' function ='0x0' /> </video > <memballoon model ='virtio' > <address type ='pci' domain ='0x0000' bus ='0x00' slot ='0x06' function ='0x0' /> </memballoon > </devices > </domain >
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 1 、搭建虚机环境10.27 .38 .242 :8 10.27 .38 .243 :7 10.27 .38 .244 :10 /etc/ssh/sshd_config 开始: cd /mnt/data1/moban # curl -O -u vuser:suning@ 123 ftp: # curl -O -u vuser:suning@ 123 ftp: cd /mnt/data2 cp /mnt/data1/moban/CentOS7U3.qcow2 /mnt/data2/dev-55. qcow2 cp /mnt/data1/moban/centos73-34. xml /etc/libvirt/qemu/dev-55. xml qemu-img create -f qcow2 dev-55 -data.qcow2 800 G vi /etc/libvirt/qemu/dev-55. xml virsh define /etc/libvirt/qemu/dev-55. xml virsh start dev-55 virsh list --all virsh vncdisplay dev-55 查看端口 vnc登录 修改虚机ip:vi /etc/sysconfig/network-scripts/ifcfg-eth0