模拟准备:
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访问动态资源:
静态页面代码: