一、nginx 负载均衡配置
一、 nginx 负载均衡配置
修改 nginx 的配置文件,重点内容如下:
http {
include /etc/nginx/conf.d/*.conf;
upstream iivey {
server 172.16.213.232:8080 weight=1;
server 172.16.213.233:8080 weight=1;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://iivey;
}
}
二、tomcat的安装和配置
1、下载
wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.79/bin/apache-tomcat-7 .0.79.tar.gz
2、安装
安装好 jdk,然后解压tomcat安装包到任意目录,解压即可。
3、配置 tomcat
1) 先给出正确的配置和 jar包 所需 jar 包如下
tomcat-redis-session-manager1.2.jar
jedis-2.6.2.jar
tomcat-juli.jar
tomcat-juli-adapters.jar
commons-pool-1.5.4.jar
commons-pool2-2.4.1.jar
接着,修改 tomcat 的配置文件conf/context.xml,单点 redis配置如下:
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<ValveclassName="com.orangefunction.tomcat.redissessions.RedisSessionHandle rValve"/>
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="172.16.213.234" ##注释redis 的 主机
port="6379"
database="0"
maxInactiveInterval="60"/>
</Context>
基于 redis 的集群配置如下:
<ValveclassName="com.orangefunction.tomcat.redissessions.RedisSessionHandle rValve"/>
<ManagerclassName="com.orangefunction.tomcat.redissessions.RedisSessionMa nager"
maxInactiveInterval="60"
sentinelMaster="mymaster"
sentinels="127.0.0.1:26379,127.0.0.1:26380,127.0.0.1:26381,127.0.0.1:26382"/>
最后,添加一个 tomcat 测试页index.jsp:
cat /usr/local/tomcat/webapps/ROOT/index.jsp
<html>
<head>
<title>nginx tomcat session test </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<h1>tomcat232</h1> session: <%=session.getId()%>
</body>
</html>
4、启动 tomcat
/usr/local/tomcat/bin/startup.sh
三、各个组件下载
Redis:http://redis.io/
JRedis: https://github.com/xetorthio/jedis
这 里 使 用 的 是 tomcat7 和 JDK7 , 因 此 下 载 tomcat-redis-session-manager-1.2-tomcat-7-Java-7.jar 包 https://github.com/jcoleman/tomcat-redis-session-manager/downloads
Apache Commons Pool : http://commons.apache.org/proper/commons-pool/download_pool.cgi
7,tomcat 集群+redis 单机+nginx 单机 实现 session 共享
原文:https://www.cnblogs.com/k8s-pod/p/13747235.html