KVM創建多網卡橋接網絡虛擬機


環境:centos7 關閉防火牆 selinux=disabled

設置:

(1)CPU開啟虛擬化

(2)驗證開啟虛擬化 [root@kvm-server1 ~]# grep -E "vmx|svm" /proc/cpuinfo | wc -l

2

(3)安裝KVM工具包

#yum install qemu-kvm qemu-kvm-tools libvirt libvirt- client virt-manager virt-install

# systemctl start libvirtd

# systemctl enable libvirtd

(4)創建橋接網卡 

[root@kvm-server1 network-scripts]# cat ifcfg-eth0
TYPE="Ethernet"
BOOTPROTO="static"
NAME="eth0"
DEVICE="eth0"
ONBOOT="yes"
BRIDGE=br0
[root@kvm-server1 network-scripts]# cat ifcfg-br0
TYPE=Bridge
BOOTPROTO=static
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=10.0.0.128
NETMASK=255.255.0.0
GATEWAY=10.0.0.2
DNS1=10.0.0.2

(5)上傳鏡像文件並創建虛擬機

[root@kvm-server1 network-scripts]# ll /data/ISOs/      #需要創建目錄並上傳鏡像文件
total 4669440
-rw-r--r-- 1 qemu qemu 4781506560 Jun 7 21:16 CentOS-7-x86_64-DVD-2003.iso

#創建系統磁盤

[root@kvm-server1 network-scripts]#qemu-img create -f qcow2  /var/lib/libvirt/images/centos7-bridge.qcow2 10G

Formatting '/var/lib/libvirt/images/centos7-bridge.qcow2',fmt=qcow2 size=10737418240 cluster_size=65536 lazy_refcounts=off refcount_bits=16
#創建基於橋接網絡的虛擬機

[root@kvm-server1 network-scripts]#virt-install \

--virt-type kvm \

--name centos7-bridge \      -n NAME, --name=NAME:虛擬機名稱,需全局惟一; 

--ram 1024 \                       # --ram=MEMORY:虛擬機內在大小,單位為MB;

--vcpus 2 \                         #VCPU個數及相關配置;

--cdrom=/data/ISOs/CentOS-7-x86_64-DVD-2003.iso \                    #鏡像源

--disk path=/var/lib/libvirt/images/centos7-bridge.qcow2 \                     #-disk=DISKOPTS:指定存儲設備及其屬性

--network bridge=br0 \                       # bridge=BRIDGE:連接至名為“BRIDEG”的橋設備;

--graphics vnc,listen=0.0.0.0 \          #圖形配置:定義虛擬機顯示功能相關的配置

--noautoconsole                              #--noautoconsole:禁止自動連接至虛擬機的控制台

[root@kvm-server1 network-scripts]#virt-manager

#一步步安裝虛擬機就可以了,安裝完reboot重啟

#安裝的虛擬機 

[root@localhost network-scripts]# cat ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.130
NETMASK=255.255.255.0
GATEWAY=10.0.0.2
DNS1=114.114.114.114
[root@localhost network-scripts]#

#設置多網卡

宿主機添加網卡,我這里設置為僅主機模式

#設置eth1

[root@kvm-server1 network-scripts]# cp ifcfg-eth0 ifcfg-eth1

[root@kvm-server1 network-scripts]# vim ifcfg-eth1

[root@kvm-server1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
TYPE="Ethernet"
BOOTPROTO="static"
NAME="eth1"
DEVICE="eth1"
ONBOOT="yes"
IPADDR=192.168.10.4
NETMASK=255.255.255.0
BRIDGE=br1
#設置br1

[root@kvm-server1 network-scripts]# cp ifcfg-br0 ifcfg-br1

[root@kvm-server1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-br1
TYPE=Bridge
BOOTPROTO=static
NAME=br1
DEVICE=br1
ONBOOT=yes
IPADDR=192.168.10.4
NETMASK=255.255.255.0

[root@kvm-server1 network-scripts]# systemctl restart network

[root@kvm-server1 network-scripts]# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.128 netmask 255.255.0.0 broadcast 10.0.255.255
inet6 fe80::20c:29ff:fed3:e11c prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d3:e1:1c txqueuelen 1000 (Ethernet)
RX packets 30627 bytes 3437251 (3.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 28475 bytes 7362182 (7.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

br1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.4 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::6088:67ff:fe8f:ca9e prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d3:e1:26 txqueuelen 1000 (Ethernet)
RX packets 2352 bytes 221884 (216.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 11 bytes 782 (782.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:d3:e1:1c txqueuelen 1000 (Ethernet)
RX packets 33704 bytes 4189587 (3.9 MiB)
RX errors 0 dropped 20 overruns 0 frame 0
TX packets 30832 bytes 9059601 (8.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:d3:e1:26 txqueuelen 1000 (Ethernet)
RX packets 2385 bytes 256890 (250.8 KiB)
RX errors 0 dropped 19 overruns 0 frame 0
TX packets 71 bytes 6566 (6.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 54088 bytes 87109072 (83.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 54088 bytes 87109072 (83.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:d2:6d:fa txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fc54:ff:fe25:6246 prefixlen 64 scopeid 0x20<link>
ether fe:54:00:25:62:46 txqueuelen 1000 (Ethernet)
RX packets 587 bytes 79819 (77.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2293 bytes 285786 (279.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

vnet1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fc54:ff:feff:ec00 prefixlen 64 scopeid 0x20<link>
ether fe:54:00:ff:ec:00 txqueuelen 1000 (Ethernet)
RX packets 45 bytes 4114 (4.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2292 bytes 248960 (243.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@kvm-server1 network-scripts]# virt-manager

#這個時候虛擬機就可以添加網卡了,重啟

[root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-eth1

[root@localhost network-scripts]# cat ifcfg-eth1
TYPE=Ethernet
BOOTPROTO=static
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=192.168.10.5
NETMASK=255.255.255.0

[root@localhost network-scripts]# ping www.baidu.com
PING www.a.shifen.com (110.242.68.3) 56(84) bytes of data.
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=1 ttl=128 time=16.1 ms
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=2 ttl=128 time=13.8 ms
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=3 ttl=128 time=29.3 ms


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM