RHEL7聚合网络

RHEL7聚合网络

实际生产环境中,大公司的网络要求是比较严格的,特别是针对有特别服务的服务器,是要求不能出现问题的。要保证365x24的运行,以便提供更好的服务。还有,针对流量访问大的服务,还要求提供负载均衡,保证服务器不会出现访问拥堵的情况。本实验,我们简单介绍下Linux环境中的的聚合网络,通过多块网卡的绑定实现负载和容错的功能。

1.课程目标

  • 了解什么是聚合网络;
  • 了解聚合网络的作用、益处;
  • 掌握聚合网络的配置;
  • 能够单独熟练运用聚合网络。

2.添加网卡

首先,关闭虚拟机,添加两块网卡。此过程不在赘述,相信大家都OK的!添加后如下:

在虚拟机环境中,①&②两块网卡要在同一个桥接模式。添加好后,点击【开启此虚拟机】开机。

3.nmcli的使用

根据以往的经验,在虚拟机中,关机之后添加的网卡,再次开机是不会自动生成配置文件的,但是ifconfig可以查看的到。

Ifconfig查看网卡信息


[[email protected] ~]# ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

inet 192.168.10.10  netmask 255.255.255.0  broadcast 192.168.10.255

inet6 fe80::20c:29ff:fe70:f064  prefixlen 64  scopeid 0x20<link>

ether 00:0c:29:70:f0:64  txqueuelen 1000  (Ethernet)

RX packets 122  bytes 16482 (16.0 KiB)

RX errors 0  dropped 0  overruns 0  frame 0

TX packets 71  bytes 12785 (12.4 KiB)

TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

ether 00:0c:29:70:f0:6e  txqueuelen 1000  (Ethernet)

RX packets 17  bytes 4171 (4.0 KiB)

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

eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

ether 00:0c:29:70:f0:78  txqueuelen 1000  (Ethernet)

RX packets 17  bytes 4171 (4.0 KiB)

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

注:

  • 在RHEL7系统中,网卡的默认显示名是BIOS读取设备信息之后取的,如:第一块网卡名为eno16777736。此处显示eth0、eth1、eth2是因为之前人工修改了第一块网卡名为eth0,所以之后添加的网卡默认为eth1、eth2……

查看网卡配置文件文件


[[email protected] ~]# ls /etc/sysconfig/network-scripts/

ifcfg-eno16777736.bak  ifdown-post      ifup-eth     ifup-Team

ifcfg-eth0             ifdown-ppp       ifup-ippp    ifup-TeamPort

ifcfg-lo               ifdown-routes    ifup-ipv6    ifup-tunnel

ifcfg-Profile_1        ifdown-sit       ifup-isdn    ifup-wireless

ifdown                 ifdown-Team      ifup-plip    init.ipv6-global

ifdown-bnep            ifdown-TeamPort  ifup-plusb   network-functions

ifdown-eth             ifdown-tunnel    ifup-post    network-functions-ipv6

ifdown-ippp            ifup             ifup-ppp

ifdown-ipv6            ifup-aliases     ifup-routes

ifdown-isdn            ifup-bnep        ifup-sit

如上:只有ifcfg-eth0的配置文件,没有另外两块网卡的配置文件。而此时的eth1、eth2处于未活动状态,还没有active。

