#Centos7.4#Linux虚拟机KVM配置网卡【Requested operation is not valid: network 'br0' is not active】

案例:

【20181218 10:25 事故描述】

jump宿主机服务器172.16.20.16死机,联系机房管理员重启,拨通机房vpn后ssh连接不上

【20181219 11:25 现场问题排查】

网卡显示ip是172.16.20.161,没有kvm桥接网卡br0,

启动kvm虚拟机报错:Requested operation is not valid: network 'br0' is not active

#ifconfig
enp1s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.20.161 netmask 255.255.255.0 broadcast 172.16.20.255
inet6 fe80::226:6cff:fef5:a514 prefixlen 64 scopeid 0x20<link>
ether 00:26:6c:f5:a5:14 txqueuelen 0 (Ethernet)
RX packets 31936 bytes 1780910 (1.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2511 bytes 364044 (355.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

【解决问题】

1、##kvm网桥网卡br0配置##
brctl addbr br0 #创建网桥
brctl addif br0 eth0 #把br0和eth0网卡绑定
brctl stp br0 on #有关stp协议的

2、在/etc/sysconfig/network-scripts/目录cp  ifcfg-enp1s0f0 ifcfg-br0

3、修改配置网卡信息 ifcfg-enp1s0f0 和ifcfg-br0信息

【ifcfg-enp1s0f0】

TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
NM_CONTROLLED=no
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp1s0f0
UUID=b4a34022-21d9-4f88-80c3-f4a625c16d5d
DEVICE=enp1s0f0
ONBOOT=yes
BRIDGE=br0

【ifcfg-br0】

TYPE=Bridge
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
NM_CONTROLLED=no
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=172.16.20.16
NETMASK=255.255.255.0
GATEWAY=172.16.20.1
DNS1=114.114.114.114

4、

5、

6、#virsh start jumpserver 启动kvm虚拟机jumpserver

 

【修改后的宿主机配置】

#ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.20.16 netmask 255.255.255.0 broadcast 172.16.20.255
inet6 fe80::226:6cff:fef5:a514 prefixlen 64 scopeid 0x20<link>
ether 00:26:6c:f5:a5:14 txqueuelen 0 (Ethernet)
RX packets 31936 bytes 1780910 (1.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2511 bytes 364044 (355.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

enp1s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::226:6cff:fef5:a514 prefixlen 64 scopeid 0x20<link>
ether 00:26:6c:f5:a5:14 txqueuelen 1000 (Ethernet)
RX packets 9445502 bytes 584441758 (557.3 MiB)
RX errors 0 dropped 94 overruns 0 frame 0
TX packets 137325 bytes 32258671 (30.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xfafe0000-faffffff

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 0 (Local Loopback)
RX packets 7217 bytes 410182 (400.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7217 bytes 410182 (400.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


操作票
1、virsh net-list --all

##kvm网桥网卡配置##
brctl addbr br0 #创建网桥
brctl addif br0 eth0 #把br0和eth0网卡绑定
brctl stp br0 on #有关stp协议的

 

cp ifcfg-eth0 ifcfg-br0
【修改前ifcfg-eth0】
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
NM_CONTROLLED=no
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eth0
UUID=b4a34022-21d9-4f88-80c3-f4a625c16d5d
DEVICE=eth0
ONBOOT=yes
IPADDR=172.16.20.16
NETMASK=255.255.255.0
GATEWAY=172.16.20.1
DNS1=114.114.114.114

修改ifcfg-eth0文件
BOOTRPOTO=none
追加 BRIDGE=br0
###
【修改后ifcfg-br0和ifcfg-eth0】
[root@BD-PRD-Docker network-scripts]# cat ifcfg-br0
TYPE=Bridge
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
NM_CONTROLLED=no
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=172.16.20.16
NETMASK=255.255.255.0
GATEWAY=172.16.20.1
DNS1=114.114.114.114

[root@BD-PRD-Docker network-scripts]# cat ifcfg-enp1s0f0
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
NM_CONTROLLED=no
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp1s0f0
UUID=b4a34022-21d9-4f88-80c3-f4a625c16d5d
DEVICE=enp1s0f0
ONBOOT=yes
#IPADDR=172.16.20.16
#NETMASK=255.255.255.0
#GATEWAY=172.16.20.1
#DNS1=114.114.114.114
BRIDGE=br0

service network restart

 

【可能用到的命令】
brctl addbr br0 #创建网桥

brctl addif br0 eth0 #把br0和eth0网卡绑定

brctl stp br0 on #有关stp协议的

brctl delif br0 eth0 #解除绑定

ifconfig br0 down #关闭br0,不关闭删不掉

brctl delbr br0 #删除br0

关闭NetworkManager
#service NetworkManager stop
#chkconfig NetworkManager off
#kvm命令
#virsh 进入kvm控制台
##list --all显示所有kvm虚拟机
##console id或者name 进入kvm机子
virsh net-list --all显示所有网络接口,default接口是默认的nat转发
virsh net-destroy default 关闭default网络接口
virsh net-undefine default 删除default网络接口
service libvirtd restart 重启kvm服务

virsh shutdown jumpserver 关闭kvm虚拟机
virsh start jumpserver 启动kvm虚拟机


【修改kvm虚拟机的资源大小cpu、内存、硬盘】

# virsh list --all 

Id    Name         State
-------------------------------------------------
-     bbotte       shut off 
    
# virsh setvcpus bbotte --maximum 4 --config
# virsh setmaxmem bbotte 1048576 --config

# virsh dominfo bbotte
Id:             2
Name:           bbotte
UUID:           bd22f444-ee7f-7f00-3d1b-1bb0d0857e43
OS Type:        hvm
State:          running
CPU(s):         4
CPU time:       152.3s
Max memory:     1048576 KiB
Used memory:    524288 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: none
Security DOI:   0
   ####修改xml配置文件###

1、virsh edit centos73 (更改前要将virsh shutdown centos73 )
找到“memory”和“vcpu”标签,将
<name>centos73</name>
  <uuid>2220a6d1-a36a-4fbb-8523-e078b3dfe795</uuid>
  <memory unit='KiB'>2097152</memory>
  <currentMemory unit='KiB'>2097152</currentMemory>
  <vcpu placement='static'>1</vcpu>
改为:
<name>centos73</name>
  <uuid>2220a6d1-a36a-4fbb-8523-e078b3dfe795</uuid>
  <memory unit='KiB'>3145728</memory>
  <currentMemory unit='KiB'>3145728</currentMemory>
  <vcpu placement='static'>2</vcpu>
 
 virsh define /etc/libvirt/qemu/centos73.xml    重定义使配置生效    
重启虚拟机
virsh start centos73 --console
查看原配置信息

 
[root@localhost kvm]# virsh dominfo centos734
Id:             -
Name:           centos73
UUID:           2220a6d1-a36a-4fbb-8523-e078b3dfe795
OS Type:        hvm
State:          shut off
CPU(s):         1
Max memory:     2097152 KiB
Used memory:    2097152 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: none
Security DOI:   0
调整后信息:
[root@localhost kvm]# virsh dominfo centos73
Id:             -
Name:           centos73
UUID:           2220a6d1-a36a-4fbb-8523-e078b3dfe795
OS Type:        hvm
State:          shut off
CPU(s):         2
Max memory:     3145728 KiB
Used memory:    3145728 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: none
Security DOI:   0

参考连接:

http://blog.sina.com.cn/s/blog_625fcb0b0102wayc.html
http://blog.51cto.com/13570993/2061254

https://blog.csdn.net/hnhuangyiyang/article/details/50902223

 
posted @ 2018-12-20 12:03  勇敢の牛肉丸  阅读(1106)  评论(0编辑  收藏  举报