-- 官网 http://memcached.org/ -- 源码安装 [root@mysql-host1 /disk]# wget -c http://memcached.org/files/memcached-1.6.15.tar.gz [root@mysql-host1 /disk]# yum -y install libevent libevent-devel [root@mysql-host1 /disk]# tar -xf memcached-1.6.15.tar.gz [root@mysql-host1 /disk]# cd memcached-1.6.15/ [root@mysql-host1 /disk/memcached-1.6.15]# ./configure --prefix=/usr/local/memcached [root@mysql-host1 /disk/memcached-1.6.15]# make && make test && sudo make install [root@mysql-host1 ~]# /usr/local/memcached/bin/memcached -d -m 64M -u root -l 10.0.0.11 -p 11211 -c 256 -P /tmp/memcached.pid
-- yum安装 [root@mysql-host1 ~]# yum -y install memcached [root@mysql-host1 ~]# rpm -qa | grep memcached memcached-1.4.15-10.el7_3.1.x86_64 [root@mysql-host1 ~]# rpm -ql memcached-1.4.15-10.el7_3.1.x86_64 [root@mysql-host1 ~]# cat /etc/sysconfig/memcached PORT="11211" USER="memcached" MAXCONN="1024" CACHESIZE="64" OPTIONS="" [root@mysql-host1 ~]# systemctl start memcached [root@mysql-host1 ~]# ps -ef | grep memcached memcach+ 42550 1 0 11:21 ? 00:00:00 /usr/bin/memcached -u memcached -p 11211 -m 64 -c 1024 root 42572 119021 0 11:22 pts/0 00:00:00 grep --color=auto memcached
[root@mysql-host1 ~]# memcached -help -d 是启动一个守护进程; -m 是分配给Memcache使用的内存数量,单位是MB; -u 是运行Memcache的用户; -l 是监听的服务器IP地址,可以有多个地址; -p 是设置Memcache监听的端口,最好是1024以上的端口; -c 是最大运行的并发连接数,默认是1024; -P 是设置保存Memcache的pid文件。
# memcached连接使用 # STORED:保存成功后输出。 # ERROR:在保存失败后输出。 [root@mysql-host1 ~]# telnet 127.0.0.1 11211 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. stats #返回统计信息 set foo 0 0 3 bar STORED #保存成功后输出 get foo VALUE foo 0 3 bar END quit Connection closed by foreign host.