示例图

memcached 安装配置 菜鸟教程链接

Memcached 的 Windows 平台安装包 32位系统 1.4.4版本 64位系统 1.4.4版本

使用管理员权限运行以下命令:安装、启动、停止、卸载

c:\memcached\memcached.exe -d install
c:\memcached\memcached.exe -d start
c:\memcached\memcached.exe -d stop
c:\memcached\memcached.exe -d uninstall

修改 memcached 的内存配置 注册表

“HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached”

修改 ImagePath 为:

“c:\memcached\memcached.exe” -d runservice -m 512

-m 512 意思是设置 memcached 最大的缓存配置为512M。


memcached-session-manager 官方配置向导链接

Configure tomcat

https://repo1.maven.org/maven2/de/javakaffee/msm/
https://repo1.maven.org/maven2/net/spy/spymemcached/

下载以下jar放到tomcat lib下

memcached-session-manager-${version}.jar
memcached-session-manager-tc8-${version}.jar 
spymemcached-${version}.jar

maven获取必须的jar到WEB-INF lib 使用msm-kryo-serializer序列化

<dependency>
    <groupId>de.javakaffee.msm</groupId>
    <artifactId>msm-kryo-serializer</artifactId>
    <version>2.3.2</version>
    <scope>runtime</scope>
</dependency>

context.xml 配置

non-sticky sessions + kryo 模式配置

<Context>
  <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
    memcachedNodes="n1:host1.yourdomain.com:11211,n2:host2.yourdomain.com:11211"
    memcachedProtocol="binary"  
    sticky="false"  
    sessionBackupAsync="false"
    requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
    transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
    />
</Context>

nginx负载均衡 指定轮询几率,weight和访问比率成正比

upstream webmemcached{
  server 192.168.1.31:9100 weight=10;
  server 192.168.1.32:9100 weight=10;
}
server {
  listen       90;
  server_name  localhost;
  location / {
     proxy_pass http://webmemcached;
  }
}