Nginx均衡器配置

vim /usr/local/nginx/nginx.conf
1.在server节点上面增加以下节点:
[quote]upstream backend{
ip_hash;
server 192.168.73.206:8080;
server 192.168.73.207:8080;
}[/quote]
2.找到:
[quote]location / {
root html;
index index.html index.htm;
} [/quote]
改成:
[quote]location / {
proxy_pass http://backend;
proxy_redirect default;
proxy_connect_timeout 10;
}[/quote]
3.找到:
[quote]server {
listen 80;
server_name localhost;[/quote]
改成:
[quote]server {
listen 80;
server_name 192.168.73.208;[/quote]

另外:
1.如果要查看Nginx的调试级日志,需要在编译时加上--with-debug选项,然后再在配置文件中指定日志级别。
./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.21 \
--with-zlib=/usr/local/src/zlib-1.2.8 \
--with-openssl=/usr/local/src/openssl-1.0.1c \
--with-debug

可以使用 debug_connection 指令只调试某些连接。

2.ip_hash均衡算法,只针对IP地址的前三段进行hash,所以在局域网中因为IP前三段都是一样的,所以都转发到同一台Tomcat。
[quote] The first three octets of the client IPv4 address, or the entire IPv6 address, are used as a hashing key. [/quote]

3.关于jvmRoute
http://tomcat.apache.org/tomcat-5.5-doc/config/engine.html
[quote]Identifier which must be used in load balancing scenarios to enable session affinity. The identifier, which must be unique across all Tomcat 5 servers which participate in the cluster, will be appended to the generated session identifier, therefore allowing the front end proxy to always forward a particular session to the same Tomcat 5 instance.[/quote]
http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html
[quote]If you are using mod_jk, make sure that jvmRoute attribute is set at your Engine <Engine name="Catalina" jvmRoute="node01" > and that the jvmRoute attribute value matches your worker name in workers.properties[/quote]
jvmRoute应该是Tomcat使用mod_jk与Apache集成实现粘性会话(sticky session)而出现的,它通过在session id中添加tomcat的jvmRoute来实现粘性会话。
Nginx也有类似的实现方式,如:
https://code.google.com/p/nginx-upstream-jvm-route/
在Nginx中如果使用ip_hash均衡算法,则不需要在Tomcat中配置jvmRoute。
其它算法还有(使用Cookie来实现粘性会话):
https://code.google.com/p/nginx-sticky-module/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值