按照之前在RHEL6及之前系统中的实验做法,是把eth0的文件复制之后修改其配置信息为eth1的,然后重启网络服务,让eth1处于active状态。但是这种做法是没办法修改网卡的UUID的(UUID为系统自动分配的设备唯一标示符。针对此,下面我们将介绍一种更好的生成新增网卡配置文件的方式,就是使用nmcli命令。

nmcli是在RHEL7中一个管理NetworkManager很方便工具,会自动把配置文件写到/etc/sysconfig/network-scripts下,下面就看其具体使用。

在生成网卡配置文件之前,我们先查看下当前网卡标示信息,查看那些网卡为active状态


[[email protected] ~]# nmcli connection show

NAME       UUID                                  TYPE            DEVICE

Profile 1  3dc840bd-b13f-4e51-b1ac-6fe0a9dcc498  802-3-ethernet  eth0

如上:现在只有缺省的eth0。还没有另外两块网卡信息。

使用nmcli添加eth1、eth2的配置文件信息并激活两块网卡


[[email protected] ~]# nmcli connection add con-name eth1 type ethernet ifname eth1

//add添加名为eth1的网卡,类型为以太网,物理设备名字为eth1(如果没改en16777736为eth0的话默认就是原设备名)

Connection ‘eth1‘ (042d6385-8670-4dcd-91c4-989e4924df66) successfully added.

[[email protected] ~]# nmcli connection add con-name eth2 type ethernet ifname eth2

Connection ‘eth2‘ (36e513bf-07b1-4ee7-b8be-b04aa3cd383e) successfully added.

------------------------------------------------添加成功之后查看------------------------------------------------

[[email protected] ~]# nmcli connection show

NAME       UUID                                  TYPE            DEVICE

eth2       36e513bf-07b1-4ee7-b8be-b04aa3cd383e  802-3-ethernet  eth2

eth1       042d6385-8670-4dcd-91c4-989e4924df66  802-3-ethernet  eth1

Profile 1  3dc840bd-b13f-4e51-b1ac-6fe0a9dcc498  802-3-ethernet  eth0

查看是否生成配置文件


[[email protected] ~]# ls /etc/sysconfig/network-scripts/

ifcfg-eno16777736.bak  ifdown-ipv6      ifup-aliases  ifup-routes

ifcfg-eth0             ifdown-isdn      ifup-bnep     ifup-sit

ifcfg-eth1             ifdown-post      ifup-eth      ifup-Team

ifcfg-eth2             ifdown-ppp       ifup-ippp     ifup-TeamPort

如上,使用nmcli之后,自动生成了网卡配置文件,并active了网卡。

以eth1为例,使用nmcli为eth1设置IP地址


[[email protected] network-scripts]# nmcli connection modify eth1 ipv4.addresses "172.16.30.100/24" ipv4.method manual

[[email protected] network-scripts]# nmcli connection up eth1

//启用此网卡

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)

[[email protected] network-scripts]# ifconfig eth1

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

inet 172.16.30.100  netmask 255.255.255.0  broadcast 172.16.30.255

inet6 fe80::20c:29ff:fe70:f06e  prefixlen 64  scopeid 0x20<link>

ether 00:0c:29:70:f0:6e  txqueuelen 1000  (Ethernet)

RX packets 132  bytes 21376 (20.8 KiB)

RX errors 0  dropped 0  overruns 0  frame 0

TX packets 117  bytes 13546 (13.2 KiB)

TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

除了使用上面的一条命令直接设置外,还可以分步骤设置,如下:


[[email protected] ~]# nmcli con edit "eth1"

//打开编辑模式

===| nmcli interactive connection editor |===

Editing existing ‘802-3-ethernet‘ connection: ‘eth1‘

Type ‘help‘ or ‘?‘ for available commands.

Type ‘describe [<setting>.<prop>]‘ for detailed property description.

You may edit the following settings: connection, 802-3-ethernet (ethernet), 802-1x, ipv4, ipv6, dcb

nmcli> set ipv4.addresses  172.16.30.100/24 172.16.30.1

//设置IP地址

nmcli> save

//保存设置

Connection ‘eth1‘ (042d6385-8670-4dcd-91c4-989e4924df66) successfully updated.

nmcli> activate eth1

//激活网卡

Monitoring connection activation (press any key to continue)

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)

nmcli> quit

//退出编辑模式

4.聚合网络设置

聚合网络的原理

真实的ip地址并不是在物理网卡上设置的,而是把两个或多个物理网卡聚合成一个虚拟的网卡,在虚拟网卡上设置地址,而外部网络访问本机时,就是访问的这个虚拟网卡的地址,虚拟网卡接到数据后经过两个网卡的负载交给服务器处理。如果一块网卡出现问题,则通过另一块传递数据,保证正常通信。此原理与CISCO的HSRP协议相似,懂网络的同学理解更容易。

本部分实验我们将详细介绍网卡的绑定,实现聚合网络以达到负载和容错的能力。

聚合网络实验过程中,添加的两块新网卡可以不是active状态,甚至nmcli connect show查看没有新添加的网卡信息。也可以使active状态的网卡。前者聚合后的网络,eth1&eth2的MAC地址是一样的,而后者聚合后的网络,eth1&eth2的MAC地址是不一样的。本实验接着上部分实验继续。

添加虚拟网卡配置文件并设置策略自动激活(active)此虚拟网卡、自动容错切换


[[email protected] ~]# nmcli connection add con-name team0 type team ifname team0 config ‘{"run":{"name":"activeback"}}‘

//team类型、卡名team0为规定。无物理设备,名字可以填写虚拟的team0。Config后为策略,让网卡之间出问题时自动切换。

