centos6.7下ngnix1.8+tomcat8+memcached1.4.25 集群实现session共享

安装完centos后

一、更换国内源

[plain]  view plain  copy
  1. sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup  
  2. sudo vim /etc/yum.repos.d/CentOS-Base.repo  
内容如下

[plain]  view plain  copy
  1. # CentOS-Base.repo  
  2. #  
  3. # The mirror system uses the connecting IP address of the client and the  
  4. # update status of each mirror to pick mirrors that are updated to and  
  5. # geographically close to the client.  You should use this for CentOS updates  
  6. # unless you are manually picking other mirrors.  
  7. #  
  8. # If the mirrorlist= does not work for you, as a fall back you can try the   
  9. # remarked out baseurl= line instead.  
  10. #  
  11. #  
  12.    
  13. [base]  
  14. name=CentOS-$releasever - Base - mirrors.ustc.edu.cn  
  15. baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/  
  16. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os  
  17. gpgcheck=1  
  18. gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6  
  19.    
  20. #released updates   
  21. [updates]  
  22. name=CentOS-$releasever - Updates - mirrors.ustc.edu.cn  
  23. baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/  
  24. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates  
  25. gpgcheck=1  
  26. gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6  
  27.    
  28. #additional packages that may be useful  
  29. [extras]  
  30. name=CentOS-$releasever - Extras - mirrors.ustc.edu.cn  
  31. baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/  
  32. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras  
  33. gpgcheck=1  
  34. gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6  
  35.    
  36. #additional packages that extend functionality of existing packages  
  37. [centosplus]  
  38. name=CentOS-$releasever - Plus - mirrors.ustc.edu.cn  
  39. baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/  
  40. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus  
  41. gpgcheck=1  
  42. enabled=0  
  43. gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6  
  44.    
  45. #contrib - packages by Centos Users  
  46. [contrib]  
  47. name=CentOS-$releasever - Contrib - mirrors.ustc.edu.cn  
  48. baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/contrib/$basearch/  
  49. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib  
  50. gpgcheck=1  
  51. enabled=0  
  52. gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6  


[plain]  view plain  copy
  1. yum makecache  

备注:

可以开启ssh

[plain]  view plain  copy
  1. sudo chkconfig sshd on  
  2. sudo service sshd start  

安装jdk

删除旧的

[plain]  view plain  copy
  1. rpm -qa |grep java  
  2.  yum -y remove java-1.6.0-openjdk-1.6.0.35-1.13.7.1.el6_6.i686  
  3. yum -y remove java-1.7.0-openjdk-1.7.0.79-2.5.5.4.el6.i686  


[plain]  view plain  copy
  1. sudo yum -y install jdk-7u71-linux-i586.rpm   

修改/etc/profile添加

[plain]  view plain  copy
  1. export JAVA_HOME=/usr/java/jdk1.7.0_71  
  2. export PATH=$JAVA_HOME/bin:$PATH  
  3. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar  



二、下载并解压tomcat

[plain]  view plain  copy
  1. tar -zxvf apache-tomcat-8.0.30.tar.gz   
  2. mv apache-tomcat-8.0.30 /usr/local/tomcat1  

更改catalina.sh

[plain]  view plain  copy
  1. CATALINA_HOME=/usr/local/tomcat1  

备注:

[plain]  view plain  copy
  1. sudo yum install -y gcc gcc-c++ openssl libssl-dev  

三、下载并安装ngnix

[plain]  view plain  copy
  1. tar zxvf pcre-8.37.tar.gz   
  2. cd pcre-8.37  
  3. ./configure   
  4. make  
  5. sudo make install  
  6.   
  7. tar zxvf zlib-1.2.8.tar.gz   
  8. cd zlib-1.2.8  
  9. make  
  10. sudo make install  
  11.   
  12.   
  13. tar zxvf nginx-1.8.0.tar.gz   
  14. cd nginx-1.8.0  
  15. ./configure   
  16. make  
  17. sudo make install  


配置防火墙

[plain]  view plain  copy
  1. 1.sudo vim /etc/sysconfig/iptables  
  2. 2.在-A INPUT -j REJECT --reject-with icmp-host-prohibited  
  3. -A FORWARD -j REJECT --reject-with icmp-host-prohibited代码上面加入-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT  
  4. 3.sudo service iptables restart  


启动

sudo /usr/local/nginx/sbin/nginx 

问题:nginx error while loading shared libraries: libpcre.so.1

[plain]  view plain  copy
  1. 32位:  
  2. 1.ldd $(which /usr/local/nginx/sbin/nginx)发现是libpcre.so.1 => not found  
  3. 2. cd /lib/  
  4. 3. ln -s libpcre.so.0.0.1 libpcre.so.1  
  5. 4.重新启动sudo /usr/local/nginx/sbin/nginx   



配置ngnix

proxy.conf

[plain]  view plain  copy
  1. proxy_redirect          off;  
  2. proxy_set_header        Host $host;  
  3. proxy_set_header        X-Real-IP $remote_addr;  
  4. proxy_set_header        X-Forwarded-For   $proxy_add_x_forwarded_for;  
  5. client_max_body_size    10m;  
  6. client_body_buffer_size 128k;  
  7. proxy_connect_timeout   300;  
  8. proxy_send_timeout      300;  
  9. proxy_read_timeout      300;  
  10. proxy_buffer_size       4k;  
  11. proxy_buffers           4 32k;  
  12. proxy_busy_buffers_size 64k;  
  13. proxy_temp_file_write_size 64k;  
