KVM--使用桥接网络br0搭建虚拟机

使用iso光驱新建虚拟机

[root@vm1 images]# grep -E "vmx|svm" /proc/cpuinfo | wc -l   ##bios是否开启支持虚拟化
3
[root@vm1 images]# yum install qemu-kvm qemu-kvm-tools libvirt libvirt-client virt-manager virt-install acpid -y
[root@localhost ~]# systemctl start libvirtd
[root@localhost ~]# systemctl enable libvirtd
[root@localhost ~]# ifconfig virbr0                           # ifconfig virbr0 #验证是否生成NAT网卡virbr0,类似docker0
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:1d:c4:df  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
 
       
 ####搭建br0,使用桥接,不使用默认的nat########
[root@vm1 images]# cat  /etc/sysconfig/network-scripts/ifcfg-br0 
TYPE=Bridge
BOOTPROTO=static
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=192.168.1.223
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=202.101.172.35
[root@vm1 images]# cat  /etc/sysconfig/network-scripts/ifcfg-ens33 
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
ONBOOT=yes
BRIDGE=br0
[root@localhost ~]# service network restart
[root@vm1 images]# ifconfig br0              # ifconfig br0 桥接接口
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.223  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20a6:9dff:fe21:ddb3  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:22:f0:e8  txqueuelen 1000  (Ethernet)
        RX packets 97093  bytes 9647019 (9.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 46641  bytes 150190883 (143.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 
       
[root@vm1 images]# qemu-img create -f qcow2 /main/server/new_partions/images/centos.qcow2 8G
Formatting '/main/server/new_partions/images/centos.qcow2', fmt=qcow2 size=8589934592 encryption=off cluster_size=65536 lazy_refcounts=off
[root@vm1 images]# du -sh centos.qcow2    #qcow2格式的磁盘,并没有直接占用8G大小的空间
196K	centos.qcow2




[root@vm1 images]# virt-install --virt-type kvm --name centos7 --ram 1024 --vcpus 2 --cdrom=/main/server/new_partions/iso/CentOS-7-x86_64-Minimal-1908.iso --disk path=/main/server/new_partions/images/centos.qcow2 --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole
Starting install...
Domain installation still in progress. You can reconnect to 
the console to complete the installation process.
[root@vm1 ~]# netstat -tunpl | grep qemu
tcp        0      0 0.0.0.0:5900            0.0.0.0:*               LISTEN      72294/qemu-kvm
[root@vm1 images]# virt-manager

使用已有的qcow2硬盘新建虚拟机

## --boot hd 表示从硬盘引导,不是从iso
[root@localhost images]# virt-install --virt-type kvm --name centos7 --ram 1024 --vcpus 2  --disk path=/main/server/new_partions/images/centos.qcow2 --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole --boot hd

[root@localhost images]# netstat -tunpl | grep qemu
tcp        0      0 0.0.0.0:5900            0.0.0.0:*               LISTEN      3559/qemu-kvm

##使用vnc可以连接5900端口
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值