Connection ‘team0‘ (8d0a1f5a-348f-4537-8adf-aaf87d106277) successfully added.

[[email protected] ~]# nmcli connection show

NAME       UUID                                  TYPE            DEVICE

Profile 1  3dc840bd-b13f-4e51-b1ac-6fe0a9dcc498  802-3-ethernet  eth0

eth2       36e513bf-07b1-4ee7-b8be-b04aa3cd383e  802-3-ethernet  eth2

team0      8d0a1f5a-348f-4537-8adf-aaf87d106277  team            team0

添加虚拟网卡之后,为其设置IP


[[email protected] ~]# nmcli connection modify  team0 ipv4.addresses "172.16.30.100/24" ipv4.method manual connection.autoconnect yes

//设置自动连接

把两块网卡添加到team0中,即把两块网卡聚合在一起


[[email protected] ~]# nmcli connection add con-name slave1 ifname eth1 type team-slave master team0

Connection ‘slave1‘ (8abcd1af-21b3-4571-a72b-b5835228e570) successfully added.

[[email protected] ~]# nmcli connection add con-name slave2 ifname eth2 type team-slave master team0

Connection ‘slave2‘ (824a0b75-bfe9-40a7-bd72-4c41a05cd763) successfully added.

查看聚合后的信息


[[email protected] ~]# nmcli connection show

NAME       UUID                                  TYPE            DEVICE

Profile 1    3dc840bd-b13f-4e51-b1ac-6fe0a9dcc498  802-3-ethernet        eth0

eth2       36e513bf-07b1-4ee7-b8be-b04aa3cd383e  802-3-ethernet       eth2

slave2      824a0b75-bfe9-40a7-bd72-4c41a05cd763  802-3-ethernet       --

slave1      8abcd1af-21b3-4571-a72b-b5835228e570  802-3-ethernet       eth1

team0      8d0a1f5a-348f-4537-8adf-aaf87d106277  team                team0

启用网卡


[[email protected] ~]# nmcli connection up team0

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)

Ifconfig查看网卡信息


[[email protected] ~]# ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

inet 192.168.10.10  netmask 255.255.255.0  broadcast 192.168.10.255

inet6 fe80::20c:29ff:fe70:f064  prefixlen 64  scopeid 0x20<link>

ether 00:0c:29:70:f0:64  txqueuelen 1000  (Ethernet)

RX packets 1573  bytes 145080 (141.6 KiB)

RX errors 0  dropped 0  overruns 0  frame 0

TX packets 1202  bytes 138099 (134.8 KiB)

TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

ether 00:0c:29:70:f0:6e  txqueuelen 1000  (Ethernet)

RX packets 34  bytes 5999 (5.8 KiB)

RX errors 0  dropped 0  overruns 0  frame 0

TX packets 117  bytes 16308 (15.9 KiB)

TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

ether 00:0c:29:70:f0:78  txqueuelen 1000  (Ethernet)

RX packets 181  bytes 26498 (25.8 KiB)

RX errors 0  dropped 0  overruns 0  frame 0

