NGINX + Tomcat + Memcached 集群搭建
环境说明:CentOS 6.5 + Java7 + Tomcat7 + Memcached 1.6.5 + Nginx1.6.2
环境搭建概述
1. 下载 并 安装Java 7
JDK7 下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
安装命令如下
# sudo rpm -ivh jdk-7u76-linux-x64.rpm
注:安装完成后使用 java -version 和 javac -version 测试安装结果,如有需要配置JAVA 环境变量
本人测试实际安装过程中,无需配置Java环境变量,安装完即可正常工作
如需配置,请参考 http://www.cnblogs.com/rilley/archive/2012/02/02/2335395.html
2. 下载并安装Tomcat 7
可参考 http://www.cnblogs.com/zhoulf/archive/2013/02/04/2891633.html
3. Install Nginx
在安装Ngin前,需要先安装PCRE, PCRE 安装时又需要 g++, gcc的支持
相应的版本可选择相当较新的版本,
可参考
http://www.kankanews.com/ICkengine/archives/103726.shtml
Nginx 安装后,如出现问题 可参考
http://www.linuxidc.com/Linux/2012-05/60003.htm
nginx 配置参考:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}4.Install memcached
下载地址及安装方法,请参照官网描述 http://www.memcached.org/downloads
同时也可参考 http://www.cnblogs.com/yixiwenwen/p/3574137.html
5.Tomcat and Memcached
必备的JAR包:
- memcached-session-manager-1.6.5.jar、memcached-session-manager-tc7-1.6.5(tomcat6 请选tc6)、javolution-5.5.1.jar、msm-javolution-serializer-1.6.5.jar、 spymemcached-2.10.3.jar
- couchbase-client-1.4.4.jar
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:localhost:11211"
requestUriIgnorePattern=".*/.(png|gif|jpg|css|js)$"
sessionBackupAsync="false"
sessionBackupTimeout="100"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
copyCollectionsForSerialization="false"/>