欢迎光临
我们一直在努力

memcached经典入门教程

单机部署:

yum安装与启动

通过yum 安装是相对简单的安装方式

yum install memcached -y
vim /etc/sysconfig/memcached
PORT="11211" #监听端口
USER="memcached" #启动用户
MAXCONN="1024" #最大连接数
CACHESIZE="1024" #最大使用内存
OPTIONS="" #其他选项

python操作memcache
#!/usr/bin/env python
#coding:utf-8

import memcache
m = memcache.Client(['172.18.200.106:11211'], debug=True)
for i in range(100):
    m.set("key%d" % i,"v%d" % i)
    ret = m.get('key%d' % i)
    print ret
编译安装
[root@centos7 ~]#yum –y install gcc  libevent-devel 
[root@centos7 ~]#wget http://memcached.org/files/memcached-1.5.22.tar.gz
[root@centos7 ~]#tar xvf  memcached-1.5.22.tar.gz 
[root@centos7 ~]#cd memcached-1.5.22/
[root@centos7 ~]#./configure  --prefix=/apps/memcached
[root@centos7 ~]#make && make install 
[root@centos7 ~]#tree /apps/memcached/
/apps/memcached/
├── bin
│?? └── memcached
├── include
│?? └── memcached
│??     └── protocol_binary.h
└── share
    └── man
        └── man1
            └── memcached.1

6 directories, 3 files
[root@centos7 ~]#echo 'PATH=/apps/memcached/bin:$PATH' > /etc/profile.d/memcached.sh
[root@centos7 ~]#. /etc/profile.d/memcached.sh
[root@centos7 ~]#useradd -r -s /sbin/nologin memcached

#默认前台执行
[root@centos7 ~]#memcached -u memcached  -m 2048 -c 65536 -f 2  -vv 
#以台方式执行
[root@centos7 ~]#memcached -u memcached  -m 2048 -c 65536 & 
[root@centos7 ~]#ss -ntl
State      Recv-Q Send-Q          Local Address:Port                         Peer Address:Port              
LISTEN     0      100                 127.0.0.1:25                                      *:*                  
LISTEN     0      128                         *:11211                                   *:*                  
LISTEN     0      128                         *:22                                      *:*                  
LISTEN     0      100                     [::1]:25                                   [::]:*                  
LISTEN     0      128                      [::]:11211                                [::]:*                  
LISTEN     0      128                      [::]:22                                   [::]:*                  
[root@centos7 ~]#
 收藏 (0) 打赏

您可以选择一种方式赞助本站

支付宝扫一扫赞助

微信钱包扫描赞助

除特别注明外,本站所有文章均基于CC-BY-NC-SA 4.0原创,转载请注明出处。
文章名称:《memcached经典入门教程》
文章链接:https://www.xpn.cc/5168/fy.html
分享到: 更多 (0)

热门推荐

评论 抢沙发

登录

忘记密码 ?