1.安装配置tomcat
修改tomcat端口号,在server.conf文件中配置
<Serverport="8015"shutdown="SHUTDOWN"><!--这里需要修改tomcat的关闭端口 默认是8005-->
<ListenerclassName="org.apache.catalina.startup.VersionLoggerListener" />
<ListenerclassName="org.apache.catalina.core.JasperListener" />
<ListenerclassName="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<ListenerclassName="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<ListenerclassName="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resourcename="UserDatabase"auth="Container"type="org.apache.catalina.UserDatabase"description="User database that can be updated and saved"factory="org.apache.catalina.users.MemoryUserDatabaseFactory"pathname="conf/tomcat-users.xml" />
</GlobalNamingResources><Servicename="Catalina"><!--这里需要修改tomcat的访问端口 默认是8080-->
<Connectorport="8081"protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" />
<!--这里需要修改tomcat的代理端口 8443不用更改--><Connectorport="7009"protocol="AJP/1.3"redirectPort="8443" />
将两个tomcat关闭后修改,启动后访问不同的tomcat
2.nginx的安装配置
进行nginx的安装,nginx的配置有5种方式
序号 方式名称 方式说明(1 2 3实践测试过)
1 轮询
默认配置
upstream xsdemo{
server ip:8081;
server ip:8082;
}
2 weight(权重)
正向代理 设置权重
upstream xsdemo{
server ip:8081 weight=10;
server ip:8082 weight=10;
}
3 ip_hash
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session(并不是共享session解决)的问题。
upstream xsdemo{
ip_hash;
server ip:8081 weight=10;
server ip:8082 weight=10;
}
4 fair 按后端服务器的响应时间来分配请求,响应时间短的优先分配
5 url_hash 按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有效
修改nginx.conf配置文件
upstream xsDemo {
server ip:8081;
server 192.168.110.128:8082;ip
}
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
proxy_pass http://xsDemo;
}
3.
redis和session的共享
redis正常安装即可,并设置密码(还是比较重要的,现在挖矿病毒挺多的,防止中招),允许任意地址登录
# requirepass foobared
foobared 为你要设置的密码去掉注释
bind 127.0.0.1 修改为 bind 0.0.0.0
添加tomcat-redis-session-manager、commons-pool、jedis三个jar到tomcta的lib文件夹,注意版本号,防止jar冲突
修改tomcat/conf/context.xml文件
<?xml version='1.0' encoding='utf-8'?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<ValveclassName="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<ManagerclassName="com.orangefunction.tomcat.redissessions.RedisSessionManager"host="ip"port="redis端口号"password="redis密码" 如果设置了密码则在这里配置上
database="0"redis默认16个database 第一个是0 最后一个是15maxInactiveInterval="60" />
</Context>
重新启动tomcat,刷新工程即可