Debian环境下WebLogic负载均衡实践
一 架构与准备
二 方案一 使用 Nginx 进行负载均衡
sudo apt update && sudo apt install nginxsudo systemctl enable --now nginxhttp {
upstream weblogic_cluster {
least_conn; # 可选:最少连接
server weblogic1.example.com:7001 max_fails=3 fail_timeout=30s;
server weblogic2.example.com:7001 max_fails=3 fail_timeout=30s;
server weblogic3.example.com:7001 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://weblogic_cluster;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
max_fails 与 fail_timeout 实现被动健康检查,失败超过阈值将被暂时剔除。sudo nginx -tsudo systemctl reload nginx三 方案二 使用 HAProxy 进行负载均衡
sudo apt update && sudo apt install haproxysudo systemctl enable --now haproxyglobal
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
maxconn 4096
user haproxy
group haproxy
daemon
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
frontend web_front
bind *:80
default_backend weblogic_cluster
backend weblogic_cluster
balance leastconn
option httpchk GET /console
server weblogic1 192.168.10.11:7001 check inter 5000 fall 3 rise 2
server weblogic2 192.168.10.12:7001 check inter 5000 fall 3 rise 2
server weblogic3 192.168.10.13:7001 check inter 5000 fall 3 rise 2
sudo haproxy -c -f /etc/haproxy/haproxy.cfgsudo systemctl restart haproxy四 WebLogic 集群与部署要点
五 验证与运维建议
max_fails/fail_timeout 与 HAProxy 的 option httpchk 实现后端异常自动摘除与恢复,建议结合应用健康端点(如 /console 或自定义 /health)。