搜尋
首頁資料庫Redisnginx+tomcat怎麼使用redis session共享

nginx+tomcat怎麼使用redis session共享

May 30, 2023 pm 06:40 PM
redisnginxtomcat

環境準備

1、準備一台nginx伺服器ip192.168.1.133 連接埠81

安裝過程:

#首先安装依赖:
yum -y install gcc-c++ 
yum -y install pcre pcre-devel 
yum -y install zlib zlib-devel 
yum -y install openssl openssl—devel
#注意 : 安装nginx必须使用 root 用户安装
#创建一个nginx目录
mkdir /usr/local/src/nginx
#进入到nginx目录
cd /usr/local/src/nginx
#下载或上传安装包
wget http://nginx.org/download/nginx.tar.gz 或 rz上传
#解压安装包
tar -xvf nginx.tar.gz
#进入到解压后的目录
cd nginx
# 下面 才开始正式安装
#把nginx安装到指定用户的目录
mkdir -p /ucenter/soft/nginx
#安装配置 prefix为安装目录 user为用户 group为 组
./configure --prefix=/ucenter/soft/nginx --user=ucenter --group=ucenter
#编译
make 
#安装
make install
#在linux系统中由于非root用户不能占用80端口,所以需要使普通用户以root身份启动nginx。 
cd /ucenter/soft/nginx/sbin
#把soft文件下所有的文件所属者修改为ucener -r 表示递归
chown ucenter:ucenter ./soft/ -r
#修改 ./nginx 的所属为root
chown root nginx
#让普通用户可以使用80端口,可以使用root权限启用nginx
chmod u+s nginx
#修改配置文件 在修改配置文件之前 ,要备份该文件
cd conf/
# 要注意nginx 的工作进程,一般根据cpu的核数去修改
vim nginx.conf
#关闭防火墙,打开80端口
service iptables stop
#启动nginx
./nginx
#重启nginx
./nginx -s reload
#关闭nginx
./nginx -s stop

準備一台tomcat伺服器,先準備java環境,安裝jdk步驟省略

然後分別安裝3個tomcat 伺服器ip位址:192.168.1.143,tomcat1 8080端口,tomcat2 8081端口,tomcat3 8082端口。

nginx+tomcat怎么使用redis session共享

apache-tomcat-7.0.64/conf/server.xml設定檔修改這三個地方,這樣連接埠就不會衝突

<server port="8005" shutdown="shutdown">
<connector port="8080" protocol="http/1.1"
connectiontimeout="20000"
redirectport="8443" />
<connector port="8009" protocol="ajp/1.3" redirectport="8443" />

修改tomcat root目錄下index.jsp,分別增加每個tomcat的標識,以及在頁面上顯示session id

