tomcat session----memcache

安装memcache

[[email protected] ~]# yum info memcached

已加载插件:fastestmirror, refresh-packagekit, security

Loading mirror speeds from cached hostfile

* base: mirrors.opencas.cn

* epel: mirror.premi.st

* extras: mirrors.nwsuaf.edu.cn

* updates: mirrors.nwsuaf.edu.cn

可安装的软件包

Name        : memcached

Arch        : x86_64

Version     : 1.4.4

Release     : 3.el6

Size        : 68 k

Repo        : base

Summary     : High Performance, Distributed Memory Object Cache

URL         : http://www.memcached.org/

License     : BSD

Description : memcached is a high-performance, distributed memory object caching

: system, generic in nature, but intended for use in speeding up dynamic

: web applications by alleviating database load.

[[email protected] ~]# yum install -y memcached

[[email protected] ~]# rpm -q memcached

memcached-1.4.4-3.el6.x86_64

[[email protected] ~]# rpm -ql memcached

/etc/rc.d/init.d/memcached

/etc/sysconfig/memcached

/usr/bin/memcached

/usr/bin/memcached-tool

/usr/share/doc/memcached-1.4.4

/usr/share/doc/memcached-1.4.4/AUTHORS

/usr/share/doc/memcached-1.4.4/CONTRIBUTORS

/usr/share/doc/memcached-1.4.4/COPYING

/usr/share/doc/memcached-1.4.4/ChangeLog

/usr/share/doc/memcached-1.4.4/NEWS

/usr/share/doc/memcached-1.4.4/README

/usr/share/doc/memcached-1.4.4/protocol.txt

/usr/share/doc/memcached-1.4.4/readme.txt

/usr/share/doc/memcached-1.4.4/threads.txt

/usr/share/man/man1/memcached.1.gz

/var/run/memcached

查看配置文件

[[email protected] ~]# cat /etc/sysconfig/memcached

PORT="11211"

USER="memcached"

MAXCONN="1024"

CACHESIZE="64"

OPTIONS=""

[[email protected] ~]# man memcached---------查看使用用法

[[email protected] ~]# memcached -f 1.25 -u memcached -vv---------(-f 增长因子;-u 用户)

slab class   1: chunk size        96 perslab   10922

slab class   2: chunk size       120 perslab    8738

slab class   3: chunk size       152 perslab    6898

slab class   4: chunk size       192 perslab    5461

slab class   5: chunk size       240 perslab    4369

slab class   6: chunk size       304 perslab    3449

slab class   7: chunk size       384 perslab    2730

slab class   8: chunk size       480 perslab    2184

slab class   9: chunk size       600 perslab    1747

slab class  10: chunk size       752 perslab    1394

slab class  11: chunk size       944 perslab    1110

slab class  12: chunk size      1184 perslab     885

slab class  13: chunk size      1480 perslab     708

slab class  14: chunk size      1856 perslab     564

slab class  15: chunk size      2320 perslab     451

slab class  16: chunk size      2904 perslab     361

slab class  17: chunk size      3632 perslab     288

slab class  18: chunk size      4544 perslab     230

slab class  19: chunk size      5680 perslab     184

slab class  20: chunk size      7104 perslab     147

slab class  21: chunk size      8880 perslab     118

slab class  22: chunk size     11104 perslab      94

slab class  23: chunk size     13880 perslab      75

slab class  24: chunk size     17352 perslab      60

slab class  25: chunk size     21696 perslab      48

slab class  26: chunk size     27120 perslab      38

slab class  27: chunk size     33904 perslab      30

slab class  28: chunk size     42384 perslab      24

slab class  29: chunk size     52984 perslab      19

slab class  30: chunk size     66232 perslab      15

slab class  31: chunk size     82792 perslab      12

slab class  32: chunk size    103496 perslab      10

slab class  33: chunk size    129376 perslab       8

slab class  34: chunk size    161720 perslab       6

slab class  35: chunk size    202152 perslab       5

slab class  36: chunk size    252696 perslab       4

slab class  37: chunk size    315872 perslab       3

slab class  38: chunk size    394840 perslab       2

slab class  39: chunk size    493552 perslab       2

slab class  40: chunk size    616944 perslab       1

slab class  41: chunk size    771184 perslab       1

slab class  42: chunk size   1048576 perslab       1

启动

[[email protected] ~]# service memcached start

正在启动 memcached:                                       [确定]

