简明扼要kvm安装

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiaoying5191/article/details/79955276

本来打算使用ESXi进行虚拟机的创建和管理,公司只给了一台台式机进行部署,找了好几个版本,台式机电脑cpu有点老,加上机器是个组装机。虽然支持虚拟化,但是Esxi死活装不上,总是卡在O.E.M。正好机器没有什么用途,并且机器系统是新装的CentOS7.4,所以直接转向KVM。

kvm部署

必要条件:

  • cpu支持虚拟化:

    命令 egrep '(vmx|svm)' /proc/cpuinfo
    查看cpu信息包含vmx或者svm表示支持虚拟化

  • 关闭SELinux:

    sed -i 7's/enforcing/disabled/' /etc/sysconfig/seliunx

安装步骤:

  • 安装epel源: yum -y install epel-release net-tools
  • 安装kvm和依赖:yum -y install qemu-kvm libvirt virt-install bridge-utils
  • 命令lsmod | grep kvm用来检测是否安装成功
    • 新建桥接网卡:

    • 备份当前网卡文件ifcfg-enp2s0,备份文件不能存在/etc/sysconfig/network-scripts/目录和其子目录下。

    • 新建网卡ifcfg-enp2s0,并填入内容:

      TYPE=Ethernet
      DEFROUTE=yes
      NAME=enp2s0
      DEVICE=enp2s0
      ONBOOT=yes
      BRIDGE=br0
      BOOTPROTO=none
      IPV6INIT=no
      NM_CONTROLLED=no
    • 新建网卡文件ifcfg-br0,并定义网卡类型为桥接

      ifcfg-br0
      BOOTPROTO=static
      DEVICE=br0
      TYPE=Bridge
      NM_CONTROLLED=no
      IPADDR=192.168.100.50
      NETMASK=255.255.255.0
      GATEWAY=192.168.100.1
      DNS1=202.106.0.20
      DNS2=8.8.8.8
  • 重启网络服务:systemctl restart network并查看一下网络:ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000
    link/ether 00:e0:4c:31:21:0e brd ff:ff:ff:ff:ff:ff
    inet6 fe80::2e0:4cff:fe31:210e/64 scope link 
       valid_lft forever preferred_lft forever
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether 00:e0:4c:31:21:0e brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.50/24 brd 192.168.100.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::2e0:4cff:fe31:210e/64 scope link 
       valid_lft forever preferred_lft forever
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
    link/ether 52:54:00:3d:db:16 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
    link/ether 52:54:00:3d:db:16 brd ff:ff:ff:ff:ff:ff
10: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN qlen 1000
    link/ether fe:54:00:b8:26:dc brd ff:ff:ff:ff:ff:ff
    inet6 fe80::fc54:ff:feb8:26dc/64 scope link 
       valid_lft forever preferred_lft forever
  • 开启kvm:systemctl start libvirtd
  • kvm开机自启:systemctl enable libvirtd
  • 查看kvm状态:systemctl status libvirtd
● libvirtd.service - Virtualization daemon
   Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2018-04-13 18:28:31 CST; 6min ago
     Docs: man:libvirtd(8)
           http://libvirt.org
 Main PID: 1223 (libvirtd)
   CGroup: /system.slice/libvirtd.service
           ├─1223 /usr/sbin/libvirtd
           ├─1722 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
           └─1723 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
    -
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页