haproxy是什么?以及haproxy基础实验

news2024/9/22 17:37:25

目录

一、什么是负载均衡?

二、为什么要用haproxy?

三、haproxy的基本部署实验:

3.1 基本配置实验

环境准备:

详细步骤:

3.2 haproxy-多进程与多线程实验:

多进程:

多线程:

四、haproxy的全局global配置实验:

五、haproxy的proxies配置实验:server

环境准备:

实验步骤:


haproxy的工具及其算法:haproxy的工具及其算法-CSDN博客

haproxy 高级功能及配置:haproxy 高级功能及配置-CSDN博客

一、什么是负载均衡?

负载均衡:Load Balance,简称LB,是一种服务或基于硬件设备等实现的高可用反向代理技术,负载均衡将特定的业务(web服务、网络流量等)分担给指定的一个或多个后端特定的服务器或设备,从而提高了公司业务的并发处理能力、保证了业务的高可用性、方便了业务后期的水平动态扩展。

1.1 负载均衡的特点:

1. Web服务器的动态水平扩展
2. 增加业务并发访问及处理能力
3. 节约公网IP地址:节约成本
4. 隐藏內部服务器IP:提高内部服务器安全性
5. 配置简单
6. 功能丰富:支持四层和七层
7. 性能较强

1.2 四层负载均衡:

客户端访问服务器:修改报文头部的目标地址,修改源地址(NAT不改源地址)。

1. 通过 ip+port 决定负载均衡的去向。
2. 对流量请求进行 NAT 处理,转发至后台服务器。
3. 记录 tcp、udp 流量分别是 由哪台服务器处理,后续该请求连接的流量都通过该服务器处理。
4. 支持四层的软件:
        Ivs:重量级四层负载均衡器。
        Nginx:轻量级四层负载均衡器,可缓存。 (nginx四层是通过upstream模块)
        Haproxy:模拟四层转发。

1.3 七层负载均衡:

1. 通过虚拟 url 或主机 ip 进行流量识别,根据应用层信息进行解析,决定是否需要进行负载均衡。
2. 代理后台服务器与客户端建立连接,如 nginx 可代理前后端,与前端客户端 tcp 连接,与后端服务器建立tcp连接
3. 支持七层代理的软件:
        Nginx:基于http协议(nginx七层是通过proxy_ pass)
        Haproxy:七层代理,会话保持、标记、路径转移等。

1.4 四层和七层的对比:

同样性能的前提下,不涉及后端检测或者七层,选择四层更快。如果涉及到动静分离,url分析等,选择七层。

1. 分层位置:四层负载均衡在传输层及以下,七层负载均衡在应用层及以下。

2. 性能:四层负载均衡架构无需解析报文消息内容,在网络吞吐量与处理能力上较高:七层可支持解析应用层报文消息内容,识别URL、Cookie、HTTP header等信息。
3. 原理:四层负载均衡是基于ip+port;七层是基于虚拟的URL或主机IP等。
4. 功能类比:四层负载均衡类似于路由器;七层类似于代理服务器(正向和反向代理)。
5. 安全性:四层负载均衡无法识别DDoS攻击;七层可防御SYN Cookie/Flood攻击。

正向和反向代理

正向代理:翻墙,不同国家之间的请求,国家之间有防火墙,可通过其他地域的代理进行请求。

反向代理:类似于LVS。不同地点的服务器,请求可通过所在地的LVS代理,有则返回,没有则代理向服务器请求。

mode http #7层

mode tcp  #4层

二、为什么要用haproxy?

LVS:没有后端检测,当后端出现问题时,LVS仍然会去访问服务停止的主机。

        优点:速度快,体积小

        缺点:没有后端检测,不能实现七层负载

haproxy:可以实现当后端出现问题时,会把所以流量达到正常的主机上。即可实现四层负载也可实现七层负载。

配置文件及基本参数:

HAProxy的配置文件 haproxy.cfg 由两大部分组成,分别是:

1. global:全局配置段
① 进程及安全配置相关的参数
② 性能调整相关参数
③ Debug参数


2. proxies:代理配置段
① defaults:为frontend, backend, listen提供默认配置
② frontend:前端,相当于nginx中的server {}
③ backend:后端,相当于nginx中的upstream {}
④ listen:同时拥有前端和后端配置,配置简单,生产推荐使用

