[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
原理
生成树协议(spanning-tree),作用是在交换网络中提供冗余备份链路,并且解决交换网络中的环路问题。生成树协议是利用SPA算法(生成树算法),在存在交换环路的网络中生成一个没有环路的树形网络。运用该算法将交换网络冗余的备份链路逻辑上断开,当主要链路出现故障时,能够自动的切换到备份链路,保证数据的正常转发。
生成树协议目前常见的版本有STP(生成树协议IEEE802.1d)、RSTP(快速生成树协议IEEE802.1w)、MSTP(多生成树协议IEEE802.1s)。
生成树协议的特点是收敛时间长。当主要链路出现故障以后,到切换到备份链路需要50秒的时间。
快速生成树协议(RSTP)在生成树协议的基础上增加了两种端口角色:替换端口(alternate Port)和备份端口(backup
Port),分别做为根端口(root Port)和指定端口(designated
Port)的冗余端口。当根端口或指定端口出现故障时,冗余端口不需要经过50秒的收敛时间,可以直接切换到替换端口或备份端口。从而实现RSTP协议小于1秒的快速收敛。
快速生成树基础配置
开启STP:switch(config)# spanning-tree vlan 1
设置RSTP:switch(config)# spanning-tree mode rapid-pvst
设置STP:switch(config)# spanning-tree mode pvst
关闭STP:switch(config)# no spanning-tree vlan 1(要把全部vlan都关闭哦)
设置交换机优先级:switch(config)# spanning-tree vlan 1 priority +数字
指定根交换机:switch(config)# spanning-tree vlan 1 root primary
查看交换机生成树配置状态:switch # show spanning-tree
查看交换机端口状态:switch # show spanning-tree interfaces fastEthernet 0/1
验证测试
!!!按照拓扑图连接网络时注意,两台交换机都配置快速生成树协议后,再将两台交换机连接起来。如果先连线再配置会造成广播风暴,影响交换机的正常工作。
(1)网络拓扑图
(2)在两个交换机上的操作:创建vlan 10,并将端口0/3划入vlan 10,将端口0/1-2配置为trunk,开启STP,switch0是根交换机
(3)PC0连续pingPC1,ping期间将switch0与switch1的端口F0/1之间的链路down掉,中间有一段时间丢包,之后切换链路,PC0仍能ping通PC1,丢包5个
(4) 将两个交换机设置为RSTP,switch0是根交换机
(5)PC0连续pingPC1,ping期间将switch0与switch1的端口F0/1之间的链路down掉,很快地切换链路,没有丢包