k-v形式的:memcached、redis 适合储存用户信息,比如会话、配置文件、参数、购物车等等。这些信息一般都和ID(键)挂钩,这种情景下键值数据库是个很好的选择。
文档数据库:mongodb 将数据以文档的形式储存。每个文档都是一系列数据项的集合。每个数据项都有一个名称与对应的值,值既可以是简单的数据类型,如字符串、数字和日期等;也可以是复杂的类型,如有序列表和关联对象。数据存储的最小单位是文档,同一个表中存储的文档属性可以是不同的,数据可以使用XML、JSON或者JSONB等多种形式存储。
列存储 Hbase
图 Neo4J、Infinite Graph、OrientDB
MemCache是一个自由、源码开放、高性能、分布式的分布式内存对象缓存系统,用于动态Web应用以减轻数据库的负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高了网站访问的速度。MemCaChe是一个存储键值对的HashMap,在内存中对任意的数据(比如字符串、对象等)所使用的key-value存储,数据可以来自数据库调用、API调用,或者页面渲染的结果。MemCache设计理念就是小而强大,它简单的设计促进了快速部署、易于开发并解决面对大规模的数据缓存的许多难题,而所开放的API使得MemCache能用于Java、C/C++/C#、Perl、Python、PHP、Ruby等大部分流行的程序语言。
另外,说一下MemCache和MemCached的区别
1、MemCache是项目的名
2、MemCached是MemCache服务器端可以执行文件的名称
安装 yum install -y memcached libmemcached libevent
配置文件: /etc/sysconfig/memcached 可以配置参数
加上监听的ip,可以把OPTIONS="" 改为OPTIONS=“127.0.0.1”
其中-m指定memcached分配内存
-c指定最大并发数
-u指定运行memcached服务的用户
[root@linux-001 ~]# yum install -y memcached
已加载插件:fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.yun-idc.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 memcached.x86_64.0.1.4.15-10.el7_3.1 将被 安装
--> 解决依赖关系完成
依赖关系解决
================================================================================================================================================================================================================
Package 架构 版本 源 大小
================================================================================================================================================================================================================
正在安装:
memcached x86_64 1.4.15-10.el7_3.1 base 85 k
事务概要
================================================================================================================================================================================================================
安装 1 软件包
总下载量:85 k
安装大小:176 k
Downloading packages:
memcached-1.4.15-10.el7_3.1.x86_64.rpm | 85 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : memcached-1.4.15-10.el7_3.1.x86_64 1/1
验证中 : memcached-1.4.15-10.el7_3.1.x86_64 1/1
已安装:
memcached.x86_64 0:1.4.15-10.el7_3.1
完毕!
查看memcached的配置文件:
[root@linux-001 ~]# cat /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""
[root@linux-001 ~]# memcached-tool 127.0.0.1:11211 stats
#127.0.0.1:11211 Field Value
accepting_conns 1
auth_cmds 0
auth_errors 0
bytes 0
bytes_read 7
bytes_written 0
cas_badval 0
cas_hits 0
cas_misses 0
cmd_flush 0
cmd_get 0
cmd_set 0
cmd_touch 0
conn_yields 0
connection_structures 11
curr_connections 10
curr_items 0
decr_hits 0
decr_misses 0
delete_hits 0
delete_misses 0
evicted_unfetched 0
evictions 0
expired_unfetched 0
get_hits 0
get_misses 0
hash_bytes 524288
hash_is_expanding 0
hash_power_level 16
incr_hits 0
incr_misses 0
libevent 2.0.21-stable
limit_maxbytes 67108864
listen_disabled_num 0
pid 10403
pointer_size 64
reclaimed 0
reserved_fds 20
rusage_system 0.012161
rusage_user 0.002211
threads 4
time 1562805264
total_connections 11
total_items 0
touch_hits 0
touch_misses 0
uptime 63
version 1.4.15
nc命令需要安装nc软件
[root@linux-001 ~]# yum install -y nc
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* epel: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 nmap-ncat.x86_64.2.6.40-16.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
==================================================================================================================================================
Package 架构 版本 源 大小
==================================================================================================================================================
正在安装:
nmap-ncat x86_64 2:6.40-16.el7 base 206 k
事务概要
==================================================================================================================================================
安装 1 软件包
总下载量:206 k
安装大小:423 k
Downloading packages:
nmap-ncat-6.40-16.el7.x86_64.rpm | 206 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : 2:nmap-ncat-6.40-16.el7.x86_64 1/1
验证中 : 2:nmap-ncat-6.40-16.el7.x86_64 1/1
已安装:
nmap-ncat.x86_64 2:6.40-16.el7
完毕!
使用nc查看memcache状态
[root@linux-001 ~]# echo stats |nc 127.0.0.1 11211
STAT pid 10403
STAT uptime 112
STAT time 1562805313
STAT version 1.4.15
STAT libevent 2.0.21-stable
STAT pointer_size 64
STAT rusage_user 0.003569
STAT rusage_system 0.014278
STAT curr_connections 10
STAT total_connections 12
STAT connection_structures 11
STAT reserved_fds 20
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 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 touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 13
STAT bytes_written 1024
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT evictions 0
STAT reclaimed 0
END
[root@linux-001 ~]#
memstat 需要安装 libmemcached 包
[root@linux-001 ~]# yum install -y libmemcached
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* epel: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 libmemcached.x86_64.0.1.0.16-5.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
==================================================================================================================================================
Package 架构 版本 源 大小
==================================================================================================================================================
正在安装:
libmemcached x86_64 1.0.16-5.el7 base 237 k
事务概要
==================================================================================================================================================
安装 1 软件包
总下载量:237 k
安装大小:677 k
Downloading packages:
libmemcached-1.0.16-5.el7.x86_64.rpm | 237 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : libmemcached-1.0.16-5.el7.x86_64 1/1
验证中 : libmemcached-1.0.16-5.el7.x86_64 1/1
已安装:
libmemcached.x86_64 0:1.0.16-5.el7
完毕!
查看memcache状态
[root@linux-001 ~]# memstat --servers=127.0.0.1:11211
Server: 127.0.0.1 (11211)
pid: 10403
uptime: 260
time: 1562805461
version: 1.4.15
libevent: 2.0.21-stable
pointer_size: 64
rusage_user: 0.004755
rusage_system: 0.020606
curr_connections: 10
total_connections: 13
connection_structures: 11
reserved_fds: 20
cmd_get: 0
cmd_set: 0
cmd_flush: 0
cmd_touch: 0
get_hits: 0
get_misses: 0
delete_misses: 0
delete_hits: 0
incr_misses: 0
incr_hits: 0
decr_misses: 0
decr_hits: 0
cas_misses: 0
cas_hits: 0
cas_badval: 0
touch_hits: 0
touch_misses: 0
auth_cmds: 0
auth_errors: 0
bytes_read: 30
bytes_written: 2069
limit_maxbytes: 67108864
accepting_conns: 1
listen_disabled_num: 0
threads: 4
conn_yields: 0
hash_power_level: 16
hash_bytes: 524288
hash_is_expanding: 0
bytes: 0
curr_items: 0
total_items: 0
expired_unfetched: 0
evicted_unfetched: 0
evictions: 0
reclaimed: 0
[root@linux-001 ~]#
[root@linux-001 ~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
set key1 1 100 2
ab
STORED
get key1
VALUE key1 1 2
ab
END
^]
telnet> quit
Connection closed.
[root@linux-001 ~]#
数据导出
[root@linux-001 ~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
set key 12 0 6
xihaji
STORED
get key
VALUE key 12 6
xihaji
END
^]
telnet> quit
Connection closed.
[root@linux-001 ~]# memcached-tool 127.0.0.1:11211 dump > 2.txt
Dumping memcache contents
Number of buckets: 1
Number of items : 1
Dumping bucket 1 - 1 total items
[root@linux-001 ~]# cat 2.txt
add key 12 1562806267 6
xihaji
[root@linux-001 ~]#
数据导入,虽然我们在定义key的时候设置了key的过期是0,不过期,但是我们在导出memcache的时候,会给这个key加一个时间戳,这个时间戳其实是在创建key的时候的时间戳。通过上面我们可以了解到,如果说数据过了这个时间戳,memcache就会把这个数据丢掉。这样我们是无法把这个数据导入的。
[root@linux-001 ~]# date +%s -d'+1 day'
1562893113
[root@linux-001 ~]# vim 2.txt
add key 12 1562893113 6
xihaji
[root@linux-001 ~]# systemctl restart memcached.service
[root@linux-001 ~]# nc 127.0.0.1 11211 < 2.txt
STORED
[root@linux-001 ~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key
VALUE key 12 6
xihaji
END
^]
telnet> quit
Connection closed.
[root@linux-001 ~]#
下载地址: http://pecl.php.net/package/memcache
[root@linux-02 ~]# cd /usr/local/src/
[root@linux-02 src]# ls
apache-tomcat-9.0.20 mysql-5.6.43-linux-glibc2.12-x86_64 nginx-1.16.0.tar.gz
apache-tomcat-9.0.20.tar.gz mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz php-5.6.39
jdk-8u211-linux-x64.tar.gz mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz php-5.6.39.tar.bz2
mariadb-10.2.23-linux-x86_64.tar.gz nginx-1.16.0 php-7.3.0.tar.bz2
[root@linux-02 src]#
[root@linux-02 src]#
[root@linux-02 src]# wget http://pecl.php.net/get/memcache-3.0.8.tgz
--2019-07-11 23:10:20-- http://pecl.php.net/get/memcache-3.0.8.tgz
正在解析主机 pecl.php.net (pecl.php.net)... 104.236.228.160
正在连接 pecl.php.net (pecl.php.net)|104.236.228.160|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:70523 (69K) [application/octet-stream]
正在保存至: “memcache-3.0.8.tgz”
100%[=========================================================================================>] 70,523 41.6KB/s 用时 1.7s
2019-07-11 23:10:22 (41.6 KB/s) - 已保存 “memcache-3.0.8.tgz” [70523/70523])
[root@linux-02 src]# ls
apache-tomcat-9.0.20 memcache-3.0.8.tgz nginx-1.16.0 php-7.3.0.tar.bz2
apache-tomcat-9.0.20.tar.gz mysql-5.6.43-linux-glibc2.12-x86_64 nginx-1.16.0.tar.gz
jdk-8u211-linux-x64.tar.gz mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz php-5.6.39
mariadb-10.2.23-linux-x86_64.tar.gz mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz php-5.6.39.tar.bz2
[root@linux-02 src]# tar -zxvf memcache-3.0.8.tgz
package.xml
memcache-3.0.8/config.m4
memcache-3.0.8/config9.m4
memcache-3.0.8/config.w32
memcache-3.0.8/CREDITS
memcache-3.0.8/LICENSE
memcache-3.0.8/example.php
memcache-3.0.8/memcache.c
memcache-3.0.8/memcache_pool.c
memcache-3.0.8/memcache_queue.c
memcache-3.0.8/memcache_session.c
memcache-3.0.8/memcache_ascii_protocol.c
memcache-3.0.8/memcache_binary_protocol.c
memcache-3.0.8/memcache_standard_hash.c
memcache-3.0.8/memcache_consistent_hash.c
memcache-3.0.8/memcache.dsp
memcache-3.0.8/php_memcache.h
memcache-3.0.8/memcache_pool.h
memcache-3.0.8/memcache_queue.h
memcache-3.0.8/README
memcache-3.0.8/memcache.php
memcache-3.0.8/tests/001.phpt
memcache-3.0.8/tests/002.phpt
memcache-3.0.8/tests/003.phpt
memcache-3.0.8/tests/004.phpt
memcache-3.0.8/tests/005.phpt
memcache-3.0.8/tests/006.phpt
memcache-3.0.8/tests/007.phpt
memcache-3.0.8/tests/008.phpt
memcache-3.0.8/tests/009.phpt
memcache-3.0.8/tests/010.phpt
memcache-3.0.8/tests/011.phpt
memcache-3.0.8/tests/012.phpt
memcache-3.0.8/tests/013.phpt
memcache-3.0.8/tests/014.phpt
memcache-3.0.8/tests/015.phpt
memcache-3.0.8/tests/016.phpt
memcache-3.0.8/tests/017.phpt
memcache-3.0.8/tests/018.phpt
memcache-3.0.8/tests/019a.phpt
memcache-3.0.8/tests/019.phpt
memcache-3.0.8/tests/020.phpt
memcache-3.0.8/tests/021.phpt
memcache-3.0.8/tests/022a.phpt
memcache-3.0.8/tests/022.phpt
memcache-3.0.8/tests/023.phpt
memcache-3.0.8/tests/024a.phpt
memcache-3.0.8/tests/024.phpt
memcache-3.0.8/tests/025.phpt
memcache-3.0.8/tests/026.phpt
memcache-3.0.8/tests/027a.phpt
memcache-3.0.8/tests/027.phpt
memcache-3.0.8/tests/028.phpt
memcache-3.0.8/tests/029.phpt
memcache-3.0.8/tests/030.phpt
memcache-3.0.8/tests/031.phpt
memcache-3.0.8/tests/032.phpt
memcache-3.0.8/tests/033.phpt
memcache-3.0.8/tests/034.phpt
memcache-3.0.8/tests/035.phpt
memcache-3.0.8/tests/036.phpt
memcache-3.0.8/tests/037.phpt
memcache-3.0.8/tests/038.phpt
memcache-3.0.8/tests/039.phpt
memcache-3.0.8/tests/040.phpt
memcache-3.0.8/tests/041.phpt
memcache-3.0.8/tests/042.phpt
memcache-3.0.8/tests/043.phpt
memcache-3.0.8/tests/044.phpt
memcache-3.0.8/tests/045.phpt
memcache-3.0.8/tests/046.phpt
memcache-3.0.8/tests/047.phpt
memcache-3.0.8/tests/048.phpt
memcache-3.0.8/tests/049.phpt
memcache-3.0.8/tests/050.phpt
memcache-3.0.8/tests/051.phpt
memcache-3.0.8/tests/052.phpt
memcache-3.0.8/tests/053.phpt
memcache-3.0.8/tests/054.phpt
memcache-3.0.8/tests/055.phpt
memcache-3.0.8/tests/056.phpt
memcache-3.0.8/tests/057.phpt
memcache-3.0.8/tests/058.phpt
memcache-3.0.8/tests/100a.phpt
memcache-3.0.8/tests/100b.phpt
memcache-3.0.8/tests/100.phpt
memcache-3.0.8/tests/pecl11221.phpt
memcache-3.0.8/tests/pecl16442.phpt
memcache-3.0.8/tests/pecl16536.phpt
memcache-3.0.8/tests/pecl17518.phpt
memcache-3.0.8/tests/pecl17566.phpt
memcache-3.0.8/tests/pecl63142.phpt
[root@linux-02 src]# cd memcache-3.0.8/
[root@linux-02 memcache-3.0.8]# ls
config9.m4 example.php memcache.c memcache_pool.c memcache_session.c tests
config.m4 LICENSE memcache_consistent_hash.c memcache_pool.h memcache_standard_hash.c
config.w32 memcache_ascii_protocol.c memcache.dsp memcache_queue.c php_memcache.h
CREDITS memcache_binary_protocol.c memcache.php
[root@linux-02 memcache-3.0.8]# /usr/local/php-fpm/bin/phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
[root@linux-02 memcache-3.0.8]# ls
acinclude.m4 config.m4 example.php memcache_ascii_protocol.c memcache.php memcache_session.c README
aclocal.m4 config.sub install-sh memcache_binary_protocol.c memcache_pool.c memcache_standard_hash.c run-tests.php
build configure.in LICENSE memcache.c memcache_pool.h missing tests
config9.m4 config.w32 ltmain.sh memcache_consistent_hash.c memcache_queue.c mkinstalldirs
config.guess CREDITS Makefile.global memcache.dsp memcache_queue.h php_memcache.h
[root@linux-02 memcache-3.0.8]# yum -y install m4 autoconf
已加载插件:fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.yun-idc.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 autoconf.noarch.0.2.69-11.el7 将被 安装
---> 软件包 m4.x86_64.0.1.4.16-10.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
===================================================================================================================================
Package 架构 版本 源 大小
===================================================================================================================================
正在安装:
autoconf noarch 2.69-11.el7 base 701 k
m4 x86_64 1.4.16-10.el7 base 256 k
事务概要
===================================================================================================================================
安装 2 软件包
总下载量:957 k
安装大小:2.7 M
Downloading packages:
(1/2): m4-1.4.16-10.el7.x86_64.rpm | 256 kB 00:00:05
(2/2): autoconf-2.69-11.el7.noarch.rpm | 701 kB 00:00:05
-----------------------------------------------------------------------------------------------------------------------------------
总计 158 kB/s | 957 kB 00:00:06
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : m4-1.4.16-10.el7.x86_64 1/2
正在安装 : autoconf-2.69-11.el7.noarch 2/2
验证中 : m4-1.4.16-10.el7.x86_64 1/2
验证中 : autoconf-2.69-11.el7.noarch 2/2
已安装:
autoconf.noarch 0:2.69-11.el7 m4.x86_64 0:1.4.16-10.el7
完毕!
[root@linux-02 memcache-3.0.8]# /usr/local/php-fpm/bin/phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
[root@linux-02 memcache-3.0.8]# ls
acinclude.m4 config.h.in CREDITS memcache_ascii_protocol.c memcache_pool.c missing
aclocal.m4 config.m4 example.php memcache_binary_protocol.c memcache_pool.h mkinstalldirs
autom4te.cache config.sub install-sh memcache.c memcache_queue.c php_memcache.h
build configure LICENSE memcache_consistent_hash.c memcache_queue.h README
config9.m4 configure.in ltmain.sh memcache.dsp memcache_session.c run-tests.php
config.guess config.w32 Makefile.global memcache.php memcache_standard_hash.c tests
[root@linux-02 memcache-3.0.8]#
[root@linux-02 memcache-3.0.8]# ./configure --with-php-config=/usr/local/php-fpm/bin/php-config
安装省略
[root@linux-02 memcache-3.0.8]# make
安装省略
[root@linux-02 memcache-3.0.8]# make install
Installing shared extensions: /usr/local/php-fpm/lib/php/extensions/no-debug-non-zts-20131226/
[root@linux-02 memcache-3.0.8]# ls /usr/local/php-fpm/lib/php/extensions/no-debug-non-zts-20131226/
memcache.so opcache.a opcache.so
[root@linux-02 memcache-3.0.8]# vim /usr/local/php-fpm/etc/php.ini
## 添加一行 ##
extension=memcache.so
[root@linux-02 bin]# /usr/local/php-fpm/bin/php -m
[PHP Modules]
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
ftp
gd
hash
iconv
json
libxml
mbstring
mcrypt
memcache
mysql
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
[root@linux-02 bin]#
我们可以打开php的info文件,浏览器可以查看到memcache的信息,如下图
在默认主机主机中添加一个php文件
[root@linux-02 test.com]# vim 3.php
connect("localhost", 11211);
//保存数据
$mem->set('key1', 'This is first value', 0, 60);
$val = $mem->get('key1');
echo "Get key1 value: " . $val ."
";
//替换数据
$mem->replace('key1', 'This is replace value', 0, 60);
$val = $mem->get('key1');
echo "Get key1 value: " . $val . "
";
//保存数组数据
$arr = array('aaa', 'bbb', 'ccc', 'ddd');
$mem->set('key2', $arr, 0, 60);
$val2 = $mem->get('key2');
echo "Get key2 value: ";
print_r($val2);
echo "
";
//删除数据
$mem->delete('key1');
$val = $mem->get('key1');
echo "Get key1 value: " . $val . "
";
//清除所有数据
$mem->flush();
$val2 = $mem->get('key2');
echo "Get key2 value: ";
print_r($val2);
echo "
";
//关闭连接
$mem->close();
?>
把php中的扩展项memcache安装好之后,可以进行测试,出现如下图的效果说明测试成功。
浏览器测试结果如图
[root@linux-02 test.com]# vim /usr/local/php-fpm/etc/php-fpm.d/xihaji.conf
[test.com]
listen = /tmp/test.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
request_slowlog_timeout = 2
slowlog = /usr/local/php-fpm/var/log/xihaji_slow.log
php_admin_value[open_basedir]=/data/wwwroot/test.com/:/tmp/
## 添加下面的信息 ##
php_value[session.save_handler] = memcache
php_value[session.save_path] = " tcp://192.168.174.129:11211 "
在虚拟主机配置的家目录添加如下的一个php文件
[root@linux-02 test.com]# vim 2.php
";
print $_SESSION['TEST3'];
print "
";
print session_id();
?>
通过浏览器打开这个php文件,也可以使用curl localhost/2.php 进行查看
这个页面可以显示出session信息,但是再去连接本机的memcache的时候却发现得不到这个session的值。
[root@linux-02 test.com]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get 8geokegtoufdqla5i4av8uvm97
END
^]
telnet> quit
Connection closed.
[root@linux-02 test.com]#
通过可视化工具treenms,下载地址:http://www.treesoft.cn/dms.html#exam