global参数类型作用proxies参数类型作用
chroot全局锁定运行目录defaultsproxies默认配置项,针对以下的frontend、backend和listen生效, 可以多个name也可以没有name
deamon全局以守护进程运行frontendproxies前端servername,类似于Nginx的一个虚拟主机server和LVS服务集群。
user, group, uid, gid全局运行haproxy的用户身份backendproxies#后端服务器组,等于nginx的upstream和LVS中的RS服务器作用
stats socket全局套接字文件listenproxies#将frontend和backend合并在一起配置,相对于frontend和backend配置更简洁,生产常用
nbproc N全局开启的haproxy worker进程数,默认进程数是一个
nbthread 1 (和nbproc互斥)全局指定每个haproxy进程开启的线程数,默认为每个进程一个线程
cpu-map 1 0全局绑定haproxy worker进程至指定CPU,将第1个work进程绑定至0号CPU 
cpu-map 2 1全局绑定haproxy worker进程至指定CPU,将第2个work进程绑定至1号CPU
maxconn N全局每个haproxy进程的最大并发连接数
maxsslconn N全局每个haproxy进程ssl最大连接数,用于haproxy配置了证书的场景下
maxconnrate N全局每个进程每秒创建的最大连接数量

三、haproxy的基本部署实验:

3.1 基本配置实验

环境准备:

需要三台虚拟机

rhel9克隆:haproxy(172.25.254.100)、webserver1(172.25.254.10)、webserver2(172.25.254.20)

详细步骤:

vmset.sh为设置IP及解析

[root@haproxy ~]# cat /bin/vmset.sh
#!/bin/bash
rm -fr /etc/NetworkManager/system-connections/$1.nmconnection
cat > /etc/NetworkManager/system-connections/$1.nmconnection <<EOF
[connection]
id=$1
type=ethernet
interface-name=$1
[ipv4]
address1=$2/24,172.25.254.2
method=manual
dns=114.114.114.114;
EOF
 
chmod 600 /etc/NetworkManager/system-connections/$1.nmconnection
nmcli connection reload
nmcli connection up $1
 
hostnamectl hostname $3
 
cat > /etc/hosts <<EOF
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
$2	$3
EOF
haproxy部分
#haproxy部分:
#vmset.sh eth0 172.25.254.100 haproxy.company.org
[root@haproxy ~]# 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,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:cc:d6:59 brd ff:ff:ff:ff:ff:ff
    altname enp3s0
    altname ens160
    inet 172.25.254.100/24 brd 172.25.254.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::e9d9:e029:7f5a:84bf/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@haproxy ~]# 
#此处是在下面的webserver1和webserver2的nginx部分做完后,进行测试的
[root@haproxy ~]# curl 172.25.254.10
webserver1 - 172.25.254.10
[root@haproxy ~]# curl 172.25.254.20
webserver2 - 172.25.254.20


#haproxy实现LVS轮询调度
[root@haproxy ~]# dnf install haproxy -y
Complete!
[root@haproxy ~]# rpm -qc haproxy 
/etc/haproxy/haproxy.cfg
/etc/logrotate.d/haproxy
/etc/sysconfig/haproxy
[root@haproxy ~]# 
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
[root@haproxy ~]# systemctl enable haproxy.service 
Created symlink /etc/systemd/system/multi-user.target.wants/haproxy.service → /usr/lib/systemd/system/haproxy.service.
[root@haproxy ~]# systemctl restart haproxy.service 
[root@haproxy ~]# curl 172.25.254.100
webserver1 - 172.25.254.10
[root@haproxy ~]# curl 172.25.254.100
webserver2 - 172.25.254.20
[root@haproxy ~]# curl 172.25.254.100
webserver1 - 172.25.254.10

编写配置文件:

vim /etc/haproxy/haproxy.cfg

大约在69行左右,添加以下内容,选择其中一种方式,即可实现haproxy的轮询效果

webserver1部分
#webserver1部分:
#vmset.sh eth0 172.25.254.10 webserver1.company.org
[root@webserver1 ~]# 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,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:03:5f:47 brd ff:ff:ff:ff:ff:ff
    altname enp3s0
    altname ens160
    inet 172.25.254.10/24 brd 172.25.254.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::b947:4cf:357d:b67e/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@webserver1 ~]# 
[root@webserver1 ~]# dnf install nginx -y
Complete!
[root@webserver1 ~]# echo webserver1 - 172.25.254.10 > /usr/share/nginx/html/index.html
[root@webserver1 ~]# systemctl enable --now nginx.service 
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
#之后进出haproxy进行curl测试
webserver2部分
#webserver2部分:
#vmset.sh eth0 172.25.254.20 webserver2.company.org
[root@webserver2 ~]# 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,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:f6:d1:9e brd ff:ff:ff:ff:ff:ff
    altname enp3s0
    altname ens160
    inet 172.25.254.20/24 brd 172.25.254.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::d9bf:66c4:33ab:9efa/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@webserver2 ~]# 
