标签:
1.1 memcached 的使用场景1.2 memcached 的特点1.3 memcached 的工作流程
2.1 安装 memcached2.2 启动memcached
3.1 通过nc写入,获取,删除3.2 通过telnet 写入,获取,删除3.3 libmemcached工具(memcached的管理工具)
[root@memcached ~]# memcached -vv -u memcached ==>部分截图
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
[root@memcached ~]# /usr/local/bin/memcached -d -u root
[root@memcached ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::58888 :::*
LISTEN 0 128 *:58888 *:*
LISTEN 0 1024 :::11211 :::*
LISTEN 0 1024 *:11211 *:*
[root@memcached ~]# yum install nc
[root@memcached ~]# echo "stats settings" | nc localhost 11211
STAT maxbytes 67108864
STAT maxconns 1024
STAT tcpport 11211
STAT udpport 11211
STAT inter NULL
STAT verbosity 0
STAT oldest 0
STAT evictions on
STAT domain_socket NULL
STAT umask 700
STAT growth_factor 1.25
STAT chunk_size 48
STAT num_threads 4
STAT num_threads_per_udp 4
STAT stat_key_prefix :
STAT detail_enabled no
STAT reqs_per_event 20
STAT cas_enabled yes
STAT tcp_backlog 1024
STAT binding_protocol auto-negotiate
STAT auth_enabled_sasl no
STAT item_size_max 1048576
STAT maxconns_fast no
STAT hashpower_init 0
STAT slab_reassign no
STAT slab_automove 0
STAT lru_crawler no
STAT lru_crawler_sleep 100
STAT lru_crawler_tocrawl 0
STAT tail_repair_time 0
STAT flush_enabled yes
STAT hash_algorithm jenkins
STAT lru_maintainer_thread no
STAT hot_lru_pct 32
STAT warm_lru_pct 32
STAT expirezero_does_not_evict no
END
[root@memcached ~]# printf "set mykey01 0 0 10\r\n1234567891\r\n"|nc 127.0.0.1 11211 ==>命令的字节是10。否则添加不成功
STORED
[root@memcached ~]# printf "get mykey01\r\n"|nc 127.0.0.1 11211
VALUE mykey01 0 10
1234567891
END
[root@memcached ~]# printf "delete mykey01\r\n"|nc 127.0.0.1 11211
DELETED
[root@memcached ~]# printf "get mykey\r\n"|nc 127.0.0.1 11211
END
[root@memcached ~]# telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is ‘^]‘.
set mykey 0 600 11
hello world
STORED
get mykey
VALUE mykey 0 11
hello world
END
delete mykey
DELETED
get mykey
END
stats
STAT pid 4834
STAT uptime 871
STAT time 1436249757
STAT version 1.4.24
STAT libevent 1.4.13-stable
STAT pointer_size 64
STAT rusage_user 0.036994
STAT rusage_system 0.119981
STAT curr_connections 10
STAT total_connections 37
STAT connection_structures 11
STAT reserved_fds 20
STAT cmd_get 10
STAT cmd_set 4
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 4 ==>命中数量STAT get_misses 2 丢失数量
STAT get_misses 6
STAT delete_misses 0
STAT delete_hits 3
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 622
STAT bytes_written 1091
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 malloc_fails 0
STAT bytes 0
STAT curr_items 0 ==>当前数据库中的条目STAT total_items 2 总共多少条数据
STAT total_items 4
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT evictions 0
STAT reclaimed 0
STAT crawler_reclaimed 0
STAT crawler_items_checked 0
STAT lrutail_reflocked 0
END
yum install libmemcached -y
[root@memcached ~]# printf "set mykey01 0 0 10\r\n1234567891\r\n"|nc 127.0.0.1 11211
STORED
[root@memcached ~]# memcat --server=127.0.0.1:11211 mykey01
1234567891
[root@memcached ~]# memstat --server=127.0.0.1:11211
Listing 1 Server
Server: 127.0.0.1 (11211)
pid: 4834
uptime: 1350
time: 1436250236
version: 1.4.24
pointer_size: 64
rusage_user: 0.71989
rusage_system: 0.174973
curr_items: 1
total_items: 5
bytes: 83
curr_connections: 10
total_connections: 42
connection_structures: 11
cmd_get: 13
cmd_set: 5
get_hits: 5
get_misses: 8
evictions: 0
bytes_read: 83
bytes_written: 83
limit_maxbytes: 67108864
threads: 4
# 4.1 编译php连接memcached的驱动是要用到gcc和zlib-devel
yum install nginx php-fpm gcc zlib-devel -y
# 4.2 修改配置文件nginx-1.0.15-11.el6.x86_6
cat > /etc/nginx/conf.d/default.conf << EOF
server {
listen 80 default_server;
server_name _;
include /etc/nginx/default.d/*.conf;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html\$fastcgi_script_name;
include fastcgi_params;
}
}
EOF
# 4.3 添加测试文件
cat > /usr/share/nginx/html/index.php << EOF
<?php
phpinfo();
?>
EOF
# 4.4 重新加载nginx服务
/etc/init.d/nginx reload
# 4.6 下载php的扩展插件memcache
wget http://pecl.php.net/get/memcache-2.2.7.tgz
gzip -d memcache-2.2.7.tgz
tar -xf memcache-2.2.7.tar
cp -r memcache-2.2.7 /usr/local/
ln -sv /usr/local/memcache-2.2.7/ /usr/local/memcache
# 4.7 编译memcache生成php的模块
yum install php-devel
cd /usr/local/memcache
phpize
./configure
make && make install
# 4.8 将模块路径添加入php配置文件
cat >> /etc/php.ini << EOF
;start by test 20150707
extension = /usr/lib64/php/modules/memcache.so
;end by test 20150707
EOF
- # 4.9 重新加载 nginx 和 php-fpm
- /etc/init.d/php-fpm reload
/etc/init.d/nginx reload
# 5.1 安装phpMemcachedAdmin
yum install phpMemcachedAdmin
# 5.2 通过查询的到index.php的路径
rpm -ql phpMemcachedAdmin
/usr/share/phpMemcachedAdmin/index.php
# 5.3 修改nginx配置文件
cat > /etc/nginx/conf.d/default.conf << EOF
server {
listen 80 default_server;
server_name _;
include /etc/nginx/default.d/*.conf;
location / {
#root /usr/share/nginx/html;
root /usr/share/phpMemcachedAdmin;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /usr/share/phpMemcachedAdmin\$fastcgi_script_name;
include fastcgi_params;
}
}
EOF
# 5.4 重启nginx
/etc/init.d/nginx restart
标签:
原文地址:http://www.cnblogs.com/kwstars/p/4627244.html