Java web项目,怎么做负载均衡啊?
的有关信息介绍如下:HAProxy是一款反向代理服务器工具,通过它,可以实现负载均衡。它支持双机热备支持虚拟主机,但其配置简单,拥有非常不错的服务器健康检查功能,当其代理的后端服务器出现故障, HAProxy会自动将该服务器摘除,故障恢复后再自动将该服务器搏悔脊加入。新的1.3引入了frontend,backend,frontend根据任意HTTP请求头内容做规则匹配,然后把请求定向到相关的backend.利用HAPorxy实现负载均衡1. 利用HAProxy实现负载均衡192.168.169.137 (haproxy)———负载均衡———-(192.168.169.117;192.168.169.118)安装配置HAproxycd /usr/local/wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.14.2.tar.gztar zxvf haproxy-1.3.14.2.tar.gzmv haproxy-1.3.14.2 haproxycd haproxymake TARGET=linux262. 创建配置文件# vi haproxy.cfgglobalmaxconn 5120chroot /usr/local/haproxyuid 99gid 99daemonquietnbproc 2 #通过nbproc多设置几个haproxy并发基渗进程,这样每个进程的task_queue相对就会短很多,性能自然就能提高不少#pidfile /var/run/haproxy-private.piddefaultslog globalmode httpoption httplogoption dontlognulllog 127.0.0.1 local3retries 3option redispatchmaxconn 2000contimeout 5000clitimeout 50000srvtimeout 50000listen webfarm 0.0.0.0:80mode httpstats uri /haproxy-stats #监控haproxy状态stats realm Haproxy\ statisticsstats auth netseek:52netseek #设置状态监控的用户名为netseek密码为52netseekbalance roundrobin #负载均衡算法前派cookie SERVERID insert indirectoption httpclose #option forwardfor #apache日志转发功能option httpchk HEAD /check.txt HTTP/1.0 #健康检测server app_bbs1 192.168.169.117:80 cookie app1inst1 check inter 2000 rise 2 fall 5server app_bbs2 192.168.169.118:80 cookie app1inst2 check inter 2000 rise 2 fall 5syslog.conf里加一行local3.* /var/log/haproxy.log# touch /var/log/haproxy.log# chown haproxy:haproxy /var/log/haproxy.log# chmod u+x /var/log/haproxy.log# tail –f /var/log/harpoxy.log 监控日志# ./haproxy -f haproxy.cfg 启动服务.监控状态图示http://192.168.169.137/haproxy-stats ,输入用户名密码查看状态。后端apache日志处理配置httpd.confLogFormat “%{X-Forwarded-For}i %l %u %t \”%r\” %>s %b ” combinedCustomLog /var/log/httpd/access_log combined虚拟主机不记录检测日志:SetEnvIf Request_URI “^/check\.txt$” dontlogLogLevel warnErrorLog /var/log/httpd/vhost_error.logCustomLog /var/log/httpd/vhost_access.log combined env=!dontlog相关介绍#./haproxy –help //haproxy相关命令参数介绍.haproxy -f <配置文件> [-n 最大并发连接总数] [-N 每个侦听的最大并发数] [-d] [-D] [-q] [-V] [-c] [-p