安装:
centos6:yum install libvirt libvirt-client python-virtinst virt-manager
centos7: yum install libvirt libvirt-client libvirt-client virt-manager
libvirt和libvirtd的配置文件:
libvirt配置文件:/etc/libvirt/libvirt.conf virsh命令
守护进程配置文件:/etc/libvirt/libvirtd.conf 提供virt服务,支持远程
/etc/libvirt/qemu/networks/default.xml 定义了virbr0 支持dhcp
#virsh list
#virsh iface-bridge ens33 br0 --no-stp //配置后需要重启网络服务
域配置文件:xml格式
<vcpu p;acement=‘static’>2
使用示例:
(1)镜像iso安装系统
virt-install -n "centos6" -r 512 --vcpus=2 -l http://172.16.9.1/cobbler/ks_mirror/CentOS-6.6-x86_64/ -x "ks=http://172.16.9.1/centos.x86_64.cfg" --disk path=/images/kvm/centos6.img,size=120,sparse --force -w bridge=br100,model=virtio
(2)PXE安装
virt-install -n "centos6" -r 512 --vcpus=2,maxvcpus=4 -pxe -x "ks=http://172.16.9.1/centos.x86_64.cfg" --disk path=/images/kvm/centos6.qcow2,size=120,format=qcow2,bus=virtio,sparse --network bridge=br0,model=virtio --force
(3)通过ISO文件安装
virt-install --virt-type kvm --name centos7.91 --ram 1024 --vcpus 2 --disk path=/images/kvm/centos7.85.img,size=10,format=qcow2,bus=virtio,sparse --network bridge=br0,model=virtio --graphics vnc --cdrom ~/boot.iso --os-variant rhel7
请注意以下几个细节
(1)–disk 后跟的path=可省略 --disk /images/kvm/centos.img
(2)–ram 1024 默认单位为m,不用加在数字后
(3)–disk size 10 默认为G,也不用加单位
(4)–cdrom ~/boot.iso 使用需要修改qemu.conf文件配置,才有权限使用
在使用virt-install安装虚拟机时,出现无法读取ISO磁盘映像问题,日志如下:
[root@CentOS65 ~]# virt-install --name=centos65 --ram=2048 --vcpu=1 --os-type=linux --hvm --cdrom=/root/CentOS-6.5-x86_64-minimal.iso --file=/home/kvm/centos65.img --file-size=10 --bridge=br0 --vnc --vncport=5920
Starting install...
Creating storage file centos65.img | 10 GB 00:00
ERROR internal error Process exited while reading console log output: char device redirected to /dev/pts/4
上述“Permission denied”问题,属于用户权限问题,查看/etc/libvirt/qemu.conf配置文件,查找到如下相关的配置项:
开启user=root和group=root项
# The user for QEMU processes run by the system instance. It can be
# specified as a user name or as a user id. The qemu driver will try to
# parse this value first as a name and then, if the name doesn't exist,
# as a user id.
#
# Since a sequence of digits is a valid user name, a leading plus sign
# can be used to ensure that a user id will not be interpreted as a user
# name.
#
# Some examples of valid values are:
#
# user = "qemu" # A user named "qemu"
# user = "+0" # Super user (uid=0)
# user = "100" # A user named "100" or a user with uid=100
#
user = "root"
# The group for QEMU processes run by the system instance. It can be
# specified in a similar way to user.
group = "root"
配置修改完成后,需要重启libvirtd服务
[root@CentOS65 ~]# service libvirtd restart
[root@CentOS74 ~]# systemctl restart libvirtd