nginx+tomcat7+redis session共享

1.安裝nginxhtml

wgethttp://sourceforge.net/settings/mirror_choices?projectname=pcre&filename=pcre/8.32/pcre-8.32.tar.gznginx

nginx download:c++

wgethttp://nginx.org/download/nginx-1.6.2.tar.gzredis

 

yum -y install gcc gcc-c++ autoconfautomake makeapache

yum -y install zlib zlib-devel opensslopenssl-develtomcat

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

groupadd -r nginxide

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

 

tar zxvf pcre-8.32.tar.gzspa

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  127.0.0.1;

  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>

<ValveclassName="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve"/>       

   <ManagerclassName="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共享

wKiom1bEIgzxzOoqAAAu5zfOLNE000.png

 

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

wKiom1bEIinAUXH0AAAwvNSSK_o779.png

wKiom1bEIirDimrxAAAxQjn4IYk031.png


 

 

wKiom1bEIj3RmRoMAAAu5zfOLNE296.png

相關文章
相關標籤/搜索