Session服务器之Memcached
关闭相关的安全机制
systemctl stop firewalld
iptables -F
setenforce 0
本实验用了三台虚拟机
两台安装Tomcat
一台安装nginx
一:在两台Tomcat上安装Memcached
两台都做同样的配置
[root@node1 ~]# yum -y install libevent memcached #用yum安装Memcached
二:开启服务
[root@node1 ~]# memcached -u root -m 512M -n 10 -f 2 -d -vvv -c 512 #启动Memcached服务
-h #查看帮助信息
-p #指定Memcached监听端口号 默认11211
-l #Memcached服务的IP地址
-u #Memcached程序运行时使用的用户身份必须是root用户
-m #指定使用本机的多少物理内存存储数据 默认64M
-c #Memcached服务的最大链接数
-vvv #显示详细信息
-n #chunk size的最小空间是多少单位字节
-f #chunk size大小增长的倍数 默认1.25倍
-d # 在后台运行
三:测试Memcached能否存取数据
[root@node1 ~]# telnet 192.168.200.12 11211
[root@node2 ~]# telnet 192.168.200.13 11211
Trying 192.168.200.12...
<30 new auto-negotiating client connection
Connected to 192.168.200.12.
Escape character is '^]'.
<30 set username 0 0 8 # 定义一个变量 username (0:标识符 0:过期时间 8:长度)
30: going from conn_parse_cmd to conn_nread
zhangsan #存入的值
> NOT FOUND username
>30 STORED
30: going from conn_nread to conn_write
30: going from conn_write to conn_new_cmd
30: going from conn_new_cmd to conn_waiting
30: going from conn_waiting to conn_read
STORED
get username #查看存入的值
30: going from conn_read to conn_parse_cmd
<30 get username
> FOUND KEY username
>30 sending key username
>30 END
30: going from conn_parse_cmd to conn_mwrite
30: going from conn_mwrite to conn_new_cmd
30: going from conn_new_cmd to conn_waiting
30: going from conn_waiting to conn_read
VALUE username 0 8
zhangsan
END
quit #退出
四:将文件上传
[root@node1 ~]# cd session/
[root@node1 session]# rz
javolution-5.5.1.jar minlog-1.2.jar
kryo-1.03.jar msm-javolution-serializer-1.5.1.jar
kryo-serializers-0.10.jar msm-kryo-serializer-1.6.4.jar
memcached-2.5.jar reflectasm-0.9.jar
memcached-session-manager-1.5.1.jar spymemcached-2.7.3.jar
memcached-session-manager-tc7-1.5.1.jar
[root@node1 session]# cd
memcachedNodes="memA:192.168.200.12:11211 memB:192.168.200.13:11211"
requestUrilgnorePattern=".*(ico|png|gif|jpg|css|js)$"transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>