利用Redis 对前端的Tomcat9 集群实现 non-sticky 模式的MSM。Redis 是C语言开发的一个开源高性能键值对的内存数据库,可以用来做数据库、缓存、消息中间件等场景,是一种NoSQL(not-only sql,非关系型数据库)的数据库。Redis集群技术非常成熟,其稳定性和可靠性也被普遍认可,相比 memcached ,它更多地被用于大型生产环境中。Redis一般都以集群的模式应用,但是本文仅以一台IP58主机模拟Redis集群的功能和作用,实现其对前端 Tomcat 集群的session 的cluster 持久性保障。并通过redis-cli 检测session的存放规律。
1. 架构拓扑及主机
IP
主机名
角色
软件
172.16.0.8
proxy8.shone.cn
反向代理调度
nginx
172.16.0.38
t38.shone.cn
Tomcat 主机38
JDK、Tomcat9
172.16.0.48
t48.shone.cn
Tomcat 主机48
JDK、Tomcatt9
172.16.0.58
Redis-IP58
Redos 主机58
Redis
环境准备:时间同步,确保NTP或Chrony服务正常运行。
禁用SELinux和防火墙(或放通需要的端口)
2. Nginx 反向代理服务器配置
简要说明:实际生产中可以用 Nginx 和 HAPROXY 最为反向代理,本实践中用NGINX来完成。
# 需要关闭防火墙、同时时钟等优化工作,再修改好规划好的主机名称等[root@nginx08 ]#hostnamectl set-hostname proxy8.shone.cn
[root@nginx08 ]#exit
[root@proxy8 ]#timedatectl set-timezone Asia/Shanghai
[root@proxy8 ]#sed -i 's/pool 2.centos.pool.ntp.org iburst/server ntp1.aliyun.com iburst/g' /etc/chrony.conf
# 按照规划修改好主机的DNS域名解析 (本次通过修改hosts文件来模拟)
[root@proxy8 ]#cat /etc/hosts
172.16.0.8 proxy8.shone.cn nginx08.shone.cn nginx08
172.16.0.38 t38.shone.cn t38
172.16.0.48 t48.shone.cn t48
[root@proxy8 ]#
# 配置nginx
[root@proxy8 ]#cat /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream tomcat-servers {
server t38.shone.cn:8080;
server t48.shone.cn:8080;
}
server {
location ~* \.(jsp|do)$ {
proxy_pass http://tomcat-servers;
}
}
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
[root@proxy8 ]#
[root@proxy8 ]#systemctl enable --now nginx
[root@proxy8 ]#systemctl restart nginx
[root@proxy8 ]#
3. Redis服务器配置
简要说明:实际生产中Redis一般都以集群的形成存在,本试验仅用一台redis 主机模拟其功能,实现tomcat 的session 缓存并持久保存在redis上。
# 配置redis 服务器[root@CentOS84-IP172-58 ]#hostnamectl set-hostname Redis-IP58
[root@CentOS84-IP172-58 ]#exit
[root@Redis-IP58 ]#dnf -y install redis
[root@Redis-IP58 ]#sed -i.bak 's/^bind.*/bind 0.0.0.0/' /etc/redis.conf
[root@Redis-IP58 ]#systemctl enable --now redis
[root@Redis-IP58 ]#ss -tln
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 511 0.0.0.0:6379 0.0.0.0:*
[root@Redis-IP58 ]#ss -tln
4. 配置后端两台Tomcat服务器
4.1 配置基础环境
4.1.1 主机 t38
#### t38 的配置过程[root@CentOS84-IP172-38 ]#hostnamectl set-hostname t38.shone.cn
[root@CentOS84-IP172-38 ]#exit
[root@t38 ]#timedatectl set-timezone Asia/Shanghai
[root@t38 ]#sed -i 's/pool 2.centos.pool.ntp.org iburst/server ntp1.aliyun.com iburst/g' /etc/chrony.conf
[root@t38 ]#systemctl enable --now chronyd.service
[root@t38 ]#systemctl restart chronyd.service
# 上传必须的软件包和一键安装脚本,快速完成基础环境的配置
[root@t38 ]#ll /data/
total 152840
-rw-r--r-- 1 root root 11560971 Apr 14 20:12 apache-tomcat-9.0.62.tar.gz
-rw-r--r-- 1 root root 3104 Apr 14 20:30 install_tomcat2022.sh
-rw-r--r-- 1 root root 144935989 Sep 1 2021 jdk-8u291-linux-x64.tar.gz
# 一键安装 JDK 和 tomcat 的脚本
[root@t38 ]#cat /data/install_tomcat2022.sh
DIR=`pwd`
JDK_FILE="jdk-8u321-linux-x64.tar.gz"
TOMCAT_FILE="apache-tomcat-9.0.62.tar.gz"
JDK_DIR="/usr/local"
TOMCAT_DIR="/usr/local"
color () {
RES_COL=60
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \E[0m"
echo -n "$2" && $MOVE_TO_COL
echo -n "["
if [ $1 = "success" -o $1 = "0" ] ;then
${SETCOLOR_SUCCESS}
echo -n $" OK "
elif [ $1 = "failure" -o $1 = "1" ] ;then
${SETCOLOR_FAILURE}
echo -n $"FAILED"
else
${SETCOLOR_WARNING}
echo -n $"WARNING"
fi
${SETCOLOR_NORMAL}
echo -n "]"
echo
}
install_jdk(){
if ! [ -f "$DIR/$JDK_FILE" ];then
color 1 "$JDK_FILE 文件不存在"
exit;
elif [ -d $JDK_DIR/jdk ];then
color 1 "JDK 已经安装"
exit
else
[ -d "$JDK_DIR" ] || mkdir -pv $JDK_DIR
fi
tar xvf $DIR/$JDK_FILE -C $JDK_DIR
cd $JDK_DIR && ln -s jdk* jdk
cat > /etc/profile.d/jdk.sh <<EOF
export JAVA_HOME=$JDK_DIR/jdk
export JRE_HOME=\$JAVA_HOME/jre
export CLASSPATH=\$JAVA_HOME/lib/:\$JRE_HOME/lib/
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
. /etc/profile.d/jdk.sh
java -version && color 0 "JDK 安装完成" || { color 1 "JDK 安装失败" ; exit; }
}
install_tomcat(){
if ! [ -f "$DIR/$TOMCAT_FILE" ];then
color 1 "$TOMCAT_FILE 文件不存在"
exit;
elif [ -d $TOMCAT_DIR/tomcat ];then
color 1 "TOMCAT 已经安装"
exit
else
[ -d "$TOMCAT_DIR" ] || mkdir -pv $TOMCAT_DIR
fi
tar xf $DIR/$TOMCAT_FILE -C $TOMCAT_DIR
cd $TOMCAT_DIR && ln -s apache-tomcat-*/ tomcat
echo "PATH=$TOMCAT_DIR/tomcat/bin:"'$PATH' > /etc/profile.d/tomcat.sh
id tomcat &> /dev/null || useradd -r -s /sbin/nologin tomcat
cat > $TOMCAT_DIR/tomcat/conf/tomcat.conf <<EOF
JAVA_HOME=$JDK_DIR/jdk
EOF
chown -R tomcat.tomcat $TOMCAT_DIR/tomcat/
cat > /lib/systemd/system/tomcat.service <<EOF
[Unit]
Description=Tomcat
#After=syslog.target network.target remote-fs.target nss-lookup.target
After=syslog.target network.target
[Service]
Type=forking
EnvironmentFile=$TOMCAT_DIR/tomcat/conf/tomcat.conf
ExecStart=$TOMCAT_DIR/tomcat/bin/startup.sh
ExecStop=$TOMCAT_DIR/tomcat/bin/shutdown.sh
RestartSec=3
PrivateTmp=true
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now tomcat.service &> /dev/null
systemctl is-active tomcat.service &> /dev/null && color 0 "TOMCAT 安装完成" || { color 1 "TOMCAT 安装失败" ; exit; }
}
install_jdk
install_tomcat
[root@t38 ]#
# 执行脚本完成安装
[root@t38 ]#bash install_tomcat2022.sh
4.1.2 主机 t48
#### T48 的配置过程[root@CentOS84-IP172-48 ]#hostnamectl set-hostname t48.shone.cn
[root@CentOS84-IP172-48 ]#exit
[root@t48 ]#timedatectl set-timezone Asia/Shanghai
[root@t48 ]#sed -i 's/pool 2.centos.pool.ntp.org iburst/server ntp1.aliyun.com iburst/g' /etc/chrony.conf
[root@t48 ]#systemctl enable --now chronyd.service
[root@t48 ]#systemctl restart chronyd.service
# 同t38 主机相同的方式准备好 t48 基础环境
[root@t48 ]#cd /data
[root@t48 ]#ll
total 152840
-rw-r--r-- 1 root root 11560971 Apr 14 20:12 apache-tomcat-9.0.62.tar.gz
-rw-r--r-- 1 root root 3104 Apr 14 20:30 install_tomcat2022.sh
-rw-r--r-- 1 root root 144935989 Sep 1 2021 jdk-8u291-linux-x64.tar.gz
[root@t48 ]#bash install_tomcat2022.sh
4.2 配置Tomcat
4.2.1 配置t38主机上的Tomcat
#### 修改tomcat 的 server.xml 配置文件;本实验是以基于域名的虚拟主机并自定义网页目录的方式来完成# 下面是修改后的 /usr/local/tomcat/conf/server.xml 文件的有限配置行,其中主要的就是定义了虚拟主机 t38.shone.cn 及相应的网页目录指向
[root@t38 ]#vim /usr/local/tomcat/conf/server.xml
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="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>
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="t38.shone.cn" jvmRoute="jvm38">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="t38.shone.cn" appBase="/data/webapps" unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
[root@t38 ]#
#######################################################################
# 修改 tomcat 的 context.xml 配置文件,定义了no sticky 模式的配置端
[root@t38 ]#cat /usr/local/tomcat/conf/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="redis://172.16.0.58:6379"
sticky="false"
sessionBackupAsync="false"
lockingMode="uriPattern:/path1|/path2"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>
[root@t38 ]#
#######################################################################
# 上传最新的jedis-4.2.2.jar,初始化可完成,但访问index.jsp报错,改成 jedis-3.0.0.jar低版本问题解决
[root@t38 ]#rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring jedis-3.0.0.jar...
100% 572 KB 572 KB/sec 00:00:01 0 Errors
# 上传后的全部jar包清单
[root@t38 ]#ll /usr/local/tomcat/lib/
total 11656
-rw-r----- 1 tomcat tomcat 13196 Mar 31 22:34 annotations-api.jar
-rw-r--r-- 1 tomcat tomcat 53259 Apr 15 17:49 asm-5.2.jar
-rw-r----- 1 tomcat tomcat 54063 Mar 31 22:34 catalina-ant.jar
-rw-r----- 1 tomcat tomcat 123877 Mar 31 22:34 catalina-ha.jar
-rw-r----- 1 tomcat tomcat 1724394 Mar 31 22:34 catalina.jar
-rw-r----- 1 tomcat tomcat 62796 Mar 31 22:34 catalina-ssi.jar
-rw-r----- 1 tomcat tomcat 78048 Mar 31 22:34 catalina-storeconfig.jar
-rw-r----- 1 tomcat tomcat 336956 Mar 31 22:34 catalina-tribes.jar
-rw-r----- 1 tomcat tomcat 3133846 Mar 31 22:34 ecj-4.20.jar
-rw-r----- 1 tomcat tomcat 88859 Mar 31 22:34 el-api.jar
-rw-r----- 1 tomcat tomcat 171510 Mar 31 22:34 jasper-el.jar
-rw-r----- 1 tomcat tomcat 567086 Mar 31 22:34 jasper.jar
-rw-r----- 1 tomcat tomcat 27124 Mar 31 22:34 jaspic-api.jar
-rw-r--r-- 1 root root 586620 Apr 15 19:48 jedis-3.0.0.jar
-rw-r----- 1 tomcat tomcat 63552 Mar 31 22:34 jsp-api.jar
-rw-r--r-- 1 tomcat tomcat 285211 Apr 15 17:39 kryo-3.0.3.jar
-rw-r--r-- 1 tomcat tomcat 126366 Apr 15 17:52 kryo-serializers-0.45.jar
-rw-r--r-- 1 tomcat tomcat 167294 Apr 15 18:33 memcached-session-manager-2.3.2.jar
-rw-r--r-- 1 tomcat tomcat 10967 Apr 15 17:44 memcached-session-manager-tc9-2.3.2.jar
-rw-r--r-- 1 tomcat tomcat 5923 Apr 15 17:49 minlog-1.3.1.jar
-rw-r--r-- 1 tomcat tomcat 38372 Apr 15 17:51 msm-kryo-serializer-2.3.2.jar
-rw-r--r-- 1 tomcat tomcat 55684 Apr 15 17:50 objenesis-2.6.jar
-rw-r--r-- 1 tomcat tomcat 72265 Apr 15 17:47 reflectasm-1.11.9.jar
-rw-r----- 1 tomcat tomcat 284302 Mar 31 22:34 servlet-api.jar
-rw-r--r-- 1 tomcat tomcat 473774 Apr 15 17:42 spymemcached-2.12.3.jar
-rw-r----- 1 tomcat tomcat 11515 Mar 31 22:34 tomcat-api.jar
-rw-r----- 1 tomcat tomcat 920076 Mar 31 22:34 tomcat-coyote.jar
-rw-r----- 1 tomcat tomcat 342429 Mar 31 22:34 tomcat-dbcp.jar
-rw-r----- 1 tomcat tomcat 69610 Mar 31 22:34 tomcat-i18n-cs.jar
-rw-r----- 1 tomcat tomcat 76715 Mar 31 22:34 tomcat-i18n-de.jar
-rw-r----- 1 tomcat tomcat 105212 Mar 31 22:34 tomcat-i18n-es.jar
-rw-r----- 1 tomcat tomcat 167316 Mar 31 22:34 tomcat-i18n-fr.jar
-rw-r----- 1 tomcat tomcat 190096 Mar 31 22:34 tomcat-i18n-ja.jar
-rw-r----- 1 tomcat tomcat 190781 Mar 31 22:34 tomcat-i18n-ko.jar
-rw-r----- 1 tomcat tomcat 52935 Mar 31 22:34 tomcat-i18n-pt-BR.jar
-rw-r----- 1 tomcat tomcat 50259 Mar 31 22:34 tomcat-i18n-ru.jar
-rw-r----- 1 tomcat tomcat 174502 Mar 31 22:34 tomcat-i18n-zh-CN.jar
-rw-r----- 1 tomcat tomcat 149543 Mar 31 22:34 tomcat-jdbc.jar
-rw-r----- 1 tomcat tomcat 36340 Mar 31 22:34 tomcat-jni.jar
-rw-r----- 1 tomcat tomcat 212754 Mar 31 22:34 tomcat-util.jar
-rw-r----- 1 tomcat tomcat 222925 Mar 31 22:34 tomcat-util-scan.jar
-rw-r----- 1 tomcat tomcat 241495 Mar 31 22:34 tomcat-websocket.jar
-rw-r----- 1 tomcat tomcat 39975 Mar 31 22:34 websocket-api.jar
# 确认下上传的文件的权属
[root@t38 ]#chown -R tomcat.tomcat /usr/local/tomcat/
# 创建自定义的主页目录、主页测试文件及授权
[root@t38 ]#mkdir -pv /data/webapps/ROOT
mkdir: created directory '/data/webapps'
mkdir: created directory '/data/webapps/ROOT'
[root@t38 ]#cd /data/webapps/ROOT/
[root@t38 ]#vim /data/webapps/ROOT/index.jsp
<%@ page import="java.util.*" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tomcat test</title>
</head>
<body>
<h1> Tomcat Website </h1>
<div>On <%=request.getServerName() %></div>
<div><%=request.getLocalAddr() + ":" + request.getLocalPort() %></div>
<div>SessionID = <span style="color:blue"><%=session.getId() %></span></div>
<%=new Date()%>
</body>
</html>
[root@t38 ]#chown -R tomcat.tomcat /data/webapps/
[root@t38 ]#
#######################################################################
# 重新启动tomcat服务
[root@t38 ]#systemctl restart tomcat
4.2.2 配置t48主机上的Tomcat
#### 和 t38 同样的思路修改好 t48的 /usr/local/tomcat/conf/server.xml 文件# 下面是配置好的完整的 /usr/local/tomcat/conf/server.xml文件信息
[root@t48 ]#cat /usr/local/tomcat/conf/server.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!-- APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="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>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443
This connector uses the NIO implementation. The default
SSLImplementation will depend on the presence of the APR/native
library and the useOpenSSL attribute of the AprLifecycleListener.
Either JSSE or OpenSSL style configuration may be used regardless of
the SSLImplementation selected. JSSE style configuration is used below.
-->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true">
<SSLHostConfig>
<Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
type="RSA" />
</SSLHostConfig>
</Connector>
-->
<!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
This connector uses the APR/native implementation which always uses
OpenSSL for TLS.
Either JSSE or OpenSSL style configuration may be used. OpenSSL style
configuration is used below.
-->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
maxThreads="150" SSLEnabled="true" >
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
<SSLHostConfig>
<Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
certificateFile="conf/localhost-rsa-cert.pem"
certificateChainFile="conf/localhost-rsa-chain.pem"
type="RSA" />
</SSLHostConfig>
</Connector>
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<!--
<Connector protocol="AJP/1.3"
address="::1"
port="8009"
redirectPort="8443" />
-->
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="t48.shone.cn" jvmRoute="jvm48">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="t48.shone.cn" appBase="/data/webapps" unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
#######################################################################
# 下面是配置并修改好后的 /usr/local/tomcat/conf/context.xml 文件
[root@t48 ]#cat /usr/local/tomcat/conf/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context>
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="redis://172.16.0.58:6379"
sticky="false"
sessionBackupAsync="false"
lockingMode="uriPattern:/path1|/path2"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>
[root@t48 ]#
#######################################################################
# 上传 jedis-3.0.0.jar 最终正常运行所有jar包的清单
[root@t48 ]#ll /usr/local/tomcat/lib/
total 11668
-rw-r----- 1 tomcat tomcat 13196 Mar 31 22:34 annotations-api.jar
-rw-r--r-- 1 root root 53259 Apr 15 17:49 asm-5.2.jar
-rw-r----- 1 tomcat tomcat 54063 Mar 31 22:34 catalina-ant.jar
-rw-r----- 1 tomcat tomcat 123877 Mar 31 22:34 catalina-ha.jar
-rw-r----- 1 tomcat tomcat 1724394 Mar 31 22:34 catalina.jar
-rw-r----- 1 tomcat tomcat 62796 Mar 31 22:34 catalina-ssi.jar
-rw-r----- 1 tomcat tomcat 78048 Mar 31 22:34 catalina-storeconfig.jar
-rw-r----- 1 tomcat tomcat 336956 Mar 31 22:34 catalina-tribes.jar
-rw-r----- 1 tomcat tomcat 3133846 Mar 31 22:34 ecj-4.20.jar
-rw-r----- 1 tomcat tomcat 88859 Mar 31 22:34 el-api.jar
-rw-r----- 1 tomcat tomcat 171510 Mar 31 22:34 jasper-el.jar
-rw-r----- 1 tomcat tomcat 567086 Mar 31 22:34 jasper.jar
-rw-r----- 1 tomcat tomcat 27124 Mar 31 22:34 jaspic-api.jar
-rw-r--r-- 1 root root 586620 Apr 15 19:48 jedis-3.0.0.jar
-rw-r----- 1 tomcat tomcat 63552 Mar 31 22:34 jsp-api.jar
-rw-r--r-- 1 root root 285211 Apr 15 17:39 kryo-3.0.3.jar
-rw-r--r-- 1 root root 126366 Apr 15 17:52 kryo-serializers-0.45.jar
-rw-r--r-- 1 root root 167294 Apr 15 18:33 memcached-session-manager-2.3.2.jar
-rw-r--r-- 1 root root 10826 Apr 15 19:37 memcached-session-manager-tc8-2.3.2.jar
-rw-r--r-- 1 root root 10967 Apr 15 17:44 memcached-session-manager-tc9-2.3.2.jar
-rw-r--r-- 1 root root 5923 Apr 15 17:49 minlog-1.3.1.jar
-rw-r--r-- 1 root root 38372 Apr 15 17:51 msm-kryo-serializer-2.3.2.jar
-rw-r--r-- 1 root root 55684 Apr 15 17:50 objenesis-2.6.jar
-rw-r--r-- 1 root root 72265 Apr 15 17:47 reflectasm-1.11.9.jar
-rw-r----- 1 tomcat tomcat 284302 Mar 31 22:34 servlet-api.jar
-rw-r--r-- 1 root root 473774 Apr 15 17:42 spymemcached-2.12.3.jar
-rw-r----- 1 tomcat tomcat 11515 Mar 31 22:34 tomcat-api.jar
-rw-r----- 1 tomcat tomcat 920076 Mar 31 22:34 tomcat-coyote.jar
-rw-r----- 1 tomcat tomcat 342429 Mar 31 22:34 tomcat-dbcp.jar
-rw-r----- 1 tomcat tomcat 69610 Mar 31 22:34 tomcat-i18n-cs.jar
-rw-r----- 1 tomcat tomcat 76715 Mar 31 22:34 tomcat-i18n-de.jar
-rw-r----- 1 tomcat tomcat 105212 Mar 31 22:34 tomcat-i18n-es.jar
-rw-r----- 1 tomcat tomcat 167316 Mar 31 22:34 tomcat-i18n-fr.jar
-rw-r----- 1 tomcat tomcat 190096 Mar 31 22:34 tomcat-i18n-ja.jar
-rw-r----- 1 tomcat tomcat 190781 Mar 31 22:34 tomcat-i18n-ko.jar
-rw-r----- 1 tomcat tomcat 52935 Mar 31 22:34 tomcat-i18n-pt-BR.jar
-rw-r----- 1 tomcat tomcat 50259 Mar 31 22:34 tomcat-i18n-ru.jar
-rw-r----- 1 tomcat tomcat 174502 Mar 31 22:34 tomcat-i18n-zh-CN.jar
-rw-r----- 1 tomcat tomcat 149543 Mar 31 22:34 tomcat-jdbc.jar
-rw-r----- 1 tomcat tomcat 36340 Mar 31 22:34 tomcat-jni.jar
-rw-r----- 1 tomcat tomcat 212754 Mar 31 22:34 tomcat-util.jar
-rw-r----- 1 tomcat tomcat 222925 Mar 31 22:34 tomcat-util-scan.jar
-rw-r----- 1 tomcat tomcat 241495 Mar 31 22:34 tomcat-websocket.jar
-rw-r----- 1 tomcat tomcat 39975 Mar 31 22:34 websocket-api.jar
[root@t48 ]#
#######################################################################
# 创建自定义的网页目录及测试主页
[root@t48 ]#mkdir -pv /data/webapps/ROOT
mkdir: created directory '/data/webapps'
mkdir: created directory '/data/webapps/ROOT'
[root@t48 ]#cd /data/webapps/ROOT/
[root@t48 ]#rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring index.jsp...
100% 397 bytes 397 bytes/sec 00:00:01 0 Errors
[root@t48 ]#cat /data/webapps/ROOT/index.jsp
<%@ page import="java.util.*" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tomcat test</title>
</head>
<body>
<h1> Tomcat Website </h1>
<div>On <%=request.getServerName() %></div>
<div><%=request.getLocalAddr() + ":" + request.getLocalPort() %></div>
<div>SessionID = <span style="color:blue"><%=session.getId() %></span></div>
<%=new Date()%>
</body>
</html>
[root@t48 ]#chown -R tomcat.tomcat /data/webapps/
[root@t48 ]#
#######################################################################
[root@t48 ]#systemctl restart tomcat
5. 查看日志验证配置成功
#### t38 主机#######################################################################
# 成功运行后看到的日志信息
[root@t38 ]#tail -f /usr/local/tomcat/logs/catalina.out
17-Apr-2022 01:06:50.186 INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance.
17-Apr-2022 01:06:50.187 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8080"]
17-Apr-2022 01:06:50.192 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]
17-Apr-2022 01:06:50.196 INFO [main] de.javakaffee.web.msm.MemcachedSessionService.shutdown Stopping services.
17-Apr-2022 01:06:51.233 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.62
17-Apr-2022 01:06:51.236 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Mar 31 2022 14:34:15 UTC
17-Apr-2022 01:06:51.236 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.62.0
17-Apr-2022 01:06:51.236 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
17-Apr-2022 01:06:51.236 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 4.18.0-305.3.1.el8.x86_64
17-Apr-2022 01:06:51.237 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
17-Apr-2022 01:06:51.237 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/local/jdk1.8.0_321/jre
17-Apr-2022 01:06:51.237 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_321-b07
17-Apr-2022 01:06:51.237 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
17-Apr-2022 01:06:51.237 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/apache-tomcat-9.0.62
17-Apr-2022 01:06:51.237 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/apache-tomcat-9.0.62
17-Apr-2022 01:06:51.239 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
17-Apr-2022 01:06:51.239 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
17-Apr-2022 01:06:51.239 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
17-Apr-2022 01:06:51.240 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
17-Apr-2022 01:06:51.240 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
17-Apr-2022 01:06:51.240 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
17-Apr-2022 01:06:51.240 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
17-Apr-2022 01:06:51.240 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
17-Apr-2022 01:06:51.240 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
17-Apr-2022 01:06:51.242 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
17-Apr-2022 01:06:51.682 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
17-Apr-2022 01:06:51.707 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [710] milliseconds
17-Apr-2022 01:06:51.737 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
17-Apr-2022 01:06:51.737 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.62]
17-Apr-2022 01:06:51.744 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/data/webapps/ROOT]
17-Apr-2022 01:06:52.133 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
17-Apr-2022 01:06:52.162 INFO [main] de.javakaffee.web.msm.MemcachedSessionService.startInternal starts initialization... (configured nodes definition redis://172.16.0.58:6379, failover nodes null)
17-Apr-2022 01:06:52.172 INFO [main] de.javakaffee.web.msm.RequestTrackingHostValve.<init> Setting ignorePattern to .*\.(ico|png|gif|jpg|css|js)$
17-Apr-2022 01:06:52.180 INFO [main] de.javakaffee.web.msm.MemcachedSessionService.setLockingMode Setting lockingMode to URI_PATTERN with pattern /path1|/path2
17-Apr-2022 01:06:52.184 INFO [main] de.javakaffee.web.msm.MemcachedSessionService.createTranscoderFactory Creating transcoder factory de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory
17-Apr-2022 01:06:52.190 INFO [main] de.javakaffee.web.msm.serializer.kryo.KryoTranscoder.<init> Starting with initialBufferSize 102400, maxBufferSize 2048000 and defaultSerializerFactory de.javakaffee.web.msm.serializer.kryo.DefaultFieldSerializerFactory
17-Apr-2022 01:06:52.195 INFO [main] de.javakaffee.web.msm.MemcachedSessionService.startInternal --------
- finished initialization:
- sticky: false
- operation timeout: 1000
- node ids: []
- failover node ids: []
- storage key prefix: null
- locking mode: uriPattern:/path1|/path2 (expiration: 5s)
--------
17-Apr-2022 01:06:52.226 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/data/webapps/ROOT] has finished in [481] ms
17-Apr-2022 01:06:52.229 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
17-Apr-2022 01:06:52.261 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [553] milliseconds#### t48 主机
#######################################################################
# 成功运行后看到的日志信息
[root@t48 ]#tail -f /usr/local/tomcat/logs/catalina.out
17-Apr-2022 01:00:15.544 INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance.
17-Apr-2022 01:00:15.546 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8080"]
17-Apr-2022 01:00:15.549 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]
17-Apr-2022 01:00:15.552 INFO [main] de.javakaffee.web.msm.MemcachedSessionService.shutdown Stopping services.
17-Apr-2022 01:00:15.662 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
17-Apr-2022 01:00:16.729 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.62
17-Apr-2022 01:00:16.732 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Mar 31 2022 14:34:15 UTC
17-Apr-2022 01:00:16.732 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.62.0
17-Apr-2022 01:00:16.732 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
17-Apr-2022 01:00:16.732 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 4.18.0-305.3.1.el8.x86_64
17-Apr-2022 01:00:16.732 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
17-Apr-2022 01:00:16.732 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/local/jdk1.8.0_291/jre
17-Apr-2022 01:00:16.732 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_291-b10
17-Apr-2022 01:00:16.733 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
17-Apr-2022 01:00:16.733 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/apache-tomcat-9.0.62
17-Apr-2022 01:00:16.733 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/apache-tomcat-9.0.62
17-Apr-2022 01:00:16.735 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
17-Apr-2022 01:00:16.735 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
17-Apr-2022 01:00:16.735 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
17-Apr-2022 01:00:16.735 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
17-Apr-2022 01:00:16.735 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
17-Apr-2022 01:00:16.735 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
17-Apr-2022 01:00:16.735 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
17-Apr-2022 01:00:16.735 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
17-Apr-2022 01:00:16.736 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
17-Apr-2022 01:00:16.737 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
17-Apr-2022 01:00:17.157 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
17-Apr-2022 01:00:17.180 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [735] milliseconds
17-Apr-2022 01:00:17.207 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
17-Apr-2022 01:00:17.207 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.62]
17-Apr-2022 01:00:17.214 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/data/webapps/ROOT]
17-Apr-2022 01:00:17.588 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
17-Apr-2022 01:00:17.617 INFO [main] de.javakaffee.web.msm.MemcachedSessionService.startInternal starts initialization... (configured nodes definition redis://172.16.0.58:6379, failover nodes null)
17-Apr-2022 01:00:17.626 INFO [main] de.javakaffee.web.msm.RequestTrackingHostValve.<init> Setting ignorePattern to .*\.(ico|png|gif|jpg|css|js)$
17-Apr-2022 01:00:17.634 INFO [main] de.javakaffee.web.msm.MemcachedSessionService.setLockingMode Setting lockingMode to URI_PATTERN with pattern /path1|/path2
17-Apr-2022 01:00:17.638 INFO [main] de.javakaffee.web.msm.MemcachedSessionService.createTranscoderFactory Creating transcoder factory de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory
17-Apr-2022 01:00:17.655 INFO [main] de.javakaffee.web.msm.serializer.kryo.KryoTranscoder.<init> Starting with initialBufferSize 102400, maxBufferSize 2048000 and defaultSerializerFactory de.javakaffee.web.msm.serializer.kryo.DefaultFieldSerializerFactory
17-Apr-2022 01:00:17.661 INFO [main] de.javakaffee.web.msm.MemcachedSessionService.startInternal --------
- finished initialization:
- sticky: false
- operation timeout: 1000
- node ids: []
- failover node ids: []
- storage key prefix: null
- locking mode: uriPattern:/path1|/path2 (expiration: 5s)
--------
17-Apr-2022 01:00:17.679 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/data/webapps/ROOT] has finished in [464] ms
17-Apr-2022 01:00:17.682 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
17-Apr-2022 01:00:17.694 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [514] milliseconds
6. 访问验证
6.1 正常状态
在客户端浏览器刷新访问多次,主机轮询,但SessionID不变。
6.2 模拟故障
停掉tomcat 的服务,因为session 存放在后端的redis上,所以session 保持不变的,只是轮询访问被调度到一台tomcat上了。因为本次实验后端仅有一台redis主机,停掉会发现浏览器上的session不停变化,这个是因为没地方保存和保持session ,每次都会是一次全新的访问 ,所以体现出来的就是前端的session不停变化。
# 停掉 48 上的tomcat 模拟故障,刷新浏览器页面的session没发生变化。[root@t48 ]#systemctl stop tomcat
[root@t48 ]#
# 因为本次后端redis 只有一台没用集群,所以停掉redis服务后前端的session无法保存了,就不停在变化了
6.3 redis端信息
[root@Redis-IP58 ]#redis-cli127.0.0.1:6379> keys *
1) "CB83B6DCDD3A4596B4CE2FCE00488C43.jvm48"
2) "5B1BE42D7C6C59AEB509C1BD9B1FD688.jvm38"
3) "validity:5B1BE42D7C6C59AEB509C1BD9B1FD688.jvm38"
4) "validity:CB83B6DCDD3A4596B4CE2FCE00488C43.jvm48"
5) "validity:15F7B2EE10F38F5A62CF1993F67F6928.jvm48"
6) "15F7B2EE10F38F5A62CF1993F67F6928.jvm48"
127.0.0.1:6379>
127.0.0.1:6379> get "5B1BE42D7C6C59AEB509C1BD9B1FD688.jvm38"
"\x00\x02\x00Z\x00\x00\x01\x803^\xb8\x87\x00\x00\x01\x803^\xb8\x87\x00\x00\a\b11\x00\x00\x01\x803^\xb8\x87\x00\x00\x01\x803^\xb8\x88\x00&5B1BE42D7C6C59AEB509C1BD9B1FD688.jvm38\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00"
127.0.0.1:6379>