KVM虚拟化-libvirt杂记
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了KVM虚拟化-libvirt杂记相关的知识,希望对你有一定的参考价值。
一、libvirt
1、安装libvirt工具栈(CentOS7)
# 安装qemu-kvm
[[email protected] ~]# yum install qemu-kvm
# yum install libvirt libvirt-client virt-install virt-manager
安装时检测到冲突,需要根据报错卸载一些旧软件重新安装:
[[email protected] ~]# yum remove ipa-common ipa-client ipa-client-common
[[email protected] ~]# yum install ipa-common ipa-client ipa-client-common
1.1 启动libvirt服务
[[email protected] ~]# rpm -ql libvirt-daemon | grep service
/usr/lib/systemd/system/libvirtd.service
[[email protected] ~]# systemctl start libvirtd.service
1.2 配置文件路径
/etc/libvirt
2、virsh
2.1 查看正在运行的虚拟机
[[email protected] ~]# virsh list
Id Name State
----------------------------------------------------
2.2 打开virt-manager
[[email protected] ~]# virt-manager &
2.2.1 添加连接虚拟机
2.3 vrish命令杂项
2.3.1 查看当前主机性能
[[email protected] ~]# virsh capabilities
2.3.2 查看帮助
[[email protected] ~]# virsh help
只显示一段帮助
[[email protected] ~]# virsh help interface
2.3.3 添加网桥
[[email protected] ~]# virsh iface-bridge eth0 br0 --no-stp
使用附加设备 br0 生成桥接 eth0 失败
已启动桥接接口 br0
需要重启网卡服务,eth0的IP地址才会拆除:
[[email protected] ~]# systemctl restart network
[[email protected] ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29a77aec no eth0
3、创建管理虚拟机
3.0 需要先搭建好PXE环境
3.0.1 配置DHCP
[[email protected] ~]# yum install dhcp -y
拷贝配置文件:
[[email protected] ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf -f
配置:
[[email protected] ~]# vim /etc/dhcp/dhcpd.conf
option domain-name "master1.com";
option domain-name-servers 10.201.106.131,8.8.8.8;
default-lease-time 86400;
max-lease-time 86400;
subnet 10.201.106.0 netmask 255.255.255.0 {
range 10.201.106.10 10.201.106.20;
option routers 10.201.106.131;
filename "pxelinux.0";
next-server 10.201.106.131;
}
其他暂时注释掉:
.,$s/^[^#]/#/g
启动服务:
[[email protected] dhcp]# systemctl start dhcpd.service
3.0.2 配置TFTP(TFTP是基于守护进程运行的)
[[email protected] ~]# yum -y install tftp-server
配置:
安装和启动守护进程:
[[email protected] ~]# yum -y install xinetd
[[email protected] ~]# systemctl start xinetd.service
3.0.3 PXE安装配置
安装syslinux包
[[email protected] ~]# yum install -y syslinux
将引导文件复制到tftp默认目录
[[email protected] ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
复制光盘里面的isolinux目录下的文件
[[email protected] cdrom]# cp ./images/pxeboot/vmlinuz ./images/pxeboot/initrd.img /var/lib/tftpboot/
[[email protected] isolinux]# cp vesamenu.c32 splash.jpg boot.msg /var/lib/tftpboot/
需要在tftp再创建一个目录
[[email protected] isolinux]# mkdir /var/lib/tftpboot/pxelinux.cfg
复制一个文件并重名为default
[[email protected] cdrom]# cp isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
编辑default文件
[[email protected] ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default vesamenu.c32
#prompt 1
timeout 600
display boot.msg
menu title ####### Linux Install Menu #######
label install CentOS6
menu label Install or upgrade CentOS6.6 x86
menu default
kernel vmlinuz
append initrd=initrd.img ks=http://10.201.106.131/ks.cfg
3.0.4 准备Kickstar(ks)文件
安装制作Kickstart文件的命令
[[email protected] ~]# yum install -y system-config-kickstart
从其它centos6.6系统拷贝已经安装完毕的ks文件二次修改
[[email protected] ~]# scp anaconda-ks.cfg [email protected]:/root/ks.cfg
编辑另存ks文件
接下来的设置按需设置:
保存:
记得改这个地址
[[email protected] ~]# vim ks.cfg
repo --name="CentOS" --baseurl=http://10.201.106.131 --cost=100
3.0.5 配置httpd镜像源
安装开启http:
[[email protected] ~]# yum install -y httpd
注释欢迎页:
[[email protected] ~]# vim /etc/httpd/conf.d/welcome.conf
#<LocationMatch "^/+$">
# Options -Indexes
# ErrorDocument 403 /.noindex.html
#</LocationMatch>
修改默认目录并开启目录浏览权限:
[[email protected] ~]# vim /etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/centos6"
<Directory />
Options indexes FollowSymLinks
AllowOverride none
Require all granted
</Directory>
[[email protected] ~]# service httpd start
拷贝光盘所有文件到http目录
[[email protected] ~]# mkdir /var/www/centos6
[[email protected] ~]# mount /dev/cdrom /media/cdrom
[[email protected] ~]# cp -a /media/cdrom/* /var/www/centos6/
复制ks文件到http镜像目录
[[email protected] ~]# cp ks.cfg /var/www/centos6/
[[email protected] ~]# chmod +r /var/www/centos6/ks.cfg
3.1 创建虚拟机
[[email protected] ~]# virt-manager &
创建存储,不要立即分配:
设置桥接:
一些其它配置,按需配置:
IO调整
网卡也可调整成virtio
设置VNC显示:
定义完毕开始安装
等待全自动安装完毕:
以上是关于KVM虚拟化-libvirt杂记的主要内容,如果未能解决你的问题,请参考以下文章