管理聚合链路和桥接网络
通过网口绑定技术Bonding,实现网络冗余, 负载均衡, 从而提升网络传输能力,避免网络链路单点故障, 达到高可用高可靠的目的。
Bonding的两种绑定工作模式:实际上有7种,其他不常用
模式0 balance-rr负载轮询(2网卡单独都是100MB,聚合为1个网络传输带宽200MB)
模式1 active-backup高可用(其中一条线若断线,其他线路将会自动备援)
1.1 Linux7配置bond聚合链路
centos7系统配置链路聚合bond
完成bond0, balance-rr
[root@linux-node1 ~]# nmcli device
DEVICE TYPE STATE CONNECTION
ens32 ethernet connected ens32
ens36 ethernet disconnected –
ens37 ethernet disconnected –
创建bond0, 模式为balance-rr
[root@linux-node1 ~]# nmcli connection add type bond
mode balance-rr con-name bond0 ifname bond0
ipv4.method manual
ipv4.addresses 192.168.69.223/24
ipv4.gateway 192.168.69.1
ipv4.dns 8.8.8.8
添加物理网卡连接至bond0
[root@linux-node1 ~]# nmcli connection add type bond-slave
con-name bond-slave36 ifname ens36 master bond0
[root@linux-node1 ~]# nmcli connection add type bond-slave
con-name bond-slave37 ifname ens37 master bond0
查看bond配置信息
[root@linux-node1 ~]# cat /proc/net/bonding/bond0
关闭ens36网卡, 测试bond0是否正常
[root@linux-node1 ~]# nmcli device disconnect ens36
完成bond1, active-backup
[root@linux-node1 ~]# nmcli device
DEVICE TYPE STATE CONNECTION
ens32 ethernet connected ens32
ens36 ethernet disconnected –
ens37 ethernet disconnected –
创建bond1相关设备
[root@linux-node1 ~]# nmcli connection add type bond
con-name bond1 ifname bond1 mode active-backup
ipv4.method manual ipv4.addresses ‘192.168.69.222/24’
ipv4.gateway=’192.168.69.2’ ipv4.dns=’192.168.69.2’
添加连接至bond1
[root@linux-node1 ~]# nmcli connection add type bond-slave
con-name bond-slave36 ifname ens36 master bond1
[root@linux-node1 ~]# nmcli connection add type bond-slave
con-name bond-slave37 ifname ens37 master bond1
启用相关连接
[root@linux-node1 ~]# nmcli connection up bond1
[root@linux-node1 ~]# nmcli connection up bond-slave36
[root@linux-node1 ~]# nmcli connection up bond-slave37
验证
[root@linux-node1 ~]# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: ens36 //目前是ens36网卡提供支撑
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: ens36
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:34:92:06
Slave queue ID: 0
Slave Interface: ens37
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:34:92:10
Slave queue ID: 0
停止ens36物理网卡设备
[root@linux-node1 ~]# nmcli device disconnect ens36
//ens37物理网卡设备会进行自动切换
[root@linux-node1 ~]# grep “Currently Active Slave” /proc/net/bonding/bond1
Currently Active Slave: ens37
1.2 LInux7配置team聚合链路
centos7/rhce7使用teaming实现聚合链路,能够提供网卡绑定之后的网络吞吐性能,并且提供网卡的故障切换处理能力。
Team是基于一个小型内核驱动实现聚合链路,在用户层提供teamd命令实现链路管理。
teamd可以实现以下模式的聚合链路
broadcast 广播容错
roundrobin 负载轮询
activebackup 主备(必考)
loadbalance 负载均衡
lacp 需要交换机支持lacp协议
考试建议使用命令行配置,图形界面配置不稳定
[root@linux-node1 ~]# nmcli connection add type team con-name team0 ifname team0
config ‘{“runner”:{“name”:”activebackup”}}’
ipv4.addresses 192.168.56.111/24
ipv4.gateway 192.168.56.2
ipv4.dns 192.168.56.2 ipv4.method manual
[root@linux-node1 ~]# nmcli connection add type team-slave
con-name team0-port1 ifname eth1 master team0
[root@linux-node1 ~]# nmcli connection add type team-slave
con-name team0-port2 ifname eth2 master team0
//检查team0状态
[root@linux-node1 ~]# ping -I team0 192.168.56.1
[root@linux-node1 ~]# teamdctl team0 state
//断掉后检测
[root@linux-node1 ~]# nmcli dev disconnect eth1
[root@linux-node1 ~]# teamdctl team0 state
动态修改team模式
// 导出配置进行修改 (man teamd.conf)
[root@linux-node1 ~]# teamdctl team0 config dump > /tmp/team.conf
[root@linux-node1 ~]# vim /tmp/team.conf
//以最新修改的配置选项修改team0属性
[root@linux-node1 ~]# nmcli con mod team0 team.config /tmp/team.conf
//修改之后需要重启team0
[root@linux-node1 ~]# nmcli connection down team0;nmcli connection up team0
[root@linux-node1 ~]# nmcli connection up team0-port1
[root@linux-node1 ~]# nmcli connection up team0-port2
1.3 Linux7配置brige桥接网络
建立桥接接口
创建桥接网络br1
[root@linux-node1 ~]# nmcli connection add type bridge
con-name br1 ifname br1
ipv4.addresses 192.168.56.222/24 ipv4.method manual
桥接至eth1
[root@linux-node1 ~]# nmcli connection add type bridge-slave
con-name br1-port1 ifname eth1 master br1
[root@linux-node1 ~]# ping -I br1 192.168.56.1
[root@linux-node1 ~]# brctl show
1.4 Linux6配置bond链路聚合
适用于RedHat6以及CentOS6
1.创建绑定网卡配置文件
[root@liyanzhao ~]# cat ifcfg-bond0
DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
USERCTL=no
BOOTPROTO=static
IPADDR=192.168.56.200
NETMASK=255.255.255.0
GATEWAY=192.168.56.2
DNS1=192.168.56.2
BONDING_OPTS=”mode=0 miimon=50” #如果使用模式1将mode修改为1即可
2.修改eth0和eth1网卡配置文件
[root@liyanzhao ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
USERCTL=no
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
[root@liyanzhao ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
USERCTL=no
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
3.添加驱动支持bond0
[root@liyanzhao ~]# vim /etc/modprobe.d/bonding.conf
alias bond0 bonding
centos 8 双网卡绑定
- NAT网络配置(所有服务器):
bond0配置:# yum install bash-completion # cd /etc/sysconfig/network-scripts/
# vim ifcfg-bond0 BOOTPROTO=static NAME=bond0 DEVICE=bond0 ONBOOT=yes BONDING_MASTER=yes BONDING_OPTS="mode=1 miimon=100" #指定绑定类型为1及链路状态监测间隔时间 IPADDR=192.168.10.21 NETMASK=255.255.255.0 GATEWAY=192.168.10.2 DNS1=202.106.0.20
eth0配置:
# cat ifcfg-eth0
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
MASTER=bond0
USERCTL=no
SLAVE=yes
ech1配置
# vim ifcfg-eth1
BOOTPROTO=static
NAME=eth1
DEVICE=eth1
ONBOOT=yes
MASTER=bond0
USERCTL=no
SLAVE=yes
2.仅主机网络配置
# cd /etc/sysconfig/network-scripts/
Bond1配置:
# vim ifcfg-bond1
BOOTPROTO=static
NAME=bond1
DEVICE=bond1
ONBOOT=yes
BONDING_MASTER=yes
BONDING_OPTS="mode=1 miimon=100" #指定绑定类型为1及链路状态监测间隔时间
IPADDR=192.168.20.21
NETMASK=255.255.255.0
eth2配置:
# vim ifcfg-eth2
BOOTPROTO=static
NAME=eth2
DEVICE=eth2
ONBOOT=yes
MASTER=bond1
USERCTL=no
SLAVE=yes
eth3配置:
# vim ifcfg-eth3
BOOTPROTO=static
NAME=eth3
DEVICE=eth3
ONBOOT=yes
MASTER=bond1
USERCTL=no
SLAVE=yes
3.查看网卡状态:
# nmcli c reload
# nmcli c up ethX
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc fq_codel master bond0 state UP group default qlen 1000
link/ether 00:0c:29:9d:a6:a6 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc fq_codel master bond0 state UP group default qlen 1000
link/ether 00:0c:29:9d:a6:a6 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc fq_codel master bond1 state UP group default qlen 1000
link/ether 00:0c:29:9d:a6:ba brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc fq_codel master bond1 state UP group default qlen 1000
link/ether 00:0c:29:9d:a6:ba brd ff:ff:ff:ff:ff:ff
6: bond1: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:0c:29:9d:a6:ba brd ff:ff:ff:ff:ff:ff
inet 192.168.20.50/24 brd 192.168.20.255 scope global noprefixroute bond1
valid_lft forever preferred_lft forever
7: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:0c:29:9d:a6:a6 brd ff:ff:ff:ff:ff:ff
inet 192.168.10.50/24 brd 192.168.10.255 scope global noprefixroute bond0
valid_lft forever preferred_lft forever
4.内外网通信:
# ping www.baidu.com
# ping 192.168.20.2
6.更新yum云:
# yum install wget –y
# rm -rf /etc/yum.repos.d/
# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# yum install –y centos-release-openstack-ocata.noarch
# yum install -y https://rdoproject.org/repos/rdo-release.rpm
# yum clean all
# yum makecache
主:更新阿里云openstack-ocata源,需更改rdo.repo, openstack-ocata.repo中的源为:
http://mirrors.aliyun.com/centos/7/cloud/x86_64/openstack-ocata/
http://mirrors.aliyun.com/centos/7/cloud/x86_64/openstack-queens/
7.查看yum源版本:
yum list centos-release-openstack*
8.安装常用命令
# yum install -y net-tools vim lrzsz tree screen lsof ntpdate telnet wget