002 HAPROXY +Nginx动静分离负载

模拟准备:

1.三台VMware虚拟机,两台安装配置Nginx,一台安装配置Haproxy;

2.静态页面及springbootDemo程序;

安装配置:

1.创建测试项目springboot-Demo:

创建测试用接口:

启动测试:

进入Terminal快速测试:

测试成功;

关闭项目进行打包!

完成后jar包会在target目录中,启动jar测试:

测试:

测试完成;

将jar包上传到两台server服务器(虚拟机):

上传完成后拷贝到应用账户中:

修改权限:

【关于sudo出现: xxx is not in the sudoers file.This incident will be reported.请参考https://www.cnblogs.com/xiaochaoyxc/p/6206481.html

分别启动两台虚拟机jar包:

启动完成后测试:

测试完成。

1.虚拟机server1(IP:192.168.85.128)安装nginx并启动测试:

虚拟机server2同上,IP:192.168.85.130端口80;

2.虚拟机serverH(IP:192.168.85.131)安装配置Haproxy:

创建配置文件:haproxy-dynamic.cfg

global
log 127.0.0.1 local2
chroot /var/empty
pidfile /var/run/haproxy.pid
maxconn 20000
user haproxy
group haproxy
daemon
spread-checks 2

defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
timeout http-request 2s
timeout queue 3s
timeout connect 1s
timeout client 10s
timeout server 2s
timeout http-keep-alive 10s
timeout check 2s
maxconn 18000

frontend http-in
bind *:80
mode http
log global
capture request header Host len 20
capture request header Referer len 60
acl url_static path_beg -i /static /images /img /css /stylesheets
acl url_static path_end -i .jpg .jpeg .gif .png .ico .css .js .bmp
acl url_static path_end -i .html .htm .shtml .pdf .mp3 .mp4 .rmvb .txt
acl url_static path_end -i .zip .rar
use_backend static_group if url_static
default_backend dynamic_group

backend static_group
balance roundrobin
option http-keep-alive
http-reuse safe
option httpchk GET /index.html
http-check expect status 200
server staticsrv1 192.168.85.128:81 check rise 1 maxconn 5000
server staticsrv2 192.168.85.130:80 check rise 1 maxconn 5000

backend dynamic_group
balance roundrobin
option http-server-close
http-reuse safe
option httpchk GET /index
http-check expect status 200
server app-srv1 192.168.85.128:8080 check rise 1 maxconn 5000
server app-srv2 192.168.85.130:8080 check rise 1 maxconn 5000

listen report_stats
bind *:8081
stats enable
stats hide-version
stats uri /hastats
stats realm "pls enter your name"
stats auth admin:admin
                                                                                                                                      

启动Haproxy:

访问:192.168.85.131/index.html    静态资源

再次访问(轮询负载):

点击Goto-app访问动态资源:

静态页面代码:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值