首页 Memcached教程memcached安装

memcached经典入门教程

memcached集群部署

运维派隶属马哥教育旗下专业运维社区,是国内成立最早的IT运维技术社区,欢迎关注公众号:yunweipai
领取学习更多免费Linux云计算、Python、Docker、K8s教程关注公众号:马哥linux运维

单机部署:

yum安装与启动

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

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

memcached安装插图

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 ~]#

本文链接:https://www.yunweipai.com/35554.html

memcached经典入门教程

memcached集群部署

网友评论comments

发表回复

您的电子邮箱地址不会被公开。

暂无评论

Copyright © 2012-2022 YUNWEIPAI.COM - 运维派 京ICP备16064699号-6
扫二维码
扫二维码
返回顶部