标签:
[root@oldboy-node1 ~]# yum -y install qemu-kvm qemu-kvm-tools virt-manager libvirt virt-install
|
[root@oldboy-node1 ~]# grep -E "(vmx|svm)" /proc/cpuinfo
vmx:inter
svm:amd
[root@oldboy-node1 ~]# lsmod | grep kvm
kvm_intel 148081 0
kvm 461126 1 kvm_intel
|
[root@oldboy-node1 ~]# qemu-img create -f raw /opt/CentOS-7.1-x86_64.raw 10G
Formatting ‘/opt/CentOS-7.1-x86_64.raw‘, fmt=raw size=10737418240
|
[root@oldboy-node1 ~]# systemctl enable libvirtd.service
[root@oldboy-node1 ~]# systemctl start libvirtd.service
[root@oldboy-node1 ~]# systemctl status libvirtd.service
|
[root@oldboy-node1 ~]# dd if=/dev/cdrom of=/opt/CentOS-7.1.iso
|
[root@oldboy-node1 ~]#virt-install --name CentOS-7.1-x86_64 --virt-type kvm --ram 1024 --cdrom=/opt/CentOS-7.1.iso --disk path=/opt/CentOS-7.1-x86_64.raw --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole
|
net.ifnames=0 biosdevname=0
|
关闭虚拟机
virsh shudown CentOS-7.1-x86_64(主机名)
virsh destroy CentOS-7.1-x86_64(主机名)
打开虚拟机
virsh start CentOS-7.1-x86_64
删除虚拟机
virsh undefine CentOS-7.1-x86_64
查看虚拟机(全部)
virsh list --all
编辑虚拟机
virsh edit CentOS-7.1-x86_64
挂起
virsh suspended CentOS-7.1-x86_64
恢复
virsh resume CentOS-7.1-x86_64
|
ps -aux |grep kvm
|
只需要将虚拟机的网卡启动就可以,他的KVM机器会启动一个dhcp服务器。
[root@linux-node1 network-scripts]# ps aux|grep dns
nobody 2248 0.0 0.0 15524 880 ? S 14:07 0:00 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --dhcp-script=/usr/libexec/libvirt_leaseshelper
存在这里面
cat /var/lib/libvirt/dnsmasq/default.conf
strict-order
pid-file=/var/run/libvirt/network/default.pid
except-interface=lo
bind-dynamic
interface=virbr0
dhcp-range=192.168.122.2,192.168.122.254
dhcp-no-override
dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases
dhcp-lease-max=253
dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
按装 ifconfig工具
yum -y install net-tools
|
[root@linux-node1 network-scripts]# virsh edit CentOS-7.1-1-x86_64
原:<vcpu placement=‘static‘>1</vcpu>
现:<vcpu placement=‘auto‘ current=‘1‘>4</vcpu>
VCPU匹配方式是自动,当前是1,最大是4
需要重启才能实现
在虚拟机中查看
cat /proc/cpuinfo |grep "processor"|wc -l
1
在kvm中设置cpu
virsh setvcpus CentOS-7.1-x86_64 2 --live
如果没有的话,需要把上面的O置为1
virsh setvcpus CentOS-7.1-x86_64 3 --live
热添加只能加,不能减。(开机状态)
|
[root@linux-node1 network-scripts]# virt-install --help |grep cpu
--vcpus VCPUS Number of vcpus to configure for your guest. Ex:
--vcpus 5
--vcpus 5,maxcpus=10,cpuset=1-4,6,8
--vcpus sockets=2,cores=4,threads=2,
|
[root@linux-node1 network-scripts]# virsh edit CentOS-7.1-1-x86_64
最大内存<memory unit=‘KiB‘>4048576</memory>
当前内存<currentMemory unit=‘KiB‘>1048576</currentMemory>
|
标签:
原文地址:http://www.cnblogs.com/kevingrace/p/5252976.html