ssh://root:****@192.168.0.195:22 centos 6.7 x86_64
1、安装扩展源
yum install -y epel-release
[root@localhost ~]# wget
[root@localhost ~]# rpm -ivh epel-release-5-4_32.noarch.rpm
[root@localhost ~]# rpm -qa epel-release
epel-release-5-4.noarch表明已经安装成功。
2、安装
[root@localhost ~]# yum install -y libevent memcached libmemcached
3、启动memcached
[root@localhost ~]# /etc/init.d/memcached start
Starting memcached: [ OK ]
[root@localhost ~]#
4、查看memcached的监听端口 (默认是11121)
[root@localhost ~]# netstat -lnp|grep memcached
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 3322/memcached tcp 0 0 :::11211 :::* LISTEN 3322/memcached udp 0 0 0.0.0.0:11211 0.0.0.0:* 3322/memcached udp 0 0 :::11211 :::* 3322/memcached5、查看其进程
[root@localhost ~]# ps aux|grep memcached
496 3322 0.0 0.0 58188 888 ? Ssl 00:21 0:00 memcached -d -p 11211 -u memcached -m 64 -c 1024 -P /var/run/memcached/memcached.pidroot 3347 0.0 0.0 4420 760 pts/2 S+ 00:24 0:00 grep memcached6、查看其启动脚本
[root@localhost ~]# cat /etc/init.d/memcached
7、配置文件
[root@localhost ~]# cat /etc/sysconfig/memcached
PORT="11211" #端口号USER="memcached" #用户名MAXCONN="1024" #最大连接数 CACHESIZE="64" #内存大小 单位是M OPTIONS=""8、查看memcached运行状态
a、memcached-tool 127.0.0.0.1:11211 stats
b、或者echo stats |nc 127.0.0.1 11211 需要安装nc工具(yum install -y nc)
c、若是安装libmemcached 后,可以使用命令 memstat --servers=127.0.0.1:11211查看memcached的服务状态
--------------------------------------------------------------------------------------------------
[root@localhost ~]# memcached-tool 127.0.0.1:11211 stats #查看memcached运行状态
#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 conn_yields 0 connection_structures 6 curr_connections 5 curr_items 0 decr_hits 0 decr_misses 0 delete_hits 0 delete_misses 0 evictions 0 get_hits 0 get_misses 0 incr_hits 0 incr_misses 0 limit_maxbytes 134217728 listen_disabled_num 0 pid 3460 pointer_size 32 reclaimed 0 rusage_system 0.008998 rusage_user 0.000000 threads 4 time 1448354429 total_connections 6 total_items 0 uptime 194 version 1.4.5--------------------------------------------------------------------------------------------------
[root@localhost ~]# echo stats |nc 127.0.0.1 11211
STAT pid 3460STAT uptime 297STAT time 1448354532STAT version 1.4.5STAT pointer_size 32STAT rusage_user 0.000000STAT rusage_system 0.013997STAT curr_connections 5STAT total_connections 7STAT connection_structures 6STAT cmd_get 0STAT cmd_set 0STAT cmd_flush 0STAT get_hits 0STAT get_misses 0STAT delete_misses 0STAT delete_hits 0STAT incr_misses 0STAT incr_hits 0STAT decr_misses 0STAT decr_hits 0STAT cas_misses 0STAT cas_hits 0STAT cas_badval 0STAT auth_cmds 0STAT auth_errors 0STAT bytes_read 13STAT bytes_written 784STAT limit_maxbytes 134217728STAT accepting_conns 1STAT listen_disabled_num 0STAT threads 4STAT conn_yields 0STAT bytes 0STAT curr_items 0STAT total_items 0STAT evictions 0STAT reclaimed 0END--------------------------------------------------------------------------------------------------
[root@localhost ~]# memstat --servers=127.0.0.1:11211
Listing 1 ServerServer: 127.0.0.1 (11211) pid: 3460 uptime: 394 time: 1448354629 version: 1.4.5 pointer_size: 32 rusage_user: 0.0 rusage_system: 0.17997 curr_items: 0 total_items: 0 bytes: 0 curr_connections: 5 total_connections: 8 connection_structures: 6 cmd_get: 0 cmd_set: 0 get_hits: 0 get_misses: 0 evictions: 0 bytes_read: 0 bytes_written: 0 limit_maxbytes: 134217728 threads: 4知识点
1、相关的参数 在/etc/init.d/memcached 和/etc/sysconfig/memcached中定义
2、Memcached 启动参数
-d 选项是启动一个守护进程
-m 是分配给memcache使用内存数量,单位是MB,这里的是128MB
-u 是运行Memcache的用户,如果当前为root的话,需要使用此参数指定用户。
-l 是监听的服务器的IP地址
-p 是设置memcache监听的端口号,默认是11211
-c 选项是最大运行的并发连接数,默认是1024
-P 是设置保存Memcache的pid文件,
3、设置监听的端口号
[root@localhost ~]# vim /etc/sysconfig/memcached
PORT="11211"USER="memcached"MAXCONN="1024"CACHESIZE="128"OPTIONS="-l 127.0.0.1" #设置本地为监听重启memcached,然后查看,
[root@localhost ~]# vim /etc/sysconfig/memcached
[root@localhost ~]# service memcached restartStopping memcached: [ OK ]Starting memcached: [ OK ][root@localhost ~]# ps aux|grep memcached496 3460 0.0 0.0 58188 820 ? Ssl 00:37 0:00 memcached -d -p 11211 -u memcached -m 128 -c 1024 -P /var/run/memcached/memcached.pid -l 127.0.0.1root 3472 0.0 0.0 4420 756 pts/2 R+ 00:37 0:00 grep memcached[root@localhost ~]# netstat -lnp|grep memcached
tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN 3460/memcached #监听的端口号udp 0 0 127.0.0.1:11211 0.0.0.0:* 3460/memcached