KVM(二)libvirt

安装:
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值