TX packets 137  bytes 13867 (13.5 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 0  (Local Loopback)

RX packets 6  bytes 560 (560.0 B)

RX errors 0  dropped 0  overruns 0  frame 0

TX packets 6  bytes 560 (560.0 B)

TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

team0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

inet 172.16.30.100  netmask 255.255.255.0  broadcast 172.16.30.255

inet6 fe80::20c:29ff:fe70:f06e  prefixlen 64  scopeid 0x20<link>

ether 00:0c:29:70:f0:6e  txqueuelen 0  (Ethernet)

RX packets 2  bytes 283 (283.0 B)

RX errors 0  dropped 0  overruns 0  frame 0

TX packets 54  bytes 7770 (7.5 KiB)

TX errors 0  dropped 1 overruns 0  carrier 0  collisions 0

如上,启动之后,只有team0有地址,其余两个网卡为team0的负载网卡。

验证(请自行验证):

使用同网段的主机ping  team0地址:172.16.30.100,然后断开其中一块网卡的连接,可以看到ping仍然在继续,并没有断开。如果断开全部聚合的网卡,则ping中断。这也就体现了聚合网络的负载和容错能力。

时间: 2024-08-02 18:00:18

RHEL7聚合网络的相关文章

Rhel7聚合链路

Rhel7聚合链路 方案一: 有时state看不了,把ethnet加上,重启网络再删除. 重启网络 teamdctl team0 state setup: runner: activebackup ports: eth3 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up eth4 link watches: link summary: up instance[link_watch_0]: n

RHCE 学习笔记(30)- 聚合网络

这一节主要学习了如何配置 聚合网络 (NIC Teaming)和 桥接网络(Bridge) NIC Teaming 和 桥接网络的配置和IPv4,IPv6并没有太大的区别,仍然是可以通过类似的GUI,命令行和配置文件修改. NIC teaming,简单的说就是多个物理端口绑定在一起当成一个逻辑端口使用,以便提高带宽,实现负载平衡或高可用的功能.RHEL7里面是通过runner (可以视作一段代码)来实现不同的目的. 下面看看如何配置NIC Teaming Redhat官方文档给了5种配置的方法,

rhel7配置网络yum源,配置VNC远程桌面

rhel7配置VNC远程桌面实验环境:安装了图形化界面的redhat7.0,IP是192.168.31.201先配置网络yum源[[email protected] ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo [[email protected] ~]# sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Ba

rhel7 启动网络

我装的是rhel7 服务器版本(在virtualbox虚拟机里),安装后默认不启动网络,另外还有很多命令也不能用,比如ifconfig, yum-config-manager等. 先解决网络问题: 切换root用户 在/etc/sysconfig/network-scripts目录下有一个和你网卡有关的文件,我的是  ifcfg-enp0s3 编辑文件: ,并修改为ONBOOT=on.然后即可链接网络 因为ifconfig在net-tools包里,yum-config-manager在yum-u

【RHEL7/CentOS7网络配置】 -- 2019-08-08 18:02:54

目录 网卡配置文件 查网卡信息 测试网络是否正常 使用 nmtui 命令配置网络 使用 nm-connection-editor 工具配置网络 修改回6.x版本的网卡名 原文: http://106.13.73.98/__/84/ Rhel/CentOS网络配置文件路径:/etc/sysconfig/network-scripts/ifcfg-xxxx @ 7.0版本后,网卡命名方式从eth0.eth1.eth2的方式变成了enoxxxxxxxx. 其中,en代表的是entherent(以太网)

【RHEL7/CentOS7网络配置】 -- 2019-08-11 19:48:45

目录 网卡配置文件 查网卡信息 测试网络是否正常 使用 nmtui 命令配置网络 使用 nm-connection-editor 工具配置网络 修改回6.x版本的网卡名 原文: http://106.13.73.98/__/84/ Rhel/CentOS网络配置文件路径:/etc/sysconfig/network-scripts/ifcfg-xxxx @ 7.0版本后,网卡命名方式从eth0.eth1.eth2的方式变成了enoxxxxxxxx. 其中,en代表的是entherent(以太网)

【RHEL7/CentOS7网络配置】 &#204127;

目录 网卡配置文件 查网卡信息 测试网络是否正常 使用 nmtui 命令配置网络 使用 nm-connection-editor 工具配置网络 修改回6.x版本的网卡名 原文: http://blog.gqylpy.com/gqy/309 "Rhel/CentOS网络配置文件路径:/etc/sysconfig/network-scripts/ifcfg-xxxx @ 7.0版本后,网卡命名方式从eth0.eth1.eth2的方式变成了enoxxxxxxxx. 其中,en代表的是entherent

RHEL7新特性及RHEL6功能对比

一.RHEL7新特性对比之安装 2012,发布rhel7(主要是64位系统) 1.RHEL7目前支持架构: ①64-bit AMD    ②64-bit Intel    ③IBM POWER    ④IBM System z    ⑤不再支持x86 32bit 2.RHEL7安装界面-->grub2,systemd ①全新的安装界面    ②一站式的安装配置    ③全新的kickstart结构    ④全新的分区工具 ⑤支持2TB以上硬盘作为系统引导盘    ⑥安装配置步骤较大变化 3.RH

linux网络基础配置与网络进阶管理

一. 网络基本配置: 真不敢想象没有网络的一天 应该怎样度过,但是有了网络就行了?原来刚有了网络时由于没有统一的标准,各大硬件厂商各自为政,都在搞网络,但是都只是同一厂商的设备可以进行通讯,就 和不同的国家的人交流使用了不同的语言一样,难以将所有的网络连接起来,之后Internet有了统一的标准,大家都遵循它的标准,后来计算机才能进行网 络通讯,同样将linux主机接入网络也必须进行配置它的网络,及其相关的主机名等,下面将逐一进行配置: 1.  主机名: rhel6中主机名修改 [[email