[[email protected] ~]# ss -tunl

Netid State      Recv-Q Send-Q                             Local Address:Port                               Peer Address:Port

udp   UNCONN     0      0                                              *:11211                                         *:*

udp   UNCONN     0      0                                              *:631                                           *:*

udp   UNCONN     0      0                                192.168.112.120:123                                           *:*

udp   UNCONN     0      0                                      127.0.0.1:123                                           *:*

udp   UNCONN     0      0                                              *:123                                           *:*

udp   UNCONN     0      0                                             :::11211                                        :::*

udp   UNCONN     0      0                        fe80::20c:29ff:fed2:5bd:123                                          :::*

udp   UNCONN     0      0                                            ::1:123                                          :::*

udp   UNCONN     0      0                                             :::123                                          :::*

tcp   LISTEN     0      128                                           :::11211                                        :::*

tcp   LISTEN     0      128                                            *:11211                                         *:*

tcp   LISTEN     0      128                                           :::22                                           :::*

tcp   LISTEN     0      128                                            *:22                                            *:*

tcp   LISTEN     0      128                                    127.0.0.1:631                                           *:*

tcp   LISTEN     0      128                                          ::1:631                                          :::*

tcp   LISTEN     0      100                                          ::1:25                                           :::*

tcp   LISTEN     0      100                                    127.0.0.1:25                                            *:*

tcp   LISTEN     0      128                                    127.0.0.1:6010                                          *:*

tcp   LISTEN     0      128                                          ::1:6010                                         :::*

tcp   LISTEN     0      128                                    127.0.0.1:6011                                          *:*

tcp   LISTEN     0      128                                          ::1:6011                                         :::*

[[email protected] ~]# telnet 127.0.0.1 11211

Trying 127.0.0.1...

Connected to 127.0.0.1.

Escape character is ‘^]‘.

stats

STAT pid 24034

STAT uptime 792

STAT time 1451025193

STAT version 1.4.4

STAT pointer_size 64

STAT rusage_user 0.016997

STAT rusage_system 0.043993

STAT curr_connections 10

STAT total_connections 11

STAT connection_structures 11

STAT cmd_get 0

STAT cmd_set 0

STAT cmd_flush 0

STAT get_hits 0

STAT get_misses 0

STAT delete_misses 0

STAT delete_hits 0

STAT incr_misses 0

STAT incr_hits 0

STAT decr_misses 0

STAT decr_hits 0

STAT cas_misses 0

STAT cas_hits 0

STAT cas_badval 0

STAT auth_cmds 0

STAT auth_errors 0

STAT bytes_read 7

STAT bytes_written 0

STAT limit_maxbytes 67108864

STAT accepting_conns 1

STAT listen_disabled_num 0

STAT threads 4

STAT conn_yields 0

STAT bytes 0

set mykey 0 30 11

hello hey1w

STORED

get mykey

VALUE mykey 0 11

hello hey1w

END

set testkey 0 120 1

1

STORED

incr testkey 1

2

incr test 3

NOT_FOUND

incr testkey 3

5

decr testkey 2

3

get testkey

VALUE testkey 0 1

3

END

get mykey

END

安装PHP

[[email protected] ~]# yum install php php-devel -y

[[email protected] ~]# yum groupinstall "Development Tools" "Server Platform Development" -y

[[email protected] ~]# ls

anaconda-ks.cfg                   vmware-tools-distrib  文档

epel-release-latest-6.noarch.rpm  公共的                下载

install.log                       模板                  音乐

install.log.syslog                视频                  桌面

memcache-2.2.7.tgz                图片

[[email protected] ~]# tar -xf memcache-2.2.7.tgz

[[email protected] ~]# cd memcache-2.2.7

[[email protected] memcache-2.2.7]# ls

config9.m4                  memcache.php

config.m4                   memcache_queue.c

config.w32                  memcache_queue.h

CREDITS                     memcache_session.c

example.php                 memcache_standard_hash.c

memcache.c                  php_memcache.h

memcache_consistent_hash.c  README

memcache.dsp

安装PHP扩展

[[email protected] ~]# tar -xf memcache-2.2.7.tgz

[[email protected] ~]# cd memcache-2.2.7

[[email protected] memcache-2.2.7]# ls

config9.m4                  memcache.php

config.m4                   memcache_queue.c

config.w32                  memcache_queue.h

CREDITS                     memcache_session.c