gzip.conf

[plain]  view plain  copy
  1. gzip               on;  
  2. gzip_min_length    1000;  
  3. gzip_types           text/plain text/css application/javascript application/x-javascript;  


ngnix.conf

[plain]  view plain  copy
  1. #user  nobody;  
  2. worker_processes  1;  
  3.   
  4. #error_log  logs/error.log;  
  5. #error_log  logs/error.log  notice;  
  6. #error_log  logs/error.log  info;  
  7.   
  8. #pid        logs/nginx.pid;  
  9.   
  10.   
  11. events {  
  12.     worker_connections  1024;  
  13. }  
  14.   
  15.   
  16. http {  
  17.     include       mime.types;  
  18.     default_type  application/octet-stream;  
  19.   
  20.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
  21.     #                  '$status $body_bytes_sent "$http_referer" '  
  22.     #                  '"$http_user_agent" "$http_x_forwarded_for"';  
  23.   
  24.     #access_log  logs/access.log  main;  
  25.   
  26.     sendfile        on;  
  27.     #tcp_nopush     on;  
  28.   
  29.     #keepalive_timeout  0;  
  30.     keepalive_timeout  65;  
  31.   
  32.     #gzip on;  
  33.     include    gzip.conf;  
  34.     include    proxy.conf;  
  35.   
  36.     upstream localhost{  
  37.       server localhost:8080;  
  38.       server localhost:8081;  
  39.     }  
  40.     server {  
  41.         listen       80;  
  42.         server_name  localhost;  
  43.   
  44.         #charset koi8-r;  
  45.   
  46.         #access_log  logs/host.access.log  main;  
  47.   
  48.         location / {  
  49.           #  root   html;  
  50.           #  index  index.html index.htm;  
  51.           proxy_connect_timeout 3;  
  52.           proxy_send_timeout      30;  
  53.           proxy_read_timeout      30;    
  54.           proxy_pass http://localhost;  
  55.         }  
  56.   
  57.         #error_page  404              /404.html;  
  58.   
  59.         # redirect server error pages to the static page /50x.html  
  60.         #  
  61.         error_page   500 502 503 504  /50x.html;  
  62.         location = /50x.html {  
  63.             root   html;  
  64.         }  
  65.   
  66.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
  67.         #  
  68.         #location ~ \.php$ {  
  69.         #    proxy_pass   http://127.0.0.1;  
  70.         #}  
  71.   
  72.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
  73.         #  
  74.         #location ~ \.php$ {  
  75.         #    root           html;  
  76.         #    fastcgi_pass   127.0.0.1:9000;  
  77.         #    fastcgi_index  index.php;  
  78.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  
  79.         #    include        fastcgi_params;  
  80.         #}  
  81.   
  82.         # deny access to .htaccess files, if Apache's document root  
  83.         # concurs with nginx's one  
  84.         #  
  85.         #location ~ /\.ht {  
  86.         #    deny  all;  
  87.         #}  
  88.     }  
  89.   
  90.   
  91.     # another virtual host using mix of IP-, name-, and port-based configuration  
  92.     #  
  93.     #server {  
  94.     #    listen       8000;  
  95.     #    listen       somename:8080;  
  96.     #    server_name  somename  alias  another.alias;  
  97.   
  98.     #    location / {  
  99.     #        root   html;  
  100.     #        index  index.html index.htm;  
  101.     #    }  
  102.     #}  
  103.   
  104.   
  105.     # HTTPS server  
  106.     #  
  107.     #server {  
  108.     #    listen       443 ssl;  
  109.     #    server_name  localhost;  
  110.   
  111.     #    ssl_certificate      cert.pem;  
  112.     #    ssl_certificate_key  cert.key;  
  113.   
  114.     #    ssl_session_cache    shared:SSL:1m;  
  115.     #    ssl_session_timeout  5m;  
  116.   
  117.     #    ssl_ciphers  HIGH:!aNULL:!MD5;  
  118.     #    ssl_prefer_server_ciphers  on;  
  119.   
  120.     #    location / {  
  121.     #        root   html;  
  122.     #        index  index.html index.htm;  
  123.     #    }  
  124.     #}  
  125.   
  126. }  

三、安装memcached

[plain]  view plain  copy
  1. tar zxvf memcached-1.4.25.tar.gz  
  2. /configure --prefix=/usr   
  3. make   
  4. udo make install   

启动

[plain]  view plain  copy
  1. /usr/local/bin/memcached -d -m 2048  -u root -l localhost -p 11211 -c 1024 -P /tmp/memcached.pid   
telnet localhost 11211

stats查看状态



四、复制一份tomcat2 用cp -Rp
改端口为8081

配置context.xml

[plain]  view plain  copy
  1. <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"    
  2.                     memcachedNodes="n1:localhost:11211"    
  3.                     sticky="false"    
  4.                     sessionBackupAsync="false"    
  5.                     lockingMode="auto"    
  6.                     requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"    
  7.                     transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"  
  8.                     />    

index.jsp

<%=session.getId()%>



访问时不断刷新就可以看到sessionID一样。表示成功


资源都在http://pan.baidu.com/s/1dDNu1f7

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值