nginx+tomcat+memcache
tomcat1和tomcat2都需要安装以下配置
[root@tomcat-1 ~]# yum -y install gcc openssl-devel pcre-devel zlib-devel
[root@tomcat-1 ~]# tar xf libevent-2.0.15-stable.tar.gz
[root@tomcat-1 ~]# cd libevent-2.0.15-stable
[root@tomcat-1 libevent-2.0.15-stable]# ./configure --prefix=/usr/local/libevent && make && make install
[root@tomcat-1 ~]# tar xf memcached-1.4.5.tar.gz
[root@tomcat-1 ~]# cd memcached-1.4.5
[root@tomcat-1 memcached-1.4.5]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/ && make && make install
[root@tomcat-1 memcached-1.4.5]# ldconfig -v |grep libevent
libevent_pthreads-2.0.so.5 -> libevent_pthreads.so
libevent-2.0.so.5 -> libevent.so
libevent_extra-2.0.so.5 -> libevent_extra.so
libevent_core-2.0.so.5 -> libevent_core.so
libevent_openssl-2.0.so.5 -> libevent_openssl.so
libevent_extra-1.4.so.2 -> libevent_extra-1.4.so.2.1.3
libevent_core-1.4.so.2 -> libevent_core-1.4.so.2.1.3
libevent-1.4.so.2 -> libevent-1.4.so.2.1.3
[root@tomcat-1 memcached-1.4.5]# /usr/local/memcached/bin/memcached -u root -m 512M -n 10 -f 2 -d -vvv -c 512
/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
[root@localhost memcached-1.4.5]# vim /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/libevent/lib/
[root@localhost memcached-1.4.5]# ldconfig
[root@localhost memcached-1.4.5]# /usr/local/memcached/bin/memcached -u root -m 512M -n 10 -f 2 -d -vvv -c 512
选项:
-h #查看帮助信息
-p #指定memcached监听的端口号默认11211
-l #memcached服务器的ip地址
-u #memcached程序运行时使用的用户身份必须是root用户
-m #指定使用本机的多少物理内存存数据默认64M
-c #memcached服务的最大链接数
-vvv #显示详细信息
-n #chunk size 的最小空间是多少单位字节
-f #chunk size大小增长的倍数默认 1.25倍
-d #在后台启动
[root@tomcat-1 ~]# netstat -antp| grep :11211 #(检测memecached是否存活,memcacehd 端口为11211)
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 71559/memcached
tcp 0 0 :::11211 :::* LISTEN 71559/memcached
最后执行让Tomcat-1 Tomcat-2 通过(msm)连接到Memcached
mkdir session
cd session
将session包中的“*.jar复制到/usr/local/tomcat7/lib/ 下面
[root@tomcat-1 ~]# cp session/* /usr/local/tomcat7/lib/
cd session
scp * root@192.168.30.25:/usr/local/tomcat7/lib
编辑tomcat 配置文件连接指定的 memcached服务器
tomcat-1 和 tomcat-2 配置文件一模一样,都按照一下样例写
[root@tomcat-1 ~]# vim /usr/local/tomcat7/conf/context.xml
<Context>
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="memA:192.168.200.104:11211 memB:192.168.200.105:11211"
requestUrilgnorePattern=".*\(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>
[root@tomcat-2 ~]# vim /usr/local/tomcat7/conf/context.xml
<Context>
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="memA:192.168.200.104:11211 memB:192.168.200.105:11211"
requestUrilgnorePattern=".*\(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>
[root@tomcat-1 ~]# /usr/local/tomcat7/bin/shutdown.sh
[root@tomcat-1 ~]# /usr/local/tomcat7/bin/startup.sh
如果成功,tomcat与Memcached 端口会连在一起,前后有变化
Tomcat-1与Tomcat-2如下图
[root@tomcat-1 ~]# netstat -antp|grep java
tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 62496/java
tcp 0 0 :::8009 :::* LISTEN 62496/java
tcp 0 0 :::8080 :::* LISTEN 62496/java
tcp 0 0 ::ffff:192.168.200.10:28232 ::ffff:192.168.200.10:11211 ESTABLISHED 62496/java
tcp 0 0 ::ffff:192.168.200.10:28231 ::ffff:192.168.200.10:11211 ESTABLISHED 62496/java
tcp 0 0 ::ffff:192.168.200.10:28230 ::ffff:192.168.200.10:11211 ESTABLISHED 62496/java
tcp 0 0 ::ffff:192.168.200.10:28228 ::ffff:192.168.200.10:11211 ESTABLISHED 62496/java
tcp 0 0 ::ffff:192.168.200.10:28229 ::ffff:192.168.200.10:11211 ESTABLISHED 62496/java
[root@tomcat-1 ~]# netstat -antp|grep memcached
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 62402/memcached
tcp 0 0 192.168.200.103:11211 192.168.200.103:28230 ESTABLISHED 62402/memcached
tcp 45 0 192.168.200.103:11211 192.168.200.103:28228 ESTABLISHED 62402/memcached
tcp 0 0 192.168.200.103:11211 192.168.200.103:28232 ESTABLISHED 62402/memcached
tcp 0 0 192.168.200.103:11211 192.168.200.103:28229 ESTABLISHED 62402/memcached
tcp 0 0 192.168.200.103:11211 192.168.200.103:28231 ESTABLISHED 62402/memcached
tcp 0 0 :::11211 :::* LISTEN 62402/memcached
端口访问:nginx 服务器http://192.168.30.24,刷新两下可以看到端口的切换