example.php                 memcache_standard_hash.c

memcache.c                  php_memcache.h

memcache_consistent_hash.c  README

memcache.dsp

[[email protected] memcache-2.2.7]# phpize----是有php-devel提供

Configuring for:

PHP Api Version:         20090626

Zend Module Api No:      20090626

Zend Extension Api No:   220090626

[[email protected] memcache-2.2.7]# ls

acinclude.m4    ltmain.sh

aclocal.m4      Makefile.global

autom4te.cache  memcache.c

build           memcache_consistent_hash.c

config9.m4      memcache.dsp

config.guess    memcache.php

config.h.in     memcache_queue.c

config.m4       memcache_queue.h

config.sub      memcache_session.c

configure       memcache_standard_hash.c

configure.in    missing

config.w32      mkinstalldirs

CREDITS         php_memcache.h

example.php     README

install-sh      run-tests.php

[[email protected] memcache-2.2.7]# which php-config

/usr/bin/php-config

[[email protected] memcache-2.2.7]# ./configure --with-php-config=/usr/bin/php-config

[[email protected] memcache-2.2.7]# make && make install

[[email protected] memcache-2.2.7]# ls /usr/lib64/php/modules/

curl.so  fileinfo.so  json.so  memcache.so  phar.so  zip.so

[[email protected] memcache-2.2.7]# vim /etc/php.ini

918 ; syntax:

919 ;

920 ;   extension=modulename.extension

921     extension=memcache.so

922

923 ; For example

[[email protected] memcache-2.2.7]# service httpd restart

停止 httpd:                                               [失败]

正在启动 httpd:httpd: apr_sockaddr_info_get() failed for node120.zye.com

httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName

[确定

[[email protected] memcache-2.2.7]# vim /var/www/html/index.php

<?php

phpinfo ();

?>

添加test.php

[[email protected] memcache-2.2.7]# vim /var/www/html/test.php

1 <?php

2     $mem = new Memcache;

3     $mem->connect("127.0.0.1", 11211)  or die("Could not conn    ect");

4

5     $version = $mem->getVersion();

6     echo "Server‘s version: ".$version."<br/>\n";

7

8     $mem->set(‘hellokey‘, ‘Hello World‘, 0, 600) or die("Fail    ed to save data at the memcached server");

9     echo "Store data in the cache (data will expire in 600 se    conds)<br/>\n";

10

11     $get_result = $mem->get(‘hellokey‘);

12     echo "$get_result is from memcached server.";

13 ?>

[[email protected] memcache-2.2.7]# telnet 127.0.0.1 11211

Trying 127.0.0.1...

Connected to 127.0.0.1.

Escape character is ‘^]‘.

get hellokey

VALUE hellokey 0 11

Hello World

END

quit

memcache拥有php的管理界面

[[email protected] memcache-2.2.7]# yum list all \*phpM\*

已加载插件:fastestmirror, refresh-packagekit, security

Loading mirror speeds from cached hostfile

* base: mirrors.skyshe.cn

* epel: mirror.premi.st

* extras: ftp.sjtu.edu.cn

* updates: mirrors.skyshe.cn

可安装的软件包

php-PHPMailer.noarch             5.2.2-1.el6                 epel

php-channel-phpmd.noarch         1.3-3.el6                   epel

php-phpmd-PHP-PMD.noarch         1.4.0-1.el6                 epel

phpMemcachedAdmin.noarch         1.2.2-5.svn262.el6          epel

phpMyAdmin.noarch                4.0.10.11-1.el6             epe

[[email protected] memcache-2.2.7]# yum install phpMemcachedAdmin -y

[[email protected] memcache-2.2.7]# rpm -ql phpMemcachedAdmin

etc/httpd/conf.d/phpMemcachedAdmin.conf

/etc/phpMemcachedAdmin

/etc/phpMemcachedAdmin/Memcache.php

/usr/share/doc/phpMemcachedAdmin-1.2.2

/usr/share/doc/phpMemcachedAdmin-1.2.2/LICENSE

/usr/share/phpMemcachedAdmin

/usr/share/phpMemcachedAdmin/Library

/usr/share/phpMemcachedAdmin/Library/Command

/usr/share/phpMemcachedAdmin/Library/Command/Factory.php

/usr/share/phpMemcachedAdmin/Library/Command/Interface.php

/usr/share/phpMemcachedAdmin/Library/Command/Memcache.php