<%--
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.
--%>
<!doctype html>
<%@ page session="true" %>
<%
java.text.simpledateformat sdf = new java.text.simpledateformat("yyyy");
request.setattribute("year", sdf.format(new java.util.date()));
request.setattribute("tomcaturl", "http://tomcat.apache.org/");
request.setattribute("tomcatdocurl", "/docs/");
request.setattribute("tomcatexamplesurl", "/examples/");
%>
<html>
 <head>
  <title><%=request.getservletcontext().getserverinfo() %></title>
  <link href="favicon.ico" rel="icon" type="image/x-icon" />
  <link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
  <link href="tomcat.css" rel="stylesheet" type="text/css" />
 </head>

 <body>
  <div id="wrapper">
   <div id="navigation" class="curved container">
    <span id="nav-home"><a href="${tomcaturl}">home--<%=request.getsession().getid() %></a></span>
    <span id="nav-hosts"><a href="${tomcatdocurl}">documentation</a></span>
    <span id="nav-config"><a href="${tomcatdocurl}config/">configuration</a></span>
    <span id="nav-examples"><a href="${tomcatexamplesurl}">examples</a></span>
    <span id="nav-wiki"><a href="http://wiki.apache.org/tomcat/frontpage">wiki</a></span>
    <span id="nav-lists"><a href="${tomcaturl}lists.html">mailing lists</a></span>
    <span id="nav-help"><a href="${tomcaturl}findhelp.html">find help</a></span>
    <br />
   </div>
   <div id="asf-box">
    <h1 id="pagecontext-servletcontext-serverinfo">${pagecontext.servletcontext.serverinfo}--8080</h1>
   </div>
   <div id="upper" class="curved container">
    <div id="congrats" class="curved container">
     <h2 id="if-nbsp-you-re-nbsp-seeing-nbsp-this-nbsp-you-ve-nbsp-successfully-nbsp-installed-nbsp-tomcat-nbsp-congratulations">if you&#39;re seeing this, you&#39;ve successfully installed tomcat. congratulations!</h2>
    </div>
    <div id="notice">
     <img src="/static/imghwm/default1.png"  data-src="tomcat.png"  class="lazy"   alt="[tomcat logo]" />
     <div id="tasks">
      <h3 id="recommended-nbsp-reading">recommended reading:</h3>
      <h4 id="a-nbsp-href-tomcatdocurl-security-howto-html-security-nbsp-considerations-nbsp-how-to-a"><a href="${tomcatdocurl}security-howto.html">security considerations how-to</a></h4>
      <h4 id="a-nbsp-href-tomcatdocurl-manager-howto-html-manager-nbsp-application-nbsp-how-to-a"><a href="${tomcatdocurl}manager-howto.html">manager application how-to</a></h4>
      <h4 id="a-nbsp-href-tomcatdocurl-cluster-howto-html-clustering-session-nbsp-replication-nbsp-how-to-a"><a href="${tomcatdocurl}cluster-howto.html">clustering/session replication how-to</a></h4>
     </div>
    </div>
    <div id="actions">
     <div>
      <a class="container shadow" href="/manager/status"><span>server status</span></a>
     </div>
     <div>
      <a class="container shadow" href="/manager/html"><span>manager app</span></a>
     </div>
     <div>
      <a class="container shadow" href="/host-manager/html"><span>host manager</span></a>
     </div>
    </div>
    <!--
    <br />
    -->
    <br />
   </div>
   <div id="middle" class="curved container">
    <h3 id="developer-nbsp-quick-nbsp-start">developer quick start</h3>
    <div>
     <div>
      <p><a href="${tomcatdocurl}setup.html">tomcat setup</a></p>
      <p><a href="${tomcatdocurl}appdev/">first web application</a></p>
     </div>
    </div>
    <div>
     <div>
      <p><a href="${tomcatdocurl}realm-howto.html">realms & aaa</a></p>
      <p><a href="${tomcatdocurl}jndi-datasource-examples-howto.html">jdbc datasources</a></p>
     </div>
    </div>
    <div>
     <div>
      <p><a href="${tomcatexamplesurl}">examples</a></p>
     </div>
    </div>
    <div>
     <div>
      <p><a href="http://wiki.apache.org/tomcat/specifications">servlet specifications</a></p>
      <p><a href="http://wiki.apache.org/tomcat/tomcatversions">tomcat versions</a></p>
     </div>
    </div>
    <br />
   </div>
   <div id="lower">
    <div id="low-manage" class="">
     <div class="curved container">
      <h3 id="managing-nbsp-tomcat">managing tomcat</h3>
      <p>for security, access to the <a href="/manager/html">manager webapp</a> is restricted.
      users are defined in:</p>
      <pre class="brush:php;toolbar:false">$catalina_home/conf/tomcat-users.xml
      

in tomcat 7.0 access to the manager application is split between        different users.   read more...

      
      

release notes

      

changelog

      

migration guide

      

security notices

               
     
      

documentation

      

tomcat 7.0 documentation

      

tomcat 7.0 configuration

      

tomcat wiki

      

find additional important configuration information in:

      
$catalina_home/running.txt
      

developers may be interested in:

            
    
    
     
      

getting help

      

faq and mailing lists

      

the following mailing lists are available:

      
           
  • tomcat-announce
            important announcements, releases, security vulnerability notifications. (low volume).
           
  •        
  • tomcat-users
            user support and discussion        
  •        
  • taglibs-user
            user support and discussion for apache taglibs        
  •        
  • tomcat-dev
            development mailing list, including commit messages        
  •       
     
    
    
       
    
     
      

other downloads

            
    
    
     
      

other documentation

            
    
    
     
      

get involved

            
    
    
     
      

miscellaneous

            
    
    
     
      

apache software foundation

            
    
    
   
   

copyright ©1999-${year} apache software foundation. all rights reserved

    

