部署配置haproxy,能够实现将来自用户的80端口的http请求转发至后端8000上的server服务,写出其配置过程。
HAPorxy
是免费的、极速且可靠的用于为TCP和基于HTTP应用程序提供高可用、负载均衡和代理服务的解决方案,
尤其适用于高负载且需持久连接或7层处理机制的web站点
软件特性:
只是http协议的反向代理,不提供缓存功能;但额外支持对tcp层对基于tcp通信的应用做LB;
使用场景:适合使用于大型互联网外网或者内网4&7层负载均衡。
准备两台web服务器:
第一台配置:
[root@node2 ~]# yum install nginx -y
[root@node2 ~]# vim /etc/nginx/nginx.conf
listen 8000 default_server; ###监听在8000端口
[root@node2 ~]# vim/usr/share/nginx/html/index.html
server 192.168.1.150
[root@node2 ~]# systemctl startnginx.service
第二台配置:
[root@node3 ~]# yum install nginx -y
[root@node3 ~]# vim /etc/nginx/nginx.conf
listen 8000 default_server; ###监听在8000端口
[root@node3 ~]# vim/usr/share/nginx/html/index.html
server 192.168.1.155
[root@node2 ~]# systemctl startnginx.service
二、准备一台haproxy服务器:
[root@node1 ~]# yum install haproxy -y ###安装haproxy
[root@node1 haproxy]# vim/etc/haproxy/haproxy.cfg ###编辑配置文件
frontend mysrvs
bind *:80
default_backend websrvs
backend websrvs
balance roundrobin ###动态算法,支持权重的运行时调整及慢启动机制
cookie SERVERID rewrite ###cookie中的SERVERID重写
server websrv1192.168.1.150:8000 cookie 1 weight 2 check inter 2000 rise 2 fall 3 ###权重为2,检测心跳为2000,2次正确认为服务器可用,fall3是3次失败认为服务器不可用
server websrv2192.168.1.155:8000 cookie 2 weight 1 check inter 2000 rise 2 fall 3
[root@node1 haproxy]# systemctl starthaproxy ###启动haproxy
网页端测试:
转载于:https://blog.51cto.com/rylan/1967348