/usr/share/phpMemcachedAdmin/Library/Command/Memcached.php

/usr/share/phpMemcachedAdmin/Library/Command/Server.php

/usr/share/phpMemcachedAdmin/Library/Configuration

/usr/share/phpMemcachedAdmin/Library/Configuration/Loader.php

/usr/share/phpMemcachedAdmin/Library/Data

/usr/share/phpMemcachedAdmin/Library/Data/Analysis.php

/usr/share/phpMemcachedAdmin/Library/Data/Error.php

/usr/share/phpMemcachedAdmin/Library/Data/Version.php

/usr/share/phpMemcachedAdmin/Library/HTML

/usr/share/phpMemcachedAdmin/Library/HTML/Components.php

/usr/share/phpMemcachedAdmin/Library/Loader.php

/usr/share/phpMemcachedAdmin/Public

/usr/share/phpMemcachedAdmin/Public/Images

/usr/share/phpMemcachedAdmin/Public/Images/635855.png

/usr/share/phpMemcachedAdmin/Public/Images/b5463f.png

/usr/share/phpMemcachedAdmin/Public/Scripts

/usr/share/phpMemcachedAdmin/Public/Scripts/Script.js

/usr/share/phpMemcachedAdmin/Public/Styles

/usr/share/phpMemcachedAdmin/Public/Styles/Style.css

/usr/share/phpMemcachedAdmin/View

/usr/share/phpMemcachedAdmin/View/Commands

/usr/share/phpMemcachedAdmin/View/Commands/Commands.tpl

/usr/share/phpMemcachedAdmin/View/Configure

/usr/share/phpMemcachedAdmin/View/Configure/Configure.tpl

/usr/share/phpMemcachedAdmin/View/Footer.tpl

/usr/share/phpMemcachedAdmin/View/Header.tpl

/usr/share/phpMemcachedAdmin/View/LiveStats

/usr/share/phpMemcachedAdmin/View/LiveStats/Frame.tpl

/usr/share/phpMemcachedAdmin/View/LiveStats/Stats.tpl

/usr/share/phpMemcachedAdmin/View/Stats

/usr/share/phpMemcachedAdmin/View/Stats/Error.tpl

/usr/share/phpMemcachedAdmin/View/Stats/Items.tpl

/usr/share/phpMemcachedAdmin/View/Stats/Slabs.tpl

/usr/share/phpMemcachedAdmin/View/Stats/Stats.tpl

/usr/share/phpMemcachedAdmin/commands.php

/usr/share/phpMemcachedAdmin/configure.php

/usr/share/phpMemcachedAdmin/index.php

/usr/share/phpMemcachedAdmin/stats.php

/var/lib/phpMemcachedAdmin

/var/lib/phpMemcachedAdmin/Temp

[[email protected] memcache-2.2.7]# vim /etc/httpd/conf.d/phpMemcachedAdmin.conf

1 # phpMemcachedAdmin - Graphic stand-alone administration for     memcached to monitor and debug purpose

2 #

3 # Allows only localhost by default

4

5 Alias /phpMemcachedAdmin /usr/share/phpMemcachedAdmin

6 Alias /phpmemcachedadmin /usr/share/phpMemcachedAdmin

7

8 <Directory /usr/share/phpMemcachedAdmin/>

9    <IfModule mod_authz_core.c>

10      # Apache 2.4

11      <RequireAny>

12        Require local

13      </RequireAny>

14    </IfModule>

15    <IfModule !mod_authz_core.c>

16      # Apache 2.2

17      Order Deny,Allow

18      Allow from All

19    </IfModule>

20 </Directory>

[[email protected] memcache-2.2.7]# service httpd restart

停止 httpd:                                               [确定]

正在启动 httpd:httpd: Could not reliably determine the server‘s fully qualified domain name, using node120.zye.com for ServerName

