[步骤] KVM 虚拟网络的创建

注意:

在创建 KVM 虚拟机网络之前要先安装 KVM

正文:

步骤一:制作 1 个 KVM 虚拟网络的配置文件

# vim /etc/libvirt/qemu/networks/vlan001.xml

创建以下内容:

<network>
  <name>vlan001</name>
  <bridge name="vlan001"/>
  <forward mode="nat"/>
  <ip address="192.168.1.254" netmask="255.255.255.0">
    <dhcp>
      <range start="192.168.1.100" end="192.168.1.200"/>
    </dhcp>
  </ip>
</network>


补充:这里以创建
1) 名为 vlan001
2) dhcp 是 192.168.1.100 到 192.168.1.100
3) 子网掩码是 255.255.255.0
4) 本机 IP 地址是 192.168.1.254
5) 配置文件是 /etc/libvirt/qemu/networks/vlan001.xml 为例

步骤二:将刚刚制作的虚拟网络配置文件定义到 KVM 里

# virsh net-define /etc/libvirt/qemu/networks/vlan001.xml

(补充:这里的虚拟网络配置文件是 /etc/libvirt/qemu/networks/vlan001.xml)

步骤三:启动刚刚定制的虚拟网络

# virsh net-start vlan001

(补充:这里的虚拟网络名是 vlan001)

步骤四:确认刚刚定制的虚拟网络

# ifconfig

步骤五:将刚刚定制的虚拟网络设置为开机自动启动

# virsh net-autostart vlan001

(补充:这里的虚拟网络名是 vlan001)

[模板] KVM 虚拟机的 XML 模板

注意:

此模板只用于参考

# vi /etc/libvirt/qemu/template_centos_7_10g.xml

创建以下内容:

<domain type='kvm'>
  <name>node</name>
  <memory unit='KB'>1524000</memory>
  <currentMemory unit='KB'>1524000</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='template_centos_7_10g'>hvm</type>
    <boot dev='hd'/>
    <bootmenu enable='yes'/>
    <bios useserial='yes'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode='host-passthrough'>
  </cpu>
  <clock offset='localtime'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/bin/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/template_centos_7_10g.img'/>
      <target dev='vda' bus='virtio'/>
    </disk>
    <interface type='bridge'>
      <source bridge='vlan001'/>
      <model type='virtio'/>
    </interface>
    <channel type='unix'>
      <target type='virtio' name='org.qemu.guest_agent.0'/>
    </channel>
    <serial type='pty'></serial>
    <console type='pty'>
      <target type='serial'/>
    </console>
    <memballoon model='virtio'></memballoon>
  </devices>
</domain>

(补充:这里以给 template_centos_7_10g 创建一个虚拟机模板为例)