nginx+tomcat7+redis session共享

ZHCRoxanna 9年前發布 | 16K 次閱讀 Web服務器

來自: http://my.oschina.net/39605380/blog/616394


1.安裝nginx

wget http://sourceforge.net/settings/mirror_choices?projectname=pcre&filename=pcre/8.32/pcre-8.32.tar.gz

nginx download:

wget http://nginx.org/download/nginx-1.6.2.tar.gz

 

yum -y install gcc gcc-c++ autoconf automake make

yum -y install zlib zlib-devel openssl openssl-devel

unzip nginx-goodies-nginx-sticky-module-ng.zip -d /usr/local/

groupadd -r nginx

useradd -s /sbin/nologin -g nginx -r nginx

 

tar zxvf pcre-8.32.tar.gz

cd pcre-8.32

./configure --prefix=/usr/local/pcre

make

make install

 

tar zxvf nginx-1.6.2.tar.gz

cd nginx-1.6.2

./configure --user=nginx --group=nginx --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --with-http_gzip_static_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.32

make

make install

 

 

修改nginx配置文件

vi /etc/nginx/nginx.conf

添加以下內容:

server {

   listen       80 default_server;

   server_name  172.25.73.120;

   root         /usr/share/nginx/html;

   # Load configuration files for the default server block.

   include /etc/nginx/default.d/*.conf;

   location / {

   }

   # redirect server error pages to the static page /40x.html

   error_page  404 /404.html;

     location = /40x.html {

   }

        

   # redirect server error pages to the static page /50x.html

   error_page   500 502 503 504  /50x.html;

     location = /50x.html {

        }

 }

 

2.安裝tomcat

tar xzf apache-tomcat-7.0.59.tar.gz

 

mv apache-tomcat-7.0.59   tomcat

 

啟動tomcat

./ tomcat/bin/ catalina.sh start

 

修改contest.xml文件

<Context>

<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />       

    <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"

        host="localhost"

        port="6379"

        database="0"

        maxInactiveInterval="60"/>

</Context>


tomcat需要的jar包,下載地址 http://down.51cto.com/data/2173531

commons-pool2-2.2

jedis-2.5.2

tomcat-redis-session-manage-tomcat7

 

上面的3jar放到  tomcat/lib/ 目錄下

 

3.安裝redis

tar -zxf redis-2.6.16.tar.gz

cd redis-2.6.16

make

make install

mv redis-2.6.16 /usr/local/redis

cd /usr/local/redis/

mkdir conf

啟動redis

/usr/local/redir/src/redis-server   /usr/local/redir/redis.conf &

 

 

測試session共享

 

同時啟動2個節點刷新頁面

 

 

 本文由用戶 ZHCRoxanna 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!