Center OS KVM安装配置手册.doc
-作者xxxx-日期xxxxCenter OS KVM安装配置手册【精品文档】KVM安装配置手册一检查确认服务器是否开启CPU虚拟化功能# lsmod | grep kvmkvm_intel 170086 0kvm 566340 1 kvm_intelirqbypass 13503 1 kvm# echo 'ulimit -SHn 65535' >> /etc/profile# source /etc/profile# ulimit n# yum check-update && yum updaye -y# yum groupinstall “Development Tools”二KVM Network#yum install -y bridge-utils 新增网桥设备br0配置文件#vim /etc/sysconfig/network-scripts/ifcfg-br0DEVICE="br0"ONBOOT="yes"TYPE="Bridge"BOOTPROTO=staticDEFROUTE=yesNM_CONTROLLED=no 修改ifcfg-em1: # cat /etc/sysconfig/network-scripts/ifcfg-em1TYPE="Ethernet"PROXY_METHOD="none"BROWSER_ONLY="no"BOOTPROTO="none"DEFROUTE="yes"IPV4_FAILURE_FATAL="no"IPV6INIT="yes"IPV6_AUTOCONF="yes"IPV6_DEFROUTE="yes"IPV6_FAILURE_FATAL="no"IPV6_ADDR_GEN_MODE="stable-privacy"NAME="em1"UUID="c72f60ed-4e17-4297-8a16-ed3c9ab02e7d"DEVICE="em1"ONBOOT="yes"#IPADDR="172.168.1.160"#PREFIX="24"#GATEWAY="172.168.1.1"#DNS1="202.96.209.133"#DNS2="114.114.114.114"#DNS3="202.96.199.133"IPV6_PRIVACY="no"NM_CONTROLLED=noBRIDGE=br0蓝色注释 红色新加# systemctl disable NetworkManager# systemctl stop NetworkManager# systemctl restart network# ifconfig三Install KVM# yum -y install qemu-kvm libvirt virt-install bridge-utils policycoreutils-python# systemctl start libvirtd# systemctl enable libvirtd四安装桥接网络创建br0.xml 配置文件(文件中uuid保证唯一即可 <network><name>br0</name><uuid>fb48b969-b9f4-e859-d957-50aedd850fb4</uuid><forward mode='bridge'><bridge name ='br0'/></forward></network> virsh net-undefine br0 删除桥接网络# virsh net-list -all# virsh net-start br0# virsh net-autostart br0# virsh net-list -all# mkdir /var/kvm# semanage fcontext -a -t virt_image_t '/var/kvm(/.*)?'# restorecon -vvFR /var/kvm/五安装系统CentOS7# qemu-img create /var/kvm/centos7-base.img 10G# virt-install -virt-type kvm -name centos7-base -ram 1200 -disk /var/kvm/centos7-base.img -network bridge=br0 -graphics vnc,listen=0.0.0.0 -noautoconsole -os-type=linux -os-variant=centos7.0 # firewall-cmd -permanent -add-service=vnc-server# firewall-cmd -reload通过VNC连接服务器IP,举例172.168.1.160(宿主机)进行系统安装步骤操作安装系统要素:地区:Asia/Shanghai语言:English + 中文简体支持Software Selection:Basic WebServerInstallation Source:I will configure partitioning.ß重点/boot 1024Mswap 8172M 等同于内存大小值M/ 剩余全部三个分区:/boot、swap、/ 根目录,分区Standard Partion 或 LVM,默认磁盘格式xfsNetwork:选择已连接的网卡eth0 设定固定ip,且开启网卡安装完系统,重启虚拟机,再次VNC连接虚拟机Enable KVM Guest console# grubby -update-kernel=ALL -args="console=ttyS0"# vim /etc/default/grub file, add console=ttyS0 to the GRUB_CMDLINE_LINUX "GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap" rhgb quiet console=ttyS0" Now, reboot the virtual machine:# reboot# virsh console centos7-base/现在可以通过console 连接,VNC方式已不可用源镜像centos7-base配置完毕后,即可克隆机器# virsh suspend centos7-base /必须先挂起,完成后virsh resume centos7-base# virt-clone -connect qemu:/system -original centos7-base ß源VM -name cybs-172.168.1.159 ßNameß定义IMGvirt-clone -connect qemu:/system -original centos7-base 72 -.img# virsh list -all/显示所有VM# virsh console /connect vm更改克隆VM的对应IP及UUID末位数字为IP末两尾VM# systemctl restart networkVM# hostnamectl set-hostname hostname/修改hostname名称六销毁VM(补充)# virsh shutdown centos7-base# virsh undefine centos7-base复制镜像源到另一台机器,进行克隆rootdev160 # mkdir /var/kvmrootdev74 # scp centos7-base.xml root172.168.1.160:rootdev74 # scp /var/kvm/centos7-base.img root172.168.1.160:/var/kvm/rootdev160 # semanage fcontext -a -t virt_image_t '/var/kvm(/.*)?'rootdev160 # restorecon -vvFR /var/kvm/rootdev160 # virsh define /root/rootdev160 # virsh start centos7-baserootdev160 # virsh console centos7-base七KVM Rename VM# virsh shutdown vm# virsh domrename vm vm1# virsh start vm1【精品文档】