{"id":1742,"date":"2021-10-12T17:57:13","date_gmt":"2021-10-13T00:57:13","guid":{"rendered":"https:\/\/www.xh86.me\/?p=1742"},"modified":"2021-10-12T17:57:13","modified_gmt":"2021-10-13T00:57:13","slug":"tomcatnginxredismysql%e5%ae%9e%e7%8e%b0%e5%8f%8d%e5%90%91%e4%bb%a3%e7%90%86%e3%80%81%e8%b4%9f%e8%bd%bd%e5%9d%87%e8%a1%a1%e3%80%81session%e5%85%b1%e4%ba%ab","status":"publish","type":"post","link":"https:\/\/www.xh86.me\/?p=1742","title":{"rendered":"Tomcat+Nginx+Redis+MySQL\u5b9e\u73b0\u53cd\u5411\u4ee3\u7406\u3001\u8d1f\u8f7d\u5747\u8861\u3001session\u5171\u4eab"},"content":{"rendered":"<h3>\u4e00\u3001\u73af\u5883\u51c6\u5907<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"137\" class=\"wp-image-1743\" src=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/text-calendar-description-automatically-generate.png\" alt=\"Text, calendar\n\nDescription automatically generated\" srcset=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/text-calendar-description-automatically-generate.png 940w, https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/text-calendar-description-automatically-generate-300x44.png 300w, https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/text-calendar-description-automatically-generate-768x112.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/p>\n<p>\u65f6\u95f4\u540c\u6b65<\/p>\n<p>\u5173\u95ed\u9632\u706b\u5899<\/p>\n<h3>\u4e8c\u3001\u5b89\u88c5nginx<\/h3>\n<p><strong>1\u3001\u89e3\u51b3\u4f9d\u8d56\u5173\u7cfb<\/strong><\/p>\n<p>[root@nginx-server ~]#\u00a0yum install gcc openssl-devel pcre-devel zlib-devel -y<\/p>\n<p><strong>2\u3001\u6dfb\u52a0\u7528\u6237nginx\uff0c\u5b9e\u73b0\u4ee5\u4e4b\u8fd0\u884cnginx\u670d\u52a1\u8fdb\u7a0b<\/strong><\/p>\n<p>[root@nginx-server ~]# groupadd -r nginx<\/p>\n<p>[root@nginx-server ~]# useradd -r -g nginx -s \/bin\/false -M nginx<\/p>\n<p><strong>3.\u3001\u4e0b\u8f7dnginx\u8f6f\u4ef6\uff0c\u5e76\u7f16\u8bd1\u5b89\u88c5<\/strong><\/p>\n<p>[root@nginx-server ~]# wget http:\/\/nginx.org\/download\/nginx-1.6.3.tar.gz<\/p>\n<p>[root@nginx-server ~]# tar xf nginx-1.6.3.tar.gz<\/p>\n<p>[root@nginx-server ~]# cd nginx-1.6.3<\/p>\n<p>[root@nginx-server nginx-1.6.3]#.\/configure \\<\/p>\n<p>&#8211;prefix=\/usr\/local\/nginx \\<\/p>\n<p>&#8211;sbin-path=\/usr\/local\/nginx\/sbin\/nginx \\<\/p>\n<p>&#8211;conf-path=\/etc\/nginx\/nginx.conf \\<\/p>\n<p>&#8211;error-log-path=\/var\/log\/nginx\/error.log \\<\/p>\n<p>&#8211;http-log-path=\/var\/log\/nginx\/access.log \\<\/p>\n<p>&#8211;pid-path=\/var\/run\/nginx\/nginx.pid \\<\/p>\n<p>&#8211;lock-path=\/var\/lock\/nginx.lock \\<\/p>\n<p>&#8211;user=nginx \\<\/p>\n<p>&#8211;group=nginx \\<\/p>\n<p>&#8211;with-http_ssl_module \\<\/p>\n<p>&#8211;with-http_flv_module \\<\/p>\n<p>&#8211;with-http_stub_status_module \\<\/p>\n<p>&#8211;with-http_gzip_static_module \\<\/p>\n<p>&#8211;http-client-body-temp-path=\/var\/tmp\/nginx\/client\/ \\<\/p>\n<p>&#8211;http-proxy-temp-path=\/var\/tmp\/nginx\/proxy\/ \\<\/p>\n<p>&#8211;http-fastcgi-temp-path=\/var\/tmp\/nginx\/fcgi\/ \\<\/p>\n<p>&#8211;http-uwsgi-temp-path=\/var\/tmp\/nginx\/uwsgi \\<\/p>\n<p>&#8211;http-scgi-temp-path=\/var\/tmp\/nginx\/scgi \\<\/p>\n<p>&#8211;with-pcre<\/p>\n<p>[root@nginx-server nginx-1.6.3]# make &amp;&amp; make install<\/p>\n<p><strong>4.\u4e3anginx\u63d0\u4f9bSysV init\u811a\u672c<\/strong><\/p>\n<p>[root@nginx-server ~]# vim \/etc\/rc.d\/init.d\/nginx<\/p>\n<p>#!\/bin\/sh<\/p>\n<p>#<\/p>\n<p># nginx &#8211; this script starts and stops the nginx daemon<\/p>\n<p>#<\/p>\n<p># chkconfig: &#8211; 85 15<\/p>\n<p># description: Nginx is an HTTP(S) server, HTTP(S) reverse \\<\/p>\n<p># proxy and IMAP\/POP3 proxy server<\/p>\n<p># processname: nginx<\/p>\n<p># config: \/etc\/nginx\/nginx.conf<\/p>\n<p># config: \/etc\/sysconfig\/nginx<\/p>\n<p># pidfile: \/var\/run\/nginx.pid<\/p>\n<p>&nbsp;<\/p>\n<p># Source function library.<\/p>\n<p>. \/etc\/rc.d\/init.d\/functions<\/p>\n<p>&nbsp;<\/p>\n<p># Source networking configuration.<\/p>\n<p>. \/etc\/sysconfig\/network<\/p>\n<p>&nbsp;<\/p>\n<p># Check that networking is up.<\/p>\n<p>[ &#8220;$NETWORKING&#8221; = &#8220;no&#8221; ] &amp;&amp; exit 0<\/p>\n<p>&nbsp;<\/p>\n<p>nginx=&#8221;\/usr\/sbin\/nginx&#8221;<\/p>\n<p>prog=$(basename $nginx)<\/p>\n<p>&nbsp;<\/p>\n<p>NGINX_CONF_FILE=&#8221;\/etc\/nginx\/nginx.conf&#8221;<\/p>\n<p>&nbsp;<\/p>\n<p>[ -f \/etc\/sysconfig\/nginx ] &amp;&amp; . \/etc\/sysconfig\/nginx<\/p>\n<p>&nbsp;<\/p>\n<p>lockfile=\/var\/lock\/subsys\/nginx<\/p>\n<p>&nbsp;<\/p>\n<p>make_dirs() {<\/p>\n<p># make required directories<\/p>\n<p>user=`nginx -V 2&gt;&amp;1 | grep &#8220;configure arguments:&#8221; | sed &#8216;s\/[^*]*&#8211;user=\\([^ ]*\\).*\/\\1\/g&#8217; -`<\/p>\n<p>options=`$nginx -V 2&gt;&amp;1 | grep &#8216;configure arguments:&#8217;`<\/p>\n<p>for opt in $options; do<\/p>\n<p>if [ `echo $opt | grep &#8216;.*-temp-path&#8217;` ]; then<\/p>\n<p>value=`echo $opt | cut -d &#8220;=&#8221; -f 2`<\/p>\n<p>if [ ! -d &#8220;$value&#8221; ]; then<\/p>\n<p># echo &#8220;creating&#8221; $value<\/p>\n<p>mkdir -p $value &amp;&amp; chown -R $user $value<\/p>\n<p>fi<\/p>\n<p>fi<\/p>\n<p>done<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>start() {<\/p>\n<p>[ -x $nginx ] || exit 5<\/p>\n<p>[ -f $NGINX_CONF_FILE ] || exit 6<\/p>\n<p>make_dirs<\/p>\n<p>echo -n $&#8221;Starting $prog: &#8221;<\/p>\n<p>daemon $nginx -c $NGINX_CONF_FILE<\/p>\n<p>retval=$?<\/p>\n<p>echo<\/p>\n<p>[ $retval -eq 0 ] &amp;&amp; touch $lockfile<\/p>\n<p>return $retval<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>stop() {<\/p>\n<p>echo -n $&#8221;Stopping $prog: &#8221;<\/p>\n<p>killproc $prog -QUIT<\/p>\n<p>retval=$?<\/p>\n<p>echo<\/p>\n<p>[ $retval -eq 0 ] &amp;&amp; rm -f $lockfile<\/p>\n<p>return $retval<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>restart() {<\/p>\n<p>configtest || return $?<\/p>\n<p>stop<\/p>\n<p>sleep 1<\/p>\n<p>start<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>reload() {<\/p>\n<p>configtest || return $?<\/p>\n<p>echo -n $&#8221;Reloading $prog: &#8221;<\/p>\n<p>killproc $nginx -HUP<\/p>\n<p>RETVAL=$?<\/p>\n<p>echo<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>force_reload() {<\/p>\n<p>restart<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>configtest() {<\/p>\n<p>$nginx -t -c $NGINX_CONF_FILE<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>rh_status() {<\/p>\n<p>status $prog<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>rh_status_q() {<\/p>\n<p>rh_status &gt;\/dev\/null 2&gt;&amp;1<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>case &#8220;$1&#8243; in<\/p>\n<p>start)<\/p>\n<p>rh_status_q &amp;&amp; exit 0<\/p>\n<p>$1<\/p>\n<p>;;<\/p>\n<p>stop)<\/p>\n<p>rh_status_q || exit 0<\/p>\n<p>$1<\/p>\n<p>;;<\/p>\n<p>restart|configtest)<\/p>\n<p>$1<\/p>\n<p>;;<\/p>\n<p>reload)<\/p>\n<p>rh_status_q || exit 7<\/p>\n<p>$1<\/p>\n<p>;;<\/p>\n<p>force-reload)<\/p>\n<p>force_reload<\/p>\n<p>;;<\/p>\n<p>status)<\/p>\n<p>rh_status<\/p>\n<p>;;<\/p>\n<p>condrestart|try-restart)<\/p>\n<p>rh_status_q || exit 0<\/p>\n<p>;;<\/p>\n<p>*)<\/p>\n<p>echo $&#8221;Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}&#8221;<\/p>\n<p>exit 2<\/p>\n<p>esac<\/p>\n<p>\u800c\u540e\u4e3a\u6b64\u811a\u672c\u8d4b\u4e88\u6267\u884c\u6743\u9650\uff1a<\/p>\n<p>[root@nginx-server ~]# chmod +x \/etc\/rc.d\/init.d\/nginx<\/p>\n<p>\u6dfb\u52a0\u81f3\u670d\u52a1\u7ba1\u7406\u5217\u8868\uff0c\u5e76\u8ba9\u5176\u5f00\u673a\u81ea\u52a8\u542f\u52a8\uff1a<\/p>\n<p>[root@nginx-server ~]# chkconfig &#8211;add nginx<\/p>\n<p>[root@nginx-server ~]# chkconfig nginx on<\/p>\n<p>\u800c\u540e\u5c31\u53ef\u4ee5\u542f\u52a8\u670d\u52a1\u5e76\u6d4b\u8bd5\u4e86\uff1a<\/p>\n<p>[root@nginx-server ~]# service nginx start<\/p>\n<p>\u6b63\u5728\u542f\u52a8 nginx\uff1a [\u786e\u5b9a]<\/p>\n<p>[root@nginx-server ~]# netstat -tnlp|grep nginx<\/p>\n<p>tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 35524\/nginx<\/p>\n<p>[root@nginx-server ~]# curl -I http:\/\/192.168.0.11\/<\/p>\n<p>HTTP\/1.1 200 OK<\/p>\n<p>Server: nginx\/1.6.3<\/p>\n<p>Date: Fri, 29 Dec 2017 13:36:19 GMT<\/p>\n<p>Content-Type: text\/html<\/p>\n<p>Content-Length: 612<\/p>\n<p>Last-Modified: Fri, 29 Dec 2017 13:20:55 GMT<\/p>\n<p>Connection: keep-alive<\/p>\n<p>ETag: &#8220;5a464137-264&#8221;<\/p>\n<p>Accept-Ranges: bytes<\/p>\n<h3>\u4e09\u3001\u5b89\u88c5tomcat\u670d\u52a1\u5668<\/h3>\n<p><strong>1.\u5b89\u88c5JDK\uff0c\u914d\u7f6eJava\u73af\u5883<\/strong><\/p>\n<p>[root@tomcat-server-1 ~]# rpm -vih jdk-8u25-linux-x64.rpm<\/p>\n<p>Preparing&#8230; ########################################### [100%]<\/p>\n<p>1:jdk1.8.0_25 ########################################### [100%]<\/p>\n<p>Unpacking JAR files&#8230;<\/p>\n<p>rt.jar&#8230;<\/p>\n<p>jsse.jar&#8230;<\/p>\n<p>charsets.jar&#8230;<\/p>\n<p>tools.jar&#8230;<\/p>\n<p>localedata.jar&#8230;<\/p>\n<p>jfxrt.jar&#8230;<\/p>\n<p>[root@tomcat-server ~]# cat \/etc\/profile.d\/java.sh #\u8bbe\u7f6ejava\u73af\u5883\u53d8\u91cf<\/p>\n<p>export JAVA_HOME=\/usr\/java\/latest<\/p>\n<p>export CLASSPATH=$JAVA_HOME\/lib\/tools.jar<\/p>\n<p>export PATH=$JAVA_HOME\/bin:$PATH<\/p>\n<p>[root@tomcat-server-1 ~]# . \/etc\/profile.d\/java.sh<\/p>\n<p>[root@tomcat-server-1 ~]# java -version #\u67e5\u770bjava\u53d8\u91cf\u662f\u5426\u914d\u7f6e\u6210\u529f<\/p>\n<p>java version &#8220;1.8.0_25&#8221;<\/p>\n<p>Java(TM) SE Runtime Environment (build 1.8.0_25-b17)<\/p>\n<p>Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)<\/p>\n<p><strong>2.\u5b89\u88c5tomcat\u670d\u52a1<\/strong><\/p>\n<p>[root@tomcat-server-1 ~]# wget http:\/\/mirrors.shuosc.org\/apache\/tomcat\/tomcat-8\/v8.0.48\/bin\/apache-tomcat-8.0.48.tar.gz<\/p>\n<p>[root@tomcat-server-1 ~]# tar xf apache-tomcat-8.0.48.tar.gz -C \/usr\/local\/<\/p>\n<p>[root@tomcat-server-1 ~]# cd \/usr\/local\/<\/p>\n<p>[root@tomcat-server-1 local]# ln -sv apache-tomcat-8.0.48 tomcat<\/p>\n<p>&#8220;tomcat&#8221; -&gt; &#8220;apache-tomcat-8.0.48&#8221;<\/p>\n<p>[root@tomcat-server-1 local]# cat \/etc\/profile.d\/tomcat.sh #\u914dtomcat\u73af\u5883\u53d8\u91cf<\/p>\n<p>export CATALINA_HOME=\/usr\/local\/tomcat<\/p>\n<p>export PATH=$CATALINA_HOME\/bin:$PATH<\/p>\n<p>[root@tomcat-server-1 local]# . \/etc\/profile.d\/tomcat.sh<\/p>\n<p>[root@tomcat1-server-1 local]# catalina.sh start #\u542f\u52a8\u670d\u52a1<\/p>\n<p>Using CATALINA_BASE: \/usr\/local\/tomcat<\/p>\n<p>Using CATALINA_HOME: \/usr\/local\/tomcat<\/p>\n<p>Using CATALINA_TMPDIR: \/usr\/local\/tomcat\/temp<\/p>\n<p>Using JRE_HOME: \/usr\/java\/latest<\/p>\n<p>Using CLASSPATH: \/usr\/local\/tomcat\/bin\/bootstrap.jar:\/usr\/local\/tomcat\/bin\/tomcat-juli.jar<\/p>\n<p>Tomcat started.<\/p>\n<p>[root@tomcat-server-1 local]# netstat -tnlp #\u67e5\u770b\u7aef\u53e3\u662f\u5426\u542f\u52a8<\/p>\n<p>Active Internet connections (only servers)<\/p>\n<p>Proto Recv-Q Send-Q Local Address Foreign Address State PID\/Program name<\/p>\n<p>tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 947\/sshd<\/p>\n<p>tcp 0 0 :::22 :::* LISTEN 947\/sshd<\/p>\n<p>tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 8014\/java<\/p>\n<p>tcp 0 0 :::8009 :::* LISTEN 8014\/java<\/p>\n<p>tcp 0 0 :::8080 :::* LISTEN 8014\/java<\/p>\n<p>[root@tomcat-server-1 local]# curl -I http:\/\/192.168.0.12:8080 #\u6d4b\u8bd5\u662f\u5426\u53ef\u4ee5\u6253\u5f00<\/p>\n<p>HTTP\/1.1 200 OK<\/p>\n<p>Server: Apache-Coyote\/1.1<\/p>\n<p>Content-Type: text\/html;charset=UTF-8<\/p>\n<p>Transfer-Encoding: chunked<\/p>\n<p>Date: Fri, 29 Dec 2017 13:49:39 GMT<\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u3002tomcat-server-2\u548ctomcat-server-1\u76f8\u540c\uff0c\u5728\u6b64\u5ffd\u7565<\/p>\n<p><strong>\u00a0\u8bbe\u7f6e\u9ed8\u8ba4\u865a\u62df\u4e3b\u673a\uff0c\u5e76\u589e\u52a0jvmRoute<\/strong><\/p>\n<p>[root@tomcat1-server-1 local]# vim \/usr\/local\/tomcat\/conf\/server.xml<\/p>\n<p>&lt;Engine name=&#8221;Catalina&#8221; defaultHost=&#8221;localhost&#8221; jvmRoute=&#8221;tomcat-1&#8243;&gt; #jvmRoute\u662fjvm\u6807\u8bc6\uff0c\u5c31\u662f\u9875\u9762\u6700\u9876\u90e8\u7684\u6807\u7b7e\uff0c\u5728\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u6240\u6709\u7684\u540e\u53f0tomcat\u6807\u8bc6\u90fd\u8981\u4e00\u6837\uff0c\u8fd9\u91cc\u4e3a\u4e86\u5b9e\u9a8c\u7684\u8bf4\u660e\u6027\uff0c\u4e24\u53f0tomcat\u7684\u6807\u8bc6\u6539\u6210\u4e0d\u4e00\u6837\u7684\uff0c\u5206\u522b\u4e3atomcat-1h\u548ctomcat-2<\/p>\n<p>&lt;Host name=&#8221;localhost&#8221; appBase=&#8221;webapps&#8221;<\/p>\n<p>unpackWARs=&#8221;true&#8221; autoDeploy=&#8221;true&#8221;&gt;<\/p>\n<p>&lt;Context docBase=&#8221;\/Data\/webapps1&#8243; path=&#8221;&#8221; reloadable=&#8221;true&#8221; \/&gt; #\u4fee\u6539\u9ed8\u8ba4\u865a\u62df\u4e3b\u673a\uff0c\u5e76\u5c06\u7f51\u7ad9\u6587\u4ef6\u8def\u5f84\u6307\u5411\/Data\/webapps1<\/p>\n<p><strong>\u521b\u5efacontext\u76ee\u5f55\u548c\u6d4b\u8bd5\u9875\u9762<\/strong><\/p>\n<p>[root@tomcat1-server-1 local]# mkdir -pv \/Data\/webapps1<\/p>\n<p>mkdir: \u5df2\u521b\u5efa\u76ee\u5f55 &#8220;\/Data&#8221;<\/p>\n<p>mkdir: \u5df2\u521b\u5efa\u76ee\u5f55 &#8220;\/Data\/webapps1&#8243;<\/p>\n<p>[root@tomcat1-server-1 local]# cat \/Data\/webapps1\/index.jsp #\u521b\u5efa\u6d4b\u8bd5\u9875\u9762\uff0cserver-2\u4e2d\u5c06tomcat-1\u6539\u4e3atomcat-1\u5373\u53ef<\/p>\n<p>&lt;%@ page language=&#8221;java&#8221; %&gt;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;head&gt;&lt;title&gt;Tomcat-1&lt;\/title&gt;&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;h1&gt;&lt;font color=&#8221;red&#8221;&gt;www.tomcat-1.com&lt;\/font&gt;&lt;\/h1&gt;<\/p>\n<p>&lt;table align=&#8221;centre&#8221; border=&#8221;1&#8243;&gt;<\/p>\n<p>&lt;tr&gt;<\/p>\n<p>&lt;td&gt;Session ID&lt;\/td&gt;<\/p>\n<p>&lt;% session.setAttribute(&#8220;tomcat-1.com&#8221;,&#8221;tomcat-1.com&#8221;); %&gt;<\/p>\n<p>&lt;td&gt;&lt;%= session.getId() %&gt;&lt;\/td&gt;<\/p>\n<p>&lt;\/tr&gt;<\/p>\n<p>&lt;tr&gt;<\/p>\n<p>&lt;td&gt;Created on&lt;\/td&gt;<\/p>\n<p>&lt;td&gt;&lt;%= session.getCreationTime() %&gt;&lt;\/td&gt;<\/p>\n<p>&lt;\/tr&gt;<\/p>\n<p>&lt;\/table&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p><strong>\u6d4b\u8bd5\u914d\u7f6e\uff0c\u5e76\u542f\u52a8<\/strong><\/p>\n<p>[root@tomcat1-server-1 local]# catalina.sh stop<\/p>\n<p>[root@tomcat1-server-1 local]# catalina.sh configtest<\/p>\n<p>[root@tomcat1-server-1 local]# catalina.sh start<\/p>\n<h3><strong><strong>\u56db\u3001\u914d\u7f6enginx\u8d1f\u8f7d\u5747\u8861tomcat<\/strong><\/strong><\/h3>\n<p>[root@nginx-server ~]# vim \/etc\/nginx\/nginx.conf<\/p>\n<p>user nginx;<\/p>\n<p>worker_processes 1;<\/p>\n<p>events {<\/p>\n<p>worker_connections 1024;<\/p>\n<p>}<\/p>\n<p>http {<\/p>\n<p>include mime.types;<\/p>\n<p>default_type application\/octet-stream;<\/p>\n<p>log_format main &#8216;$remote_addr &#8211; $remote_user [$time_local] &#8220;$request&#8221; &#8216;<\/p>\n<p>&#8216;$status $body_bytes_sent &#8220;$http_referer&#8221; &#8216;<\/p>\n<p>&#8216;&#8221;$http_user_agent&#8221; &#8220;$http_x_forwarded_for&#8221;&#8216;;<\/p>\n<p>sendfile on;<\/p>\n<p>tcp_nopush on;<\/p>\n<p>keepalive_timeout 65;<\/p>\n<p>gzip on;<\/p>\n<p>upstream tomcat-web {<\/p>\n<p>server 192.168.0.12:8080;<\/p>\n<p>server 192.168.0.13:8080;<\/p>\n<p>}<\/p>\n<p>server {<\/p>\n<p>listen 80;<\/p>\n<p>server_name www.tomcat.com;<\/p>\n<p>location \/ {<\/p>\n<p>root html;<\/p>\n<p>index index.html index.htm index.jsp;<\/p>\n<p>}<\/p>\n<p>location ~* \\.(jsp|do)$ {<\/p>\n<p>proxy_pass http:\/\/tomcat-web;<\/p>\n<p>proxy_redirect off;<\/p>\n<p>proxy_set_header Host $host;<\/p>\n<p>proxy_set_header X-Real-IP $remote_addr;<\/p>\n<p>proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<\/p>\n<p>proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;<\/p>\n<p>}<\/p>\n<p>location \/nginx_status {<\/p>\n<p>stub_status on;<\/p>\n<p>access_log off;<\/p>\n<p>allow 192.168.0.0\/24;<\/p>\n<p>deny all;<\/p>\n<p>}<\/p>\n<p>error_page 500 502 503 504 \/50x.html;<\/p>\n<p>location = \/50x.html {<\/p>\n<p>root html;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p><strong>\u91cd\u65b0\u8f7d\u5165<\/strong><\/p>\n<p>[root@nginx-server ~]# nginx -t<\/p>\n<p>nginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok<\/p>\n<p>nginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/p>\n<p>[root@nginx-server ~]# service nginx reload<\/p>\n<p>nginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok<\/p>\n<p>nginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/p>\n<p>\u91cd\u65b0\u8f7d\u5165 nginx\uff1a [\u786e\u5b9a]<\/p>\n<p><strong>\u6d4b\u8bd5(\u6d4b\u8bd5\u673a\u914d\u7f6ehosts\u6587\u4ef6\u89e3\u6790)\uff0c\u8bbf\u95eehttp:\/\/www.tomcat.com\/index.jsp URL<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"635\" height=\"227\" class=\"wp-image-1744\" src=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-5.png\" alt=\"Graphical user interface, text, application\n\nDescription automatically generated\" srcset=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-5.png 635w, https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-5-300x107.png 300w\" sizes=\"auto, (max-width: 635px) 100vw, 635px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"542\" height=\"235\" class=\"wp-image-1745\" src=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-6.png\" alt=\"Graphical user interface, text, application\n\nDescription automatically generated\" srcset=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-6.png 542w, https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-6-300x130.png 300w\" sizes=\"auto, (max-width: 542px) 100vw, 542px\" \/><\/p>\n<p><strong>\u591a\u5237\u65b0\u51e0\u6b21\uff0c\u4ece\u7ed3\u679c\u80fd\u770b\u51fa\uff0cnginx\u628a\u8bbf\u95ee\u8bf7\u6c42\u5206\u522b\u5206\u53d1\u7ed9\u4e86\u540e\u7aef\u7684tomcat-1\u548ctomcat-2\uff0c\u5ba2\u6237\u7aef\u7684\u8bbf\u95ee\u8bf7\u6c42\u5b9e\u73b0\u4e86\u8d1f\u8f7d\u5747\u8861\uff0c\u4f46session id\u4e0d\u4e00\u6837(\u5373\uff1a\u6ca1\u6709\u5b9e\u73b0session\u4fdd\u6301)<\/strong><\/p>\n<h3>\u4e94\u3001\u5b89\u88c5redis\u670d\u52a1<\/h3>\n<p><strong>\u4e0b\u8f7d\u6e90\u7801\uff0c\u5e76\u7f16\u8bd1<\/strong><\/p>\n<p>[root@redis-server ~]# wget http:\/\/download.redis.io\/releases\/redis-3.2.3.tar.gz<\/p>\n<p>[root@redis-server ~]# tar xf redis-3.2.3.tar.gz<\/p>\n<p>[root@redis-server ~]# cd redis-3.2.3<\/p>\n<p>[root@redis-server redis-3.2.3]# make<\/p>\n<p>[root@redis-server redis-3.2.3]# make PREFIX=\/usr\/local\/redis install<\/p>\n<p><strong>\u914d\u7f6eredis<\/strong><\/p>\n<p>[root@redis-server redis-3.2.3]# mkdir \/usr\/local\/redis\/etc\/<\/p>\n<p>[root@redis-server redis-3.2.3]# cp redis.conf \/usr\/local\/redis\/etc\/<\/p>\n<p>[root@redis-server redis-3.2.3]# cd \/usr\/local\/redis\/bin\/<\/p>\n<p>[root@redis-server bin]# cp redis-benchmark redis-cli redis-server \/usr\/bin\/<\/p>\n<p><strong>\u8c03\u6574\u4e0b\u5185\u5b58\u5206\u914d\u4f7f\u7528\u65b9\u5f0f\u5e76\u4f7f\u5176\u751f\u6548<\/strong><\/p>\n<p>#\u6b64\u53c2\u6570\u53ef\u7528\u7684\u503c\u4e3a0,1,2<\/p>\n<p>#0\u8868\u793a\u5f53\u7528\u6237\u7a7a\u95f4\u8bf7\u6c42\u66f4\u591a\u7684\u5185\u5b58\u65f6\uff0c\u5185\u6838\u5c1d\u8bd5\u4f30\u7b97\u51fa\u53ef\u7528\u7684\u5185\u5b58<\/p>\n<p>#1\u8868\u793a\u5185\u6838\u5141\u8bb8\u8d85\u91cf\u4f7f\u7528\u5185\u5b58\u76f4\u5230\u5185\u5b58\u7528\u5b8c\u4e3a\u6b62<\/p>\n<p>#2\u8868\u793a\u6574\u4e2a\u5185\u5b58\u5730\u5740\u7a7a\u95f4\u4e0d\u80fd\u8d85\u8fc7swap+(vm.overcommit_ratio)%\u7684RAM\u503c<\/p>\n<p>[root@redis-server bin]# echo &#8220;vm.overcommit_memory=1&#8221;&gt;&gt;\/etc\/sysctl.conf<\/p>\n<p>[root@redis-server bin]# sysctl -p<\/p>\n<p><strong>\u4fee\u6539redis\u914d\u7f6e<\/strong><\/p>\n<p>[root@redis-server bin]#vim \/usr\/local\/redis\/etc\/redis.conf<\/p>\n<p># \u4fee\u6539\u4e00\u4e0b\u914d\u7f6e<\/p>\n<p>#\u8bbe\u7f6eredis\u76d1\u542c\u7684\u5730\u5740<\/p>\n<p>bind 0.0.0.0<\/p>\n<p># redis\u4ee5\u5b88\u62a4\u8fdb\u7a0b\u7684\u65b9\u5f0f\u8fd0\u884c<\/p>\n<p># no\u8868\u793a\u4e0d\u4ee5\u5b88\u62a4\u8fdb\u7a0b\u7684\u65b9\u5f0f\u8fd0\u884c(\u4f1a\u5360\u7528\u4e00\u4e2a\u7ec8\u7aef)<\/p>\n<p>daemonize yes<\/p>\n<p># \u5ba2\u6237\u7aef\u95f2\u7f6e\u591a\u957f\u65f6\u95f4\u540e\u65ad\u5f00\u8fde\u63a5\uff0c\u9ed8\u8ba4\u4e3a0\u5173\u95ed\u6b64\u529f\u80fd<\/p>\n<p>timeout 300<\/p>\n<p># \u8bbe\u7f6eredis\u65e5\u5fd7\u7ea7\u522b\uff0c\u9ed8\u8ba4\u7ea7\u522b\uff1anotice<\/p>\n<p>loglevel verbose<\/p>\n<p># \u8bbe\u7f6e\u65e5\u5fd7\u6587\u4ef6\u7684\u8f93\u51fa\u65b9\u5f0f,\u5982\u679c\u4ee5\u5b88\u62a4\u8fdb\u7a0b\u7684\u65b9\u5f0f\u8fd0\u884credis \u9ed8\u8ba4:&#8221;&#8221;<\/p>\n<p># \u5e76\u4e14\u65e5\u5fd7\u8f93\u51fa\u8bbe\u7f6e\u4e3astdout,\u90a3\u4e48\u65e5\u5fd7\u4fe1\u606f\u5c31\u8f93\u51fa\u5230\/dev\/null\u91cc\u9762\u53bb\u4e86<\/p>\n<p>logfile &#8220;\/usr\/local\/redis\/log\/redis-access.log&#8221;<\/p>\n<p>#redis\u9ed8\u8ba4\u662f\u7a7a\u5bc6\u7801\u8bbf\u95ee\uff0c\u8fd9\u6837\u5f88\u4e0d\u5b89\u5168\u3002\u9700\u8981\u542f\u7528redis\u7684\u5bc6\u7801\u9a8c\u8bc1\u529f\u80fd<\/p>\n<p>requirepass pwd@123<\/p>\n<p><strong>redis\u73af\u5883\u53d8\u91cf\u914d\u7f6e<\/strong><\/p>\n<p>[root@redis-server bin]# echo &#8220;export PATH=\/usr\/local\/redis\/bin:$PATH&#8221; &gt; \/etc\/profile.d\/redis.sh<\/p>\n<p>[root@redis-server bin]# . \/etc\/profile.d\/redis.sh<\/p>\n<p><strong>\u521b\u5efaRedis \u7cfb\u7edf\u542f\u52a8\u811a\u672c<\/strong><\/p>\n<p>[root@redis-server bin]# cat \/etc\/init.d\/redis<\/p>\n<p>#!\/bin\/bash<\/p>\n<p>#chkconfig: 2345 80 90<\/p>\n<p># Simple Redis init.d script conceived to work on Linux systems<\/p>\n<p># as it does use of the \/proc filesystem.<\/p>\n<p>PATH=\/usr\/local\/bin:\/sbin:\/usr\/bin:\/bin<\/p>\n<p>REDISPORT=6379<\/p>\n<p>EXEC=\/usr\/local\/redis\/bin\/redis-server<\/p>\n<p>REDIS_CLI=\/usr\/local\/redis\/bin\/redis-cli<\/p>\n<p>&nbsp;<\/p>\n<p>PIDFILE=\/var\/run\/redis_6379.pid<\/p>\n<p>CONF=&#8221;\/usr\/local\/redis\/etc\/redis.conf&#8221;<\/p>\n<p>&nbsp;<\/p>\n<p>case &#8220;$1&#8221; in<\/p>\n<p>start)<\/p>\n<p>if [ -f $PIDFILE ]<\/p>\n<p>then<\/p>\n<p>echo &#8220;$PIDFILE exists, process is already running or crashed&#8221;<\/p>\n<p>else<\/p>\n<p>echo &#8220;Starting Redis server&#8230;&#8221;<\/p>\n<p>$EXEC $CONF<\/p>\n<p>fi<\/p>\n<p>if [ &#8220;$?&#8221;=&#8221;0&#8221; ]<\/p>\n<p>then<\/p>\n<p>echo &#8220;Redis is running&#8230;&#8221;<\/p>\n<p>fi<\/p>\n<p>;;<\/p>\n<p>stop)<\/p>\n<p>if [ ! -f $PIDFILE ]<\/p>\n<p>then<\/p>\n<p>echo &#8220;$PIDFILE does not exist, process is not running&#8221;<\/p>\n<p>else<\/p>\n<p>PID=$(cat $PIDFILE)<\/p>\n<p>echo &#8220;Stopping &#8230;&#8221;<\/p>\n<p>$REDIS_CLI -p $REDISPORT SHUTDOWN<\/p>\n<p>while [ -x ${PIDFILE} ]<\/p>\n<p>do<\/p>\n<p>echo &#8220;Waiting for Redis to shutdown &#8230;&#8221;<\/p>\n<p>sleep 1<\/p>\n<p>done<\/p>\n<p>echo &#8220;Redis stopped&#8221;<\/p>\n<p>fi<\/p>\n<p>;;<\/p>\n<p>restart|force-reload)<\/p>\n<p>${0} stop<\/p>\n<p>${0} start<\/p>\n<p>;;<\/p>\n<p>*)<\/p>\n<p>echo &#8220;Usage: \/etc\/init.d\/redis {start|stop|restart|force-reload}&#8221; &gt;&amp;2<\/p>\n<p>exit 1<\/p>\n<p>esac<\/p>\n<p>[root@redis-server bin]# chmod +x \/etc\/init.d\/redis<\/p>\n<p>[root@redis-server bin]# service redis start #\u542f\u52a8<\/p>\n<p><strong>\u6d4b\u8bd5\uff1a<\/strong><\/p>\n<p>[root@redis-server bin]# redis-cli -h 192.168.0.14 -p 6379 -a pwd@123<\/p>\n<p>192.168.0.14:6379&gt; keys *<\/p>\n<p>(empty list or set)<\/p>\n<p>192.168.0.14:6379&gt; set name pwb<\/p>\n<p>OK<\/p>\n<p>192.168.0.14:6379&gt; get name<\/p>\n<p>&#8220;pwb&#8221;<\/p>\n<p>redis\u6e90\u7801\u5b89\u88c5\u5b8c\u6bd5<\/p>\n<h3>\u516d\u3001\u914d\u7f6etomcatsession redis\u540c\u6b65(tomcat-server\u4e0a)<\/h3>\n<p><strong>Tomcat8\u8fde\u63a5Reids\u9700\u8981\u4ee5\u4e0b3\u4e2a\u8f6f\u4ef6\u5305\uff1a<\/strong><\/p>\n<p>1 commons-pool2-2.2.jar<\/p>\n<p>2 jedis-2.5.2.jar<\/p>\n<p>3 tomcat-redis-session-manager-2.0.0.jar #tomcat7\u8fd9\u9700\u8981\u5c06\u8fd9\u4e2a\u5305\u66ff\u6362\u4e3atomcat-redis-session-manage-tomcat7.jar<\/p>\n<p><strong>\u5c06\u6240\u9700\u8981\u7684jar\u5305\u590d\u5236\u5230$CATALINA_HOME\/lib\/\u4e0b\uff0c\u5373tomcat\u5b89\u88c5\u76ee\u5f55\u7684lib\u76ee\u5f55\u4e0b<\/strong><\/p>\n<p>[root@tomcat-server-1 ~]# cp commons-pool2-2.2.jar jedis-2.5.2.jar tomcat-redis-session-manager-2.0.0.jar \/usr\/local\/tomcat\/lib<\/p>\n<p><strong>\u5728Tomcat\u7684conf\/context.xml\u6587\u4ef6\u4e2d\u52a0\u5165\u4f7f\u7528redis-session\u7684\u914d\u7f6e<\/strong><\/p>\n<p>&lt;Valve className=&#8221;com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve&#8221; \/&gt;<\/p>\n<p>&lt;Manager className=&#8221;com.orangefunction.tomcat.redissessions.RedisSessionManager&#8221;<\/p>\n<p>host=&#8221;192.168.0.14&#8243;<\/p>\n<p>password=&#8221;pwd@123&#8243;<\/p>\n<p>port=&#8221;6379&#8243;<\/p>\n<p>database=&#8221;0&#8243;<\/p>\n<p>maxInactiveInterval=&#8221;60&#8243;<\/p>\n<p>\/&gt;<\/p>\n<p>\u6ce8\u610fValve\u5fc5\u987b\u914d\u7f6e\u5728Manager\u4e4b\u524d<\/p>\n<p><strong>\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\u6d4b\u8bd5,\u7ed3\u679c\u5982\u4e0b\uff1a<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"635\" height=\"227\" class=\"wp-image-1746\" src=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-7.png\" alt=\"Graphical user interface, text, application\n\nDescription automatically generated\" srcset=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-7.png 635w, https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-7-300x107.png 300w\" sizes=\"auto, (max-width: 635px) 100vw, 635px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"542\" height=\"235\" class=\"wp-image-1747\" src=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-8.png\" alt=\"Graphical user interface, text, application\n\nDescription automatically generated\" srcset=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-8.png 542w, https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-8-300x130.png 300w\" sizes=\"auto, (max-width: 542px) 100vw, 542px\" \/><\/p>\n<p><strong>\u53ef\u4ee5\u770b\u51fa\uff0c\u5206\u522b\u8bbf\u95ee\u4e86\u4e0d\u540c\u7684tomcat\uff0c\u4f46\u662f\u5f97\u5230\u7684session\u5374\u662f\u76f8\u540c\u7684\uff0c\u8bf4\u660e\u8fbe\u5230\u4e86\u96c6\u7fa4\u7684\u76ee\u7684\u3002<\/strong><\/p>\n<p><strong>\u6ce8\uff1a\u4eceTomcat6\u5f00\u59cb\u9ed8\u8ba4\u5f00\u542f\u4e86Session\u6301\u4e45\u5316\u8bbe\u7f6e\uff0c\u6d4b\u8bd5\u65f6\u53ef\u4ee5\u5173\u95ed\u672c\u5730Session\u6301\u4e45\u5316\uff0c\u5728Tomcat\u7684conf\u76ee\u5f55\u4e0b\u7684context.xml\u6587\u4ef6\u4e2d\uff0c\u53d6\u6d88\u00a0&lt;Manager pathname=\u201d\u201d \/&gt; \u6ce8\u91ca\u5373\u53ef<\/strong><\/p>\n<h3>\u4e03\u3001\u914d\u7f6etomcat\u8fde\u63a5\u6570\u636e\u5e93<\/h3>\n<p><strong>\u5b89\u88c5mysql\uff0c\u521b\u5efa\u8ba4\u8bc1\u7528\u6237(mysql-server\u4e0a)<\/strong><\/p>\n<p>[root@mysql-server yum]# yum install mysql-server -y<\/p>\n<p>[root@mysql-server yum]# service mysqld start<\/p>\n<p>[root@mysql-server yum]# mysql<\/p>\n<p>mysql&gt; grant all on *.* to tomcat_user@&#8217;192.168.0.%&#8217; identified by &#8216;123456&#8217;;<\/p>\n<p>Query OK, 0 rows affected (0.00 sec)<\/p>\n<p><strong>\u4e0b\u8f7dmysql-connector-java-5.1.22-bin.jar\u5e76\u590d\u5236\u5230$CATALINA_HOME\/lib\u76ee\u5f55\u4e0b(tomcat-serve\u4e0a)<\/strong><\/p>\n<p>[root@tomcat-server-2 ]# cd \/usr\/local\/tomcat\/<\/p>\n<p>[root@tomcat-server-2 tomcat]#wget https:\/\/cdn.mysql.com\/\/Downloads\/Connector-J\/mysql-connector-java-5.1.22.tar.gz<\/p>\n<p>[root@tomcat-server-2 tomcat]#unzip mysql-connector-java-5.1.22-bin.jar.zip<\/p>\n<p>[root@tomcat-server-2 tomcat]#cp mysql-connector-java-5.1.22-bin.jar lib\/<\/p>\n<p><strong>\u914d\u7f6eJNDI\u6570\u636e\u6e90\uff0c\u4fdd\u5b58\u540e\u5185\u5bb9\u5982\u4e0b\uff1a<\/strong><\/p>\n<p>conf\/context.xml<\/p>\n<p>&lt;?xml version=&#8217;1.0&#8242; encoding=&#8217;utf-8&#8242;?&gt;<\/p>\n<p>&lt;!&#8211;<\/p>\n<p>The ASF licenses this file to You under the Apache License, Version 2.0<\/p>\n<p>(the &#8220;License&#8221;); you may not use this file except in compliance with<\/p>\n<p>the License. You may obtain a copy of the License at<\/p>\n<p>http:\/\/www.apache.org\/licenses\/LICENSE-2.0<\/p>\n<p>Unless required by applicable law or agreed to in writing, software<\/p>\n<p>distributed under the License is distributed on an &#8220;AS IS&#8221; BASIS,<\/p>\n<p>WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<\/p>\n<p>See the License for the specific language governing permissions and<\/p>\n<p>limitations under the License.<\/p>\n<p>&#8211;&gt;<\/p>\n<p>&lt;!&#8211; The contents of this file will be loaded for each web application &#8211;&gt;<\/p>\n<p>&lt;Context&gt;<\/p>\n<p>&lt;WatchedResource&gt;WEB-INF\/web.xml&lt;\/WatchedResource&gt;<\/p>\n<p>&lt;WatchedResource&gt;${catalina.base}\/conf\/web.xml&lt;\/WatchedResource&gt;<\/p>\n<p>&lt;!&#8211;\u914d\u7f6emysql\u6570\u636e\u5e93\u7684\u8fde\u63a5\u6c60&#8211;&gt;<\/p>\n<p>&lt;!&#8211;\u914d\u7f6emysql\u6570\u636e\u5e93\u7684\u8fde\u63a5\u6c60,<\/p>\n<p>\u9700\u8981\u505a\u7684\u989d\u5916\u6b65\u9aa4\u662f\u5c06mysql\u7684Java\u9a71\u52a8\u7c7b\u653e\u5230tomcat\u7684lib\u76ee\u5f55\u4e0b<\/p>\n<p>maxIdle \u8fde\u63a5\u6c60\u4e2d\u6700\u591a\u53ef\u7a7a\u95f2maxIdle\u4e2a\u8fde\u63a5<\/p>\n<p>minIdle \u8fde\u63a5\u6c60\u4e2d\u6700\u5c11\u7a7a\u95f2maxIdle\u4e2a\u8fde\u63a5<\/p>\n<p>initialSize \u521d\u59cb\u5316\u8fde\u63a5\u6570\u76ee<\/p>\n<p>maxWait \u8fde\u63a5\u6c60\u4e2d\u8fde\u63a5\u7528\u5b8c\u65f6,\u65b0\u7684\u8bf7\u6c42\u7b49\u5f85\u65f6\u95f4,\u6beb\u79d2<\/p>\n<p>username \u6570\u636e\u5e93\u7528\u6237\u540d<\/p>\n<p>password \u6570\u636e\u5e93\u5bc6\u7801<\/p>\n<p>&#8211;&gt;<\/p>\n<p>&lt;!&#8211; Default set of monitored resources. If one of these changes, the &#8211;&gt;<\/p>\n<p>&lt;!&#8211; web application will be reloaded. &#8211;&gt;<\/p>\n<p>&lt;!&#8211; Uncomment this to disable session persistence across Tomcat restarts &#8211;&gt;<\/p>\n<p>&lt;!&#8211;<\/p>\n<p>&lt;Manager pathname=&#8221;&#8221; \/&gt;<\/p>\n<p>&#8211;&gt;<\/p>\n<p>&lt;!&#8211; Uncomment this to enable Comet connection tacking (provides events<\/p>\n<p>on session expiration as well as webapp lifecycle) &#8211;&gt;<\/p>\n<p>&lt;!&#8211;<\/p>\n<p>&lt;Valve className=&#8221;org.apache.catalina.valves.CometConnectionManagerValve&#8221; \/&gt;<\/p>\n<p>&#8211;&gt;<\/p>\n<p>&lt;Valve className=&#8221;com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve&#8221; \/&gt;<\/p>\n<p>&lt;Manager className=&#8221;com.orangefunction.tomcat.redissessions.RedisSessionManager&#8221;<\/p>\n<p>host=&#8221;192.168.0.14&#8243;<\/p>\n<p>password=&#8221;pwd@123&#8243;<\/p>\n<p>port=&#8221;6379&#8243;<\/p>\n<p>database=&#8221;0&#8243;<\/p>\n<p>maxInactiveInterval=&#8221;60&#8243;<\/p>\n<p>\/&gt;<\/p>\n<p>&lt;\/Context&gt;<\/p>\n<p><strong>\u5728\u9879\u76ee\u7684\u76ee\u5f55\u4e0b\u65b0\u5efaWEB-INF\u76ee\u5f55\uff0c\u7528\u4e8e\u5b58\u653e\u7f51\u7ad9xml\u914d\u7f6e\u6587\u4ef6\uff0c\u7528\u4e8etomcat\u8fde\u63a5mysql\u6570\u636e\u5e93<\/strong><\/p>\n<p>[root@tomcat-server-2 tomcat]mkdir \/Data\/webapps1\/WEB-INF<\/p>\n<p>[root@tomcat-server-2 tomcat]vim \/Data\/webapps1\/WEB-INF\/web.xml<\/p>\n<p>WEB-INF\/web.xml<\/p>\n<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;ISO-8859-1&#8243;?&gt;<\/p>\n<p>&lt;!&#8211;<\/p>\n<p>Licensed to the Apache Software Foundation (ASF) under one or more<\/p>\n<p>contributor license agreements. See the NOTICE file distributed with<\/p>\n<p>this work for additional information regarding copyright ownership.<\/p>\n<p>The ASF licenses this file to You under the Apache License, Version 2.0<\/p>\n<p>(the &#8220;License&#8221;); you may not use this file except in compliance with<\/p>\n<p>the License. You may obtain a copy of the License at<\/p>\n<p>http:\/\/www.apache.org\/licenses\/LICENSE-2.0<\/p>\n<p>Unless required by applicable law or agreed to in writing, software<\/p>\n<p>distributed under the License is distributed on an &#8220;AS IS&#8221; BASIS,<\/p>\n<p>WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<\/p>\n<p>See the License for the specific language governing permissions and<\/p>\n<p>limitations under the License.<\/p>\n<p>&#8211;&gt;<\/p>\n<p>&lt;web-app xmlns=&#8221;http:\/\/xmlns.jcp.org\/xml\/ns\/javaee&#8221;<\/p>\n<p>xmlns:xsi=&#8221;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#8221;<\/p>\n<p>xsi:schemaLocation=&#8221;http:\/\/xmlns.jcp.org\/xml\/ns\/javaee<\/p>\n<p>http:\/\/xmlns.jcp.org\/xml\/ns\/javaee\/web-app_3_1.xsd&#8221;<\/p>\n<p>version=&#8221;3.1&#8243;&gt;<\/p>\n<p>&lt;!&#8211; \u6570\u636e\u6e90 &#8211;&gt;<\/p>\n<p>&lt;resource-ref&gt;<\/p>\n<p>&lt;description&gt;DB Connection&lt;\/description&gt;<\/p>\n<p>&lt;res-ref-name&gt;jdbc\/TestDB&lt;\/res-ref-name&gt;<\/p>\n<p>&lt;res-type&gt;javax.sql.DataSource&lt;\/res-type&gt;<\/p>\n<p>&lt;res-auth&gt;Container&lt;\/res-auth&gt;<\/p>\n<p>&lt;\/resource-ref&gt;<\/p>\n<p>&lt;\/web-app&gt;<\/p>\n<p><strong>\u91cd\u542f\u670d\u52a1<\/strong><\/p>\n<p>[root@tomcat1-server-2 WEB-INF]# catalina.sh stop<\/p>\n<p>Using CATALINA_BASE: \/usr\/local\/tomcat<\/p>\n<p>Using CATALINA_HOME: \/usr\/local\/tomcat<\/p>\n<p>Using CATALINA_TMPDIR: \/usr\/local\/tomcat\/temp<\/p>\n<p>Using JRE_HOME: \/usr\/java\/latest<\/p>\n<p>Using CLASSPATH: \/usr\/local\/tomcat\/bin\/bootstrap.jar:\/usr\/local\/tomcat\/bin\/tomcat-juli.jar<\/p>\n<p>[root@tomcat1-server-2 WEB-INF]# catalina.sh start<\/p>\n<p>Using CATALINA_BASE: \/usr\/local\/tomcat<\/p>\n<p>Using CATALINA_HOME: \/usr\/local\/tomcat<\/p>\n<p>Using CATALINA_TMPDIR: \/usr\/local\/tomcat\/temp<\/p>\n<p>Using JRE_HOME: \/usr\/java\/latest<\/p>\n<p>Using CLASSPATH: \/usr\/local\/tomcat\/bin\/bootstrap.jar:\/usr\/local\/tomcat\/bin\/tomcat-juli.jar<\/p>\n<p>Tomcat started.<\/p>\n<p><strong>\u73b0\u5728\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u6d4b\u8bd5.jsp\u9875\u9762\uff0c\u6d4b\u8bd5tomcat\u548cmysql\u7684\u8fde\u901a\u6027<\/strong><\/p>\n<p>[root@tomcat-server-2 tomcat]# vim \/Data\/webapps1\/test.jsp<\/p>\n<p>&lt;%@page import=&#8221;javax.naming.InitialContext&#8221;%&gt;<\/p>\n<p>&lt;%@page import=&#8221;javax.sql.DataSource&#8221;%&gt;<\/p>\n<p>&lt;%@page import=&#8221;java.sql.Connection&#8221;%&gt;<\/p>\n<p>&lt;%@ page language=&#8221;java&#8221; contentType=&#8221;text\/html; charset=UTF-8&#8243;<\/p>\n<p>pageEncoding=&#8221;UTF-8&#8243;%&gt;<\/p>\n<p>&lt;!DOCTYPE html&gt;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html; charset=UTF-8&#8243;&gt;<\/p>\n<p>&lt;title&gt;Insert title here&lt;\/title&gt;<\/p>\n<p>&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;%<\/p>\n<p>out.print(&#8220;MySQL \u6570\u636e\u6e90\u6d4b\u8bd5\u5f00\u59cb&#8230;&#8221; + &#8220;&lt;br\/&gt;&#8221;);<\/p>\n<p>DataSource ds = null;<\/p>\n<p>try {<\/p>\n<p>InitialContext ctx = new InitialContext();<\/p>\n<p>ds = (DataSource) ctx.lookup(&#8220;java:comp\/env\/jdbc\/TestDB&#8221;);<\/p>\n<p>Connection conn = ds.getConnection();<\/p>\n<p>conn.close();<\/p>\n<p>out.print(&#8220;MySQL \u6570\u636e\u6e90\u6d4b\u8bd5\u6210\u529f\uff01&#8221;);<\/p>\n<p>} catch (Exception ex) {<\/p>\n<p>out.print(&#8220;\u51fa\u73b0\u610f\u5916\uff0c\u4fe1\u606f\u662f:&#8221; + ex.getMessage());<\/p>\n<p>ex.printStackTrace();<\/p>\n<p>}<\/p>\n<p>%&gt;<\/p>\n<p>%&lt;\/body&gt;<\/p>\n<p>%&lt;\/html&gt;<\/p>\n<p><strong>\u8bbf\u95ee\u6d4b\u8bd5\u9875\uff1a<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"547\" height=\"161\" class=\"wp-image-1748\" src=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-9.png\" alt=\"Graphical user interface, text, application\n\nDescription automatically generated\" srcset=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-9.png 547w, https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/10\/graphical-user-interface-text-application-descr-9-300x88.png 300w\" sizes=\"auto, (max-width: 547px) 100vw, 547px\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u73af\u5883\u51c6\u5907 \u65f6\u95f4\u540c\u6b65 \u5173\u95ed\u9632\u706b\u5899 \u4e8c\u3001\u5b89\u88c5nginx 1\u3001\u89e3\u51b3\u4f9d\u8d56\u5173\u7cfb [root@nginx-server [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-1742","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/1742","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1742"}],"version-history":[{"count":1,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/1742\/revisions"}],"predecessor-version":[{"id":1749,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/1742\/revisions\/1749"}],"wp:attachment":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}