文章目录
haproxy类似nginx、apache 均是7层负载:动静分离,比较智能,可以实现高可用+负载均衡+支持虚拟主机
和nginx很像,但是haproxy(不可以缓存)和nginx(可以缓存),二者都是httpd的代理
注:七层负载均衡没有四层速度快。
1 搭建实验环境
三台7版本的虚拟机+一台7版本的物理机
主机名 IP 服务 虚拟机server1 192.168.0.11 #haproxy,httpd,代理服务器
虚拟机server2 192.168.0.12 # httpd,php,后端服务器
虚拟机server3 192.168.0.13 #httpd,php,后端服务器 物理机 192.168.0.20 测试端
2 搭建一个基本的haproxy服务器
(1)在server1上面搭建HAProxy服务器
安装haproxy服务
(2)查看该服务的版本和查看安装后都生成了什么文件
(3)查看是否生成了haproxy用户
3.利用haproxy实现负载均衡
(1)修改配置文件
(2)打开两台全新虚拟机:
安装httpd服务
编写测试页
开启httpd服务,并且检测
[root@server2 ~]# yum install httpd -y
[root@server2 ~]# echo www.server2.com > /var/www/html/index.html
[root@server2 ~]# systemctl restart httpd
[root@server2 ~]# curl localhost
www.server2.com
[root@server3 ~]# yum install httpd -y
[root@server3 ~]# echo www.server3.com > /var/www/html/index.html
[root@server3 ~]# systemctl restart httpd
[root@server3 ~]# curl localhost
www