[确定

时间: 2024-10-19 22:07:53

tomcat session----memcache的相关文章

Apache+Tomcat+Session+Memcache 高性能群集搭建

一.拓扑图 二.环境安装 安装memcached的直接yum [[email protected] ~]# yum -y install memcached [[email protected] ~]# service memcached start Starting memcached:                                        [  OK  ] [[email protected] ~]# ss -anlpt | grep memcached LISTEN

Tomcat中memcache的session共享

安装tomcat,jdk,memcache等步骤省略.下面说说tomcat服务中配置memcache的session共享 首先下载tomcat支撑memcache的jar包 具体包名为kryo-1.04.jar   memcached-session-manager-tc6-1.5.1.jar  kryo-serializers-0.9.jar   minlog-1.2.jar   memcached-2.5.jar   msm-kryo-serializer-1.5.1.jar   memca

Nginx+Memcached+Tomcat session会话共享

服务器说明: 192.168.1.8 tomcat1 memcached(虚拟机1) 192.168.1.9 tomcat2(虚拟机2) 192.168.1.200 nginx (本机) 对于tomcat+nginx的配置请参考博客:[Nginx-反向代理服务器]实践篇(三)之Tomcat+Nginx搭建集群 接下来我们来安装memcached,注意linux系统的用户权限问题 1.分别把memcached和libevent下载回来,放到/usr/src目录下: # cd /usr/src# w

Nginx+Tomcat+Keepalived+Memcache 负载均衡动静分离技术

一.概述 Nginx 作负载均衡器的优点许多,简单概括为: ①实现了可弹性化的架构,在压力增大的时候可以临时添加Tomcat服务器添加到这个架构里面去; ②upstream具有负载均衡能力,可以自动判断下面的机器,并且自动踢出不能正常提供服务的机器: Keepalived 可实现 Nginx负载均衡器双机互备,任意一台机器发生故障,对方都能够将虚拟IP接管过去. Memcache可以实现Tomcat服务器的Sission共享整个拓补如下: 注意: 1.由于服务器有限,IP相同的为同一台机.只是端

Nginx+Tomcat+Keepalived+Memcache负载均衡动离分离技术

一.概述 Nginx 作负载均衡器的优点许多,简单概括为: ①实现了可弹性化的架构,在压力增大的时候可以临时添加Tomcat服务器添加到这个架构里面去; ②upstream具有负载均衡能力,可以自动判断下面的机器,并且自动踢出不能正常提供服务的机器: Keepalived 可实现 Nginx负载均衡器双机互备,任意一台机器发生故障,对方都能够将虚拟IP接管过去. Memcache可以实现Tomcat服务器的Sission共享整个拓补如下: 注意: 1.由于服务器有限,IP相同的为同一台机.只是端

Nginx+tomcat session cluster会话保持实验

Nginx+tomcat session cluster会话保持实验 实验要求: 1.nginx+tomcat 负载均衡 2.会话保持 实验拓扑 ip网络规划 Nginxnode2:172.16.76.20 tomcatAnode3:172.16.76.30 tomcatBnode4:172.16.76.40 基础配置 node2: [[email protected]~]# yum install nginx –y    node3:     [[email protected]~]# yum

第四十四课 tomcat负载均衡群集、tomcat session群集

tomcat负载均衡集群的实现 tomcat  session集群 tomcat session  server及jvm参数调整

tomcat session会话保持实验-之Nginx+tomcat+memcached

tomcat session会话保持实验-之Nginx+tomcat+memcached 实验要求 1.nginx+tomcat 负载均衡 2.memcached 会话保持 实验拓扑   ip网络规划 Nginxnode2:172.16.76.20 tomcatAnode3:172.16.76.30  memcached tomcatBnode4:172.16.76.40  memcached 基础配置   node2 [[email protected]~]# yum install ngin

实战项目memcached+tomcat+session+nginx在工作中的应用和配置

环境介绍:公司根据实际需要搭建一个购物网站,当用户购物时可以 将不同商品,放到同一个购物车中进行同时付款. 环境的搭建: 外网用户  IP地址:1.1.1.1  主机名:fanxiaohui  用户访问网站http://www.taobao.com 使用nginx实现负载均衡,由于网页是用JAVA开发的所以选用tomcat搭建网站服务,由于用户在购物时http是一个无状态的协议,不同的商品都是一个新的连接,默认不会把几个商品放到同一个购物车中,无法进行统一结账,为了能使服务器能够认识是同一个客户

基于memcached-session-manager的tomcat session共享集群

MSM的特性: a.支持tomcat 6,tomcat 7,tomcat 8 b.支持sticky session或no-sticky session c.无单点故障 d.tomcat故障转移 e.memcached故障转移 f.附带串行化插件 g.支持异步session存储,拥有更快的性能 sticky sessions粘性会话: 安装了MSM的tomcat会优先使用本机内存保存session,当一个请求结束后,MSM会把session发送到memcached节点上存放以作备份,第二次请求时,