龙空技术网

tomcat集群和session共享

爱音乐的程序员小新人 747

前言:

此时大家对“tomcatlocalhost拒绝了我们的连接请求”大约比较注意,小伙伴们都想要知道一些“tomcatlocalhost拒绝了我们的连接请求”的相关资讯。那么小编同时在网摘上汇集了一些对于“tomcatlocalhost拒绝了我们的连接请求””的相关文章,希望各位老铁们能喜欢,看官们一起来学习一下吧!

1.集群

生成发布包 项目右键export生成war包再解压一个tomcat 把war包放入第二个tomcat,wabapps中,设置端口号,根目录conf的server.xml中

再修改第二个startup.bat增加两行代码

写在最上方

SET JAVA_HOME=D:\java //指定jdk安装的路径根路径,不用进入bin文件夹中

SET CATALINA_HOME=D:\apache-tomcat-7.0.67 //指定第二个tomcat根路径

123启动nginx 根目录下conf下的nginx.conf

server {

listen 80;

server_name localhost;//表示进入端口自动寻找localtion

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root html;//默认的localtion地址

index index.html index.htm;//这个地址下有哪些页面可以访问

//添加proxy_pass

proxy_pass ;

}

12345678910111213141516在当前conf文件中添加upstream

upstream server_list{

server localhost:8080;//添加所有的tomcat访问地址

server localhost:8081;

}

1234

示例如下:

http {

limit_conn_log_level error;

limit_conn_status 503;

limit_conn_zone $binary_remote_addr zone=one:10m;

limit_conn_zone $server_name zone=perserver:10m;

limit_req_zone binary

r

emote

a

ddrzone=allips:100mrate=10r/s;其中

binaryremoteaddrzone=allips:100mrate=10r/s;其中binary_remote_addr有时需要根据自己已有的log_format变量配置进行替换

server {

…………………….

limit_conn one 100;

1234

limit_conn perserver 1000;

limit_req zone=allips burst=5 nodelay;

………………….

1234

}

}

参数解释:

Zone=one或allips 表示设置了名为“one”或“allips”的存储区,大小为10兆字节

rate=10r/s 的意思是允许1秒钟不超过10个请求

burst=5 表示最大延迟请求数量不大于5。 如果太过多的请求被限制延迟是不需要的 ,这时需要使用nodelay参数,服务器会立刻返回503状态码。

limit_conn one 100表示最大并发连接数100

limit_conn perserver 1000表示该服务提供的总连接数不得超过1000,超过请求的会被拒绝

2.启动nginx

解压nginx压缩包命令行敲代码

3.配置tomcat

多个Tomcat同步Session

分别修改tomcat的server.xml配置文件

为元素指定jvmRoute属性名,名称保持一致

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

1释放开元素注释

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

1在项目project的web.xml中配置< distributable/>元素

nginx+tomcat+redis完成session共享

安装redis、tomcat、nginx

session同步配置

下载jar包,放入到tomcat/lib目录下

tomcat-redis-session-manager-1.2-tomcat-7-java-7.jar

jedis-2.5.2.jar

commons-pool2-2.0.jar

修改tomcat中context.xml文件

<Context>

<!-- Default set of monitored resources -->

<WatchedResource>WEB-INF/web.xml</WatchedResource>

<!-- Uncomment this to disable session persistence across Tomcat restarts -->

<!--

<Manager pathname="" />

-->

<!-- Uncomment this to enable Comet connection tacking (provides events

on session expiration as well as webapp lifecycle) -->

<!--

<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />

-->

<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />

<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"

host="10.10.49.20"

port="6379"

database="0"

maxInactiveInterval="60" />

</Context>

标签: #tomcatlocalhost拒绝了我们的连接请求 #nginx配置文件同步 #tomcat集群session共享问题