①实现了可弹性化的架构,在压力增大的时候可以临时添加tomcat服务器添加到这个架构里面去;
②upstream具有负载均衡能力,可以自动判断下面的机器,并且自动踢出不能正常提供服务的机器;而Keepalvied可保证单个nginx负载均衡器的有效性,避免单点故障.
nginx(主负载均衡器):192.168.1.106nginx(从负载均衡器):192.168.1.107VIP地址:192.168.1.108tomcat1的IP:192.168.1.102tomcat2的IP:192.168.1.103tomcat3的IP:192.168.1.105
- apache-tomcat-6.0.20.tar.gz
- jdk-6u16-linux-i586.bin
- nginx-0.7.17.tar.gz
- prce-7.7.tar.gz
①首先分别在3台tomcat主机上布置java环境,安装tomcat,具体步骤为: - JDK的安装
- #chmod +x jdk-6u16-linux-i586.bin
- #./jdk-6u16-linux-i586.bin
- 到此JDK已经安装完成
- 建立符号链接
- # ln -s /usr/local/jdk-1.6.0-16/bin/java /usr/bin/java
- # ln -s /usr/local/jdk-1.6.0-16/bin/javac /usr/bin/javac
- ln -s /usr/local/jdk-1.6.0-16 /usr/local/jdk
- ln -s /usr/local/jdk-1.6.0-16/jre /usr/local/jre
- TOMCAT的安装
- #tar zxvf apache-tomcat-6.0.20.tar.gz
- #mv apache-tomcat-6.0.20 /usr/local/tomcat
设置环境变量: vim /etc/rc.d/rc.local,以追加的形式添加如下内容
- JAVA_HOME=/usr/local/jdk
- export JAVA_HOME
- JRE_HOME=/usr/local/jre
- export JRE_HOME
- CLASSPATH=/usr/local/tomcat/common/lib/:/usr/local/jdk/lib:/usr/local/jre/lib
- export CLASSPATH
- PATH=$PATH:/usr/local/tomcat/bin/:/usr/local/apache/bin:/usr/local/jdk/bin:/usr/local/jre/bin
- export PATH
- TOMCAT_HOME=/usr/local/tomcat
- export TOMCAT_HOME
- 重启服务器,启动tomcat以检查是否存在错误:
- #cd /usr/local/tomcat/bin
- #./startup.sh
- http: 3.通过nbproc多设置几个haproxy并发进程,这样每个进程的task_queue相对就会短很多,性能自然就能提高不少
- #pidfile /var/run/haproxy-private.pid
- defaults
- log global
- mode http
- optionhttplog
- optiondontlognull
- log 127.0.0.1 local3
- retries 3
- option redispatch
- maxconn 2000
- contimeout 5000
- clitimeout 50000
- srvtimeout 50000
-
- listen webfarm 0.0.0.0:80
- mode http
- stats uri /haproxy-stats #监控haproxy状态
- stats realm Haproxy\ statistics
- stats auth netseek:52netseek#设置状态监控的用户名为netseek密码为52netseek
- balance roundrobin #负载均衡算法
- cookie SERVERID insert indirect
- option 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 5
- server app_bbs2 192.168.169.118:80 cookie app1inst2 check inter 2000 rise 2 fall 5
- syslog.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:
转载:http://navyaijm.blog.51cto.com/4647068/809391