单机部署:
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 ~]#
本文链接:http://www.yunweipai.com/35554.html
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/52792.html