[root@webserver2 ~]# dnf install nginx -y
Complete!
[root@webserver2 ~]# echo webserver2 - 172.25.254.20 > /usr/share/nginx/html/index.html
[root@webserver2 ~]# systemctl enable --now nginx.service 
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
#之后进出haproxy进行curl测试

3.2 haproxy-多进程与多线程实验:

多进程:

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
[root@haproxy ~]# systemctl restart haproxy.service 
[root@haproxy ~]# pstree -p | grep haproxy
           |-haproxy(1586)-+-haproxy(1588)
           |               `-haproxy(1589)

多线程:

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
[root@haproxy ~]# systemctl restart haproxy.service 
[root@haproxy ~]# pstree -p | grep haproxy
           |-haproxy(1569)---haproxy(1571)---{haproxy}(1572)

 

四、haproxy的全局global配置实验:

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
[root@haproxy ~]# systemctl restart haproxy.service 
[root@haproxy ~]# vim /etc/rsyslog.conf 
[root@haproxy ~]# ll /var/log/haproxy.log 
-rw------- 1 root root 5436 Aug  7 16:34 /var/log/haproxy.log

 

五、haproxy的proxies配置实验:server

环境准备:

上面实验的基础上完成该实验

10与20:

systemctl stop nginx #测试sorry提示是否出现

systemctl start nginx #测试能否访问

100:

dnf install httpd -y

实验步骤:

haproxy 部分

[root@haproxy ~]# dnf install httpd -y
[root@haproxy ~]# vim /etc/httpd/conf/httpd.conf 		#将监听Listen端口改为8080
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 			#见图一
[root@haproxy ~]# systemctl restart haproxy.service 

#首先需停止webserver1和webserver2的nginx服务
[root@haproxy ~]# curl 172.25.254.100
<html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>
[root@haproxy ~]# echo sorry, this is down > /var/www/html/index.html
[root@haproxy ~]# systemctl restart httpd
[root@haproxy ~]# curl 172.25.254.100
sorry, this is down

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy.service 
[root@haproxy ~]# curl 172.25.254.100
sorry, this is down
#启动webserver2的nginx服务
[root@haproxy ~]# curl 172.25.254.100
webserver2 - 172.25.254.20
[root@haproxy ~]# curl 172.25.254.100
webserver2 - 172.25.254.20
[root@haproxy ~]# curl 172.25.254.100
webserver2 - 172.25.254.20
[root@haproxy ~]# 

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
[root@haproxy ~]# systemctl restart haproxy.service 
#启动webserver1和webserver2的nginx服务
[root@haproxy ~]# curl 172.25.254.100
webserver1 - 172.25.254.10
[root@haproxy ~]# curl 172.25.254.100
webserver1 - 172.25.254.10
[root@haproxy ~]# curl 172.25.254.100
webserver2 - 172.25.254.20
[root@haproxy ~]# curl 172.25.254.100
webserver1 - 172.25.254.10
[root@haproxy ~]# curl 172.25.254.100
webserver1 - 172.25.254.10
[root@haproxy ~]# curl 172.25.254.100
webserver2 - 172.25.254.20
[root@haproxy ~]# 

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
[root@haproxy ~]# systemctl restart haproxy.service

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
[root@haproxy ~]# systemctl restart haproxy.service 
#之后去网页测试

webserver1 部分 

[root@webserver1 ~]# systemctl stop nginx.service 
[root@webserver1 ~]# systemctl start nginx.service 
[root@webserver1 ~]# while true; do curl 172.25.254.100; sleep 0.1; done
webserver1 - 172.25.254.10
webserver1 - 172.25.254.10
webserver2 - 172.25.254.20
webserver1 - 172.25.254.10
webserver1 - 172.25.254.10
webserver2 - 172.25.254.20
webserver1 - 172.25.254.10
webserver1 - 172.25.254.10
...

webserver2 部分 

[root@webserver2 ~]# systemctl stop nginx.service 
[root@webserver2 ~]# systemctl start nginx.service 
[root@webserver2 ~]# while true
> do
> curl 172.25.254.100
> sleep 0.1
> done
webserver2 - 172.25.254.20
webserver1 - 172.25.254.10
webserver1 - 172.25.254.10
webserver2 - 172.25.254.20
webserver1 - 172.25.254.10
webserver1 - 172.25.254.10
webserver2 - 172.25.254.20
webserver1 - 172.25.254.10
...

vim /etc/haproxy/haproxy.cfg

增加 redirect prefix http://www.baidu.com/

之后去网站访问就会自动跳转到百度了!

haproxy的工具及其算法

haproxy的工具及其算法-CSDN博客

haproxy 高级功能及配置

haproxy 高级功能及配置-CSDN博客

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2034379.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【云服务器】 阿里云服务器免费试用3个月 不用学生认证

审核大大&#xff0c;这个真的不是广告呀...也是我琢磨了一下发现的一个方式&#xff0c;阿里云会找我打广告吗&#xff1f;&#xff1f; 这个羊毛不用学生认证&#xff01;&#xff01;只需登录和实名认证和即可 学生实名认证是送优惠券300&#xff0c;我没用上&#xff0c;…

Google 开发者大会(北京站) Play政策会议内容解读

2024年Google开发者大会的会议已结束&#xff0c;很庆幸自己参与了 Google Play 专场&#xff1a;全球视野&#xff0c;助力出海创新与增长 [13:00 - 15:10] 的工作坊内容&#xff0c;受益匪浅。 Google对未来Play市场的愿景&#xff0c;Play Console后台的全新功能&#xff0…

漏洞复现-XXL-JOB accessToken 存在身份认证绕过漏洞

1.漏洞描述 XXL-JOB是许雪里&#xff08;XXL-JOB&#xff09;社区的一款基于java语言的分布式任务调度平台。 2.影响版本 XXL-JOB < 2.2.0 3.影响范围 4.漏洞分析 首先通过微步的漏洞通报说是 src/main/resources/application.properties 默认情况下是非空的&#xff…

HAPropy全功能详解

在一个lvs的环境中&#xff0c;如果服务器出现故障&#xff0c;按照lvs的策略却依然会将访问方式到故障服务器&#xff0c;必然是没有回应的结果&#xff0c;在一个集群中&#xff0c;一台服务器出现故障&#xff0c;理应灵活的去寻找没有故障的服务器&#xff0c;这种方法可以…

免费【2024】springboot 个人博客系统的设计与实现

博主介绍&#xff1a;✌CSDN新星计划导师、Java领域优质创作者、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和学生毕业项目实战,高校老师/讲师/同行前辈交流✌ 技术范围&#xff1a;SpringBoot、Vue、SSM、HTML、Jsp、PHP、Nodejs、Python、爬虫、数据可视化…

C语言寻找波峰值

做到项目有需要压力采集的处理&#xff0c;为了便于在程序中计算采集的波形数据&#xff0c;这里简单写一个查找波峰的程序 首先用Python把波峰点找出来&#xff0c; 方便我们对照 我这里主要是判断波峰&#xff0c;波谷的原理也大同小异&#xff0c;改一下程序就行 波峰判断…

顺丰科技2025届校招面试流程、SHL测评题型、笔试题库及答案解析

顺丰科技有限公司成立于2009年&#xff0c;是顺丰旗下专注供应链数智解决方案的科技服务商。我们深耕于供应链数智化十余年&#xff0c;致力于构建卓越的智慧供应链&#xff0c;重塑全球商业文明和生产方式。我们基于对供应链场景的深度理解和行业头部公司的数智化实战经验&…

手机CPU性能天梯图(2024年8月),含安兔兔/GB6/3DMark跑分

原文地址&#xff08;高清无水印原图/持续更新/含榜单出处链接&#xff09;&#xff1a; 2024年8月手机处理器天梯图 2024年8月1日更新日志&#xff1a;由于近期并未有新处理器发布&#xff0c;故只做常规更新&#xff1b;移除鲁大师天梯图&#xff1b;补充其它天梯图数量。 -…

介质套检测方案,如何提升检测效率?

介质套是一种用于保护和装饰电子设备的外壳或套子。这种套子通常由各种材料制成&#xff0c;如硅胶、塑料、皮革等&#xff0c;具有不同的质地和外观风格。介质套可适用于各种电子设备&#xff0c;如手机、平板电脑、笔记本电脑等&#xff0c;为其提供额外的保护&#xff0c;并…

S32G3系列芯片如何从外置flash进行Boot启动?

《S32G3系列芯片——Boot详解》系列——S32G3系列芯片如何从外置flash进行Boot启动&#xff1f; 一、概述二、基于QuadSPI的boot2.1 基于QuadSPI的boot方式概述2.2 IO配置2.3 时钟配置2.4 QuadSPI具体配置参数2.5 系统重置后BootROM对闪存的要求2.6 应用程序对闪存配置的影响 三…

审稿超慢的顶刊,年年投稿量爆涨?年发文量1800+,国人投稿占优!

点击关注&#xff1a;关注GZH【欧亚科睿学术】&#xff0c;GET完整版2023JCR分区列表&#xff01; &#x1f525; &#x1f525; &#x1f525; &#x1f525; ELSEVIER旗下1区TOP刊 今天小编给大家介绍的是一本计算机人工智能领域的期刊《Engineering Applications of…

腾讯云AI代码助手:智能AI代码助手 ,新一代的高效代码开发辅助工具

前言 近些年是一个科技大爆发的时代&#xff0c;自从大模型发布以来越来越多的科技产品出现。例如去年的智能编码助手自出现以来&#xff0c;各大老牌大厂腾讯&#xff0c;百度 阿里也都紧随其后&#xff0c;智能编码助手的出现可以说大大的节省了我们写一些冗余代码的时间成本…

滑动窗口 | Java | (hot100) 力扣 3

力扣 3.无重复字符的最长子串 暴力法&#xff1a;双层for循环&#xff0c;i-j的字符查重 滑动窗口&#xff1a;因为这题被分在这个类别里&#xff0c;那么已知要用滑动窗口&#xff0c;思路应该是什么。 反正我想不出来…… 看了别人的题解写出来的出错点&#xff1a;特别容易…

达梦数据库的系统视图v$sql_stat

达梦数据库的系统视图v$sql_stat 达梦数据库的系统视图V$SQL_STAT用于记录当前正在执行的SQL语句的资源开销。这个视图需要启用监控功能&#xff08;即ENABLE_MONITOR1&#xff09;才开始监控。针 对 63~68 列 中 的 监 控 项 &#xff0c; 还 需 开 启 参 数 MONITOR_SQL_EXE…

通过这五个问题,带你深入了解中国式报表

一、什么是中国式报表&#xff1f; 中国式报表&#xff0c;顾名思义具有中国特色的报表&#xff0c;通常指的是中国企业/机构在财务和业务报告方面的特有风格和规范。 二、中国式报表有什么特点&#xff1f; 一句话就可以概括中国式报表&#xff1a;结构复杂、数据量大的一种…

计算机毕业设计选题推荐-高校大学生竞赛项目管理系统-Java/Python项目实战

✨作者主页&#xff1a;IT毕设梦工厂✨ 个人简介&#xff1a;曾从事计算机专业培训教学&#xff0c;擅长Java、Python、微信小程序、Golang、安卓Android等项目实战。接项目定制开发、代码讲解、答辩教学、文档编写、降重等。 ☑文末获取源码☑ 精彩专栏推荐⬇⬇⬇ Java项目 Py…

8.13-LVS的nat模式+DR模式

LVS 一、nat模式 1.角色 主机名ip地址功能web01192.168.2.101rsweb02192.168.2.102realserveenat内网:192.168.2.103 外网:192.168.2.120directorserver,ntpdns192.168.2.105dns 2..web服务器 [rootweb01 ~]# yum -y install nginx ​ [rootweb01 ~]# echo "web01&qu…

【netty系列-07】Netty中组件初步了解和基本使用

Netty系列整体栏目 内容链接地址【一】深入理解网络通信基本原理和tcp/ip协议https://zhenghuisheng.blog.csdn.net/article/details/136359640【二】深入理解Socket本质和BIOhttps://zhenghuisheng.blog.csdn.net/article/details/136549478【三】深入理解NIO的基本原理和底层…

Java语言程序设计基础篇_编程练习题*16.20(累计秒表)

目录 题目&#xff1a;*16.20&#xff08;累计秒表&#xff09; 习题思路 代码示例 结果展示 题目&#xff1a;*16.20&#xff08;累计秒表&#xff09; 编写一个程序&#xff0c;模拟一个秒表&#xff0c;如图16-45a所示。当用户单击Start按钮时&#xff0c;按钮的标签变为Pa…

AHB协议解读

1.定义 AHB或者ASB系统总线在需要做大量数据传送的模块之间提供了高带宽的接口。同时&#xff0c;外围总线APB在AHB或者ASB和低带宽的外围设备之间提供了通信的桥梁。所以APB是AHB或者ASB的二级扩展总线 2.拓扑结构 2.1 Master: 可以是CPU、DMA控制器、外设控制器等。Maste…