您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
华为HCDA认证教学视频 华为数据通信工程师初级视频.17-VRRP
发布时间:2020-12-05 19:28:41编辑:雪饮阅读()
开头一拓扑
任务目标是对于SW1与SW2和client1能互通,并且当为client1提供一个网关,网关是SW1或者SW2.
对于现实中一个计算机只能有一个网关,如果这个网关挂了,那么另外一个网关即便没有挂,但是计算机端需要重新配置到另外一个网关才可以,那么今天的任务就是实现计算机不用配置就能在一个网关挂掉的时候还能继续用另外一个网关。
实现思路就是SW1与SW2共同维护一个虚拟的ip地址做为计算机的网关。
搭建基础配置
假定我们设定vlan为vlan 10
SW3
对于LSW3配置vlan 10并接入e0/0/1
[SW3]vlan 10
[SW3]interface e0/0/1
[SW3-Ethernet0/0/1]port link-type access
[SW3-Ethernet0/0/1]port defaul vlan 10
对于LSW3的g001接口允许vlan 10的去除标签
[SW3]interface g0/0/1
[SW3-GigabitEthernet0/0/1]port link-type trunk
对于LSW3的g002接口也允许vlan 10去除标签
[SW3]interface g0/0/2
[SW3-GigabitEthernet0/0/2]port link-type trunk
[SW3-GigabitEthernet0/0/2]port trunk allow-pass vlan all
SW1
配置g001为trunk类型并且允许vlan 10去除标签
[SW1]interface g0/0/1
[SW1-GigabitEthernet0/0/1]port link-type trunk
[SW1-GigabitEthernet0/0/1]port trunk allow-pass vlan all
配置vlan10接口的ip地址(地址随意)
[SW1]vlan 10
[SW1-vlan10]quit
[SW1]interface vlan 10
[SW1-Vlanif10]ip address 10.1.1.1 255.255.255.0
SW2
配置g002接口为trunk类型并且允许vlan 10去除标签
[SW2]interface g0/0/2
[SW2-GigabitEthernet0/0/2]port link-type trunk
[SW2-GigabitEthernet0/0/2]port trunk allow-pass vlan all
配置vlan 10的ip地址与SW1保持一个网络
[SW2]vlan 10
[SW2-vlan10]quit
[SW2]interface vlan 10
[SW2-Vlanif10]ip address 10.1.1.2 255.255.255.0
client
client的网关暂时不配置
经过上面一通配置,那么接下来的拓扑图就是这样了
配置VRRP
接下来我们就需要配置VRRP网关了。
SW1
配置vlan 10接口vrrp的id和虚拟ip地址,id自定义,ip地址必须也是同上面配置的同网络即10.1.1.x
[SW1-Vlanif10]vrrp vrid 1 virtual-ip 10.1.1.254
SW2
对于SW2的vlan 10接口就和SW1的vlan 10接口配置一样
[SW2-Vlanif10]vrrp vrid 1 virtual-ip 10.1.1.254
那么接下来拓扑结构就变成这样了,中间多了一个由SW1与SW2共同维护的10.1.1.254这个虚拟接口,这个接口就是为pc提供的网关。
查看主从
用命令”display vrrp”命令就可以查看当前交换机的主从状态。
[SW1]dis vrrp
Vlanif10 | Virtual Router 1
State : Master
Virtual IP : 10.1.1.254
Master IP : 10.1.1.1
PriorityRun : 100
PriorityConfig : 100
MasterPriority : 100
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2020-12-05 18:33:05 UTC-08:00
Last change time : 2020-12-05 18:33:09 UTC-08:00
这里可以看到SW1就是master,有个规则是先配置的则优先master
那么SW2自然就是从咯
[SW2]display vrrp
Vlanif10 | Virtual Router 1
State : Backup
Virtual IP : 10.1.1.254
Master IP : 10.1.1.1
PriorityRun : 100
PriorityConfig : 100
MasterPriority : 100
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2020-12-05 18:35:14 UTC-08:00
Last change time : 2020-12-05 18:35:14 UTC-08:00
同时可以看见SW2的优先级默认是100(PriorityRun字段)
调整优先级(主从切换)
比如这里要调整SW2的优先级的值为120,比原来大了20,优先级是越大越优先
调整的时候需要提供优先级的值和vrid,就是前面和ip地址一起定义的那个id
那么调整SW2的优先级如:
[SW2]interface vlan 10
[SW2-Vlanif10]vrrp vrid 1 priority 120
可以发现现在SW2变成master状态了
[SW2-Vlanif10]dis vrrp
Vlanif10 | Virtual Router 1
State : Master
Virtual IP : 10.1.1.254
Master IP : 10.1.1.2
PriorityRun : 120
PriorityConfig : 120
MasterPriority : 120
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2020-12-05 18:35:14 UTC-08:00
Last change time : 2020-12-05 18:43:58 UTC-08:00
然后SW1就变成backup(从)状态了
[SW1]display vrrp
Vlanif10 | Virtual Router 1
State : Backup
Virtual IP : 10.1.1.254
Master IP : 10.1.1.2
PriorityRun : 100
PriorityConfig : 100
MasterPriority : 120
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2020-12-05 18:33:05 UTC-08:00
Last change time : 2020-12-05 18:43:58 UTC-08:00
抢占
从上面可以看到在SW1的display vrrp显示的信息中Preempt字段的值为yes
这个字段可以控制主从切换的抢占功能是否开启。
如果要关闭抢占功能,同样需要提供vrid并以disable值给preempt,那么关闭SW1的抢占别人的功能如:
[SW1-Vlanif10]vrrp vrid 1 preempt-mode disable
然后发现关闭抢占功能后,SW1原来是backup并且目前最大优先级是120的SW2,那么按照原来的思路只要把SW1的优先级的值调整的高于120,比如这里调整为150则肯定再次成功抢占到master。
[SW1-Vlanif10]vrrp vrid 1 priority 150
[SW1-Vlanif10]
Dec 5 2020 18:53:07-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25.
191.3.1 configurations have been changed. The current change number is 11, the ch
ange loop count is 0, and the maximum number of records is 4095.
[SW1-Vlanif10]display vrrp
Vlanif10 | Virtual Router 1
State : Backup
Virtual IP : 10.1.1.254
Master IP : 10.1.1.2
PriorityRun : 150
PriorityConfig : 150
MasterPriority : 120
Preempt : NO
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2020-12-05 18:33:05 UTC-08:00
Last change time : 2020-12-05 18:43:58 UTC-08:00
那么可以看到实际上并没有抢占成功。
撤销preempt
如果要撤销preempt则也要提供vrid,如这里重新撤销掉刚才的preempt的配置
[SW1-Vlanif10]und vrrp vrid 1 preempt-mode
[SW1-Vlanif10]
Dec 5 2020 18:56:14-08:00 SW1 %%01VRRP/4/STATEWARNINGEXTEND(l)[4]:Virtual Router
state BACKUP changed to MASTER, because of priority calculation. (Interface=Vlan
if10, VrId=1, InetType=IPv4)
[SW1-Vlanif10]
Dec 5 2020 18:56:17-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25.
191.3.1 configurations have been changed. The current change number is 12, the ch
ange loop count is 0, and the maximum number of records is 4095.
[SW1-Vlanif10]display vrrp
Vlanif10 | Virtual Router 1
State : Master
Virtual IP : 10.1.1.254
Master IP : 10.1.1.1
PriorityRun : 150
PriorityConfig : 150
MasterPriority : 150
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2020-12-05 18:33:05 UTC-08:00
Last change time : 2020-12-05 18:56:14 UTC-08:00
这里会发现preempt的配置撤销后由于刚才优先级已经调整到150了,所以preempt撤销后立马SW1就抢占到了master的状态。
测试宕机
先软宕掉SW1
[SW1]interface g0/0/1
[SW1-GigabitEthernet0/0/1]shutdown
然后回到SW2中我们知道SW1刚才宕掉之前已经抢占到了master的状态,然后现在SW1宕掉后SW2又重新抢占到了master的状态了
<SW2>display vrrp
Vlanif10 | Virtual Router 1
State : Master
Virtual IP : 10.1.1.254
Master IP : 10.1.1.2
PriorityRun : 120
PriorityConfig : 120
MasterPriority : 120
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2020-12-05 18:35:14 UTC-08:00
Last change time : 2020-12-05 19:00:05 UTC-08:00
然后撤销掉SW1的宕机后发现SW1再再次抢占到了master状态
[SW1-GigabitEthernet0/0/1]undo shutdown
[SW1-GigabitEthernet0/0/1]
Dec 5 2020 19:02:47-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25.
191.3.1 configurations have been changed. The current change number is 14, the ch
ange loop count is 0, and the maximum number of records is 4095.
[SW1-GigabitEthernet0/0/1]
Dec 5 2020 19:02:49-08:00 SW1 %%01PHY/1/PHY(l)[11]: GigabitEthernet0/0/1: cha
nge status to up
Dec 5 2020 19:02:49-08:00 SW1 %%01IFNET/4/IF_STATE(l)[12]:Interface Vlanif1 has
turned into UP state.
Dec 5 2020 19:02:49-08:00 SW1 %%01IFNET/4/IF_STATE(l)[13]:Interface Vlanif10 has
turned into UP state.
Dec 5 2020 19:02:49-08:00 SW1 %%01IFNET/4/LINK_STATE(l)[14]:The line protocol IP
on the interface Vlanif10 has entered the UP state.
[SW1-GigabitEthernet0/0/1]display
Dec 5 2020 19:02:55-08:00 SW1 %%01VRRP/4/STATEWARNINGEXTEND(l)[15]:Virtual Route
r state BACKUP changed to MASTER, because of priority calculation. (Interface=Vla
nif10, VrId=1, InetTy
[SW1-GigabitEthernet0/0/1]display vrrp
Vlanif10 | Virtual Router 1
State : Master
Virtual IP : 10.1.1.254
Master IP : 10.1.1.1
PriorityRun : 150
PriorityConfig : 150
MasterPriority : 150
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2020-12-05 18:33:05 UTC-08:00
Last change time : 2020-12-05 19:02:55 UTC-08:00
255特殊优先级
现在分别把SW1与SW2的VRRP都撤销
[SW1-Vlanif10]undo vrrp vrid 1
[SW2-Vlanif10]undo vrrp vrid 1
然后SW1重新配置虚拟ip地址为其vlan 10的ip地址(10.1.1.1)如
[SW1-Vlanif10]vrrp vrid 1 virtual-ip 10.1.1.1
Warning: The priority of this VRRP backup group has changed to 255 and will not c
hange.
[SW1-Vlanif10]
Dec 5 2020 19:13:53-08:00 SW1 %%01VRRP/4/STATEWARNINGEXTEND(l)[18]:Virtual Route
r state INITIALIZE changed to MASTER, because of interface up. (Interface=Vlanif1
0, VrId=1, InetType=IPv4)
[SW1-Vlanif10]
Dec 5 2020 19:13:58-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25.
191.3.1 configurations have been changed. The current change number is 16, the ch
ange loop count is 0, and the maximum number of records is 4095.
[SW1-Vlanif10]
可以看到有提示优先级变成255了并且不能被更改了,此时把SW2也配置起来
[SW2-Vlanif10]vrrp vrid 1 virtual-ip 10.1.1.1
此时回到SW1中可以看到display vrrp的信息中SW1仍(…)是master状态了。
[SW1-Vlanif10]display vrrp
Vlanif10 | Virtual Router 1
State : Master
Virtual IP : 10.1.1.1
Master IP : 10.1.1.1
PriorityRun : 255
PriorityConfig : 100
MasterPriority : 255
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2020-12-05 19:13:53 UTC-08:00
Last change time : 2020-12-05 19:13:53 UTC-08:00
而对于SW2肯定是backup状态了
[SW2-Vlanif10]display vrrp
Vlanif10 | Virtual Router 1
State : Backup
Virtual IP : 10.1.1.1
Master IP : 10.1.1.1
PriorityRun : 100
PriorityConfig : 100
MasterPriority : 255
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2020-12-05 19:17:27 UTC-08:00
Last change time : 2020-12-05 19:17:27 UTC-08:00
那么现在有个问题就是为什么提示说SW1的优先级已经是不能改了?并且是master?
因为配置为物理接口时候,那么如果SW2抢了master做为SW1的物理接口地址,那么再加上原来SW1的物理接口(vlan 10的10.1.1.1)地址岂不是出现了两个相同的ip地址,这样就导致ip冲突了
再加上用户可以配置的最大优先级是254,所以系统默认把这种情况下的优先级配置到255,用户就无法去抢占了
[SW1-Vlanif10]vrrp vrid 1 priority 10
[SW1-Vlanif10]vrrp vrid 1 priority 10
Dec 5 2020 19:25:08-08:00 SW1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25.
191.3.1 configurations have been changed. The current change number is 17, the ch
ange loop count is 0, and the maximum number of records is 4095.
[SW1-Vlanif10]vrrp vrid 1 priority ?
INTEGER<1-254> The level of priority(default is 100)
[SW1-Vlanif10]vrrp vrid 1 priority
^
Error:Incomplete command found at '^' position.
[SW1-Vlanif10]display vrrp
Vlanif10 | Virtual Router 1
State : Master
Virtual IP : 10.1.1.1
Master IP : 10.1.1.1
PriorityRun : 255
PriorityConfig : 10
MasterPriority : 255
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2020-12-05 19:13:53 UTC-08:00
Last change time : 2020-12-05 19:13:53 UTC-08:00
关键字词:VRRP,华为,数据通信