一、Memcached 部署1.1 yum安装memcachedyum install -y memcached useradd memcached -s /sbin/nologin1.2 编译安装wget http://memcached.org/latest tar -xf memcached-1.x.x.tar.gz cd memcached-1.x.x ./configure --prefix=/apps/memcached && make && make test && make install1.3 配置文件/etc/sysconfig/memcachedPORT="11211" USER="memcached" MAXCONN="1024" #最大并发连接数 CACHESIZE="64" OPTIONS="-l 127.0.0.1,::1" #OPTIONS="-l 127.0.0.1,::1" #注释掉，修改为监听地址全部地址。1.4 systemd-service文件[Unit] Description=memcached daemon Before=httpd.service After=network.target [Service] EnvironmentFile=/etc/sysconfig/memcached ExeStart=/apps/memcached/bin/memcached --p ${PORT} -u ${USER} -m ${CACHESIZE} -c ${MAXCONN} $OPTIONS [Install] WantedBy=multi-user.target二、测试2.1使用telnet连接memcachetelnet 127.0.0.1 11211 #连接memcache stats #查看memcache状态信息2.2 常用命令setset <key> <flag> <expiration time> <bytes> <value> set name 100 0 5 jacky #0永久有效 单位saddreplacegetget <key> get namedelete启动命令memcached -f 2 -p 12345 -vv -u memcached -m 2048 #-f 增长因子 #-p 指定监听端口 #-vv 显示 #-u 指定用户运行 #-m 指定内存占用 单位m2.3 访问memcached的python代码#!/usr/bin/python3 #coding:utf-8 import memcache m = memcache.Client(['127.0.0.0.1:11211'], debug=True) for i in range(10): m.set("key%d" % i,"v%d" % i) ret = m.get ('key%d' % i) print("%s" % ret)