以上是nginx+tomcat怎麼使用redis session共享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:亿速云。如有侵權,請聯絡admin@php.cn刪除
REDIS:流行數據結構指南REDIS:流行數據結構指南Apr 11, 2025 am 12:04 AM

Redis支持多種數據結構,具體包括:1.字符串(String),適合存儲單一值數據;2.列表(List),適用於隊列和棧;3.集合(Set),用於存儲不重複數據;4.有序集合(SortedSet),適用於排行榜和優先級隊列;5.哈希表(Hash),適合存儲對像或結構化數據。

redis計數器怎麼實現redis計數器怎麼實現Apr 10, 2025 pm 10:21 PM

Redis計數器是一種使用Redis鍵值對存儲來實現計數操作的機制,包含以下步驟:創建計數器鍵、增加計數、減少計數、重置計數和獲取計數。 Redis計數器的優勢包括速度快、高並發、持久性和簡單易用。它可用於用戶訪問計數、實時指標跟踪、遊戲分數和排名以及訂單處理計數等場景。

redis命令行怎麼用redis命令行怎麼用Apr 10, 2025 pm 10:18 PM

使用 Redis 命令行工具 (redis-cli) 可通過以下步驟管理和操作 Redis:連接到服務器,指定地址和端口。使用命令名稱和參數向服務器發送命令。使用 HELP 命令查看特定命令的幫助信息。使用 QUIT 命令退出命令行工具。

redis集群模式怎麼搭建redis集群模式怎麼搭建Apr 10, 2025 pm 10:15 PM

Redis集群模式通過分片將Redis實例部署到多個服務器,提高可擴展性和可用性。搭建步驟如下:創建奇數個Redis實例,端口不同;創建3個sentinel實例,監控Redis實例並進行故障轉移;配置sentinel配置文件,添加監控Redis實例信息和故障轉移設置;配置Redis實例配置文件,啟用集群模式並指定集群信息文件路徑;創建nodes.conf文件,包含各Redis實例的信息;啟動集群,執行create命令創建集群並指定副本數量;登錄集群執行CLUSTER INFO命令驗證集群狀態;使

redis怎麼讀取隊列redis怎麼讀取隊列Apr 10, 2025 pm 10:12 PM

要從 Redis 讀取隊列,需要獲取隊列名稱、使用 LPOP 命令讀取元素,並處理空隊列。具體步驟如下:獲取隊列名稱:以 "queue:" 前綴命名,如 "queue:my-queue"。使用 LPOP 命令:從隊列頭部彈出元素並返回其值,如 LPOP queue:my-queue。處理空隊列:如果隊列為空,LPOP 返回 nil,可先檢查隊列是否存在再讀取元素。

redis集群zset怎麼使用redis集群zset怎麼使用Apr 10, 2025 pm 10:09 PM

Redis 集群中使用 zset:zset 是一種有序集合,將元素與評分關聯。分片策略: a. 哈希分片:根據 zset 鍵的哈希值分佈。 b. 範圍分片:根據元素評分劃分為範圍,並將每個範圍分配給不同的節點。讀寫操作: a. 讀操作:如果 zset 鍵屬於當前節點的分片,則在本地處理;否則,路由到相應的分片。 b. 寫入操作:始終路由到持有 zset 鍵的分片。

redis數據怎麼清空redis數據怎麼清空Apr 10, 2025 pm 10:06 PM

如何清空 Redis 數據:使用 FLUSHALL 命令清除所有鍵值。使用 FLUSHDB 命令清除當前選定數據庫的鍵值。使用 SELECT 切換數據庫,再使用 FLUSHDB 清除多個數據庫。使用 DEL 命令刪除特定鍵。使用 redis-cli 工具清空數據。

redis過期策略怎麼設置redis過期策略怎麼設置Apr 10, 2025 pm 10:03 PM

Redis數據過期策略有兩種:定期刪除:定期掃描刪除過期鍵,可通過 expired-time-cap-remove-count、expired-time-cap-remove-delay 參數設置。惰性刪除:僅在讀取或寫入鍵時檢查刪除過期鍵,可通過 lazyfree-lazy-eviction、lazyfree-lazy-expire、lazyfree-lazy-user-del 參數設置。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SecLists

SecLists

SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器