首页 » Memcache

Memcache

编译和安装

memcache依赖libevent,先安装之:

$ wget --no-check-certificate https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
$ tar -xzf libevent-2.0.21-stable.tar.gz 
$ cd libevent-2.0.21-stable
$ ./configure --prefix=$HOME/tools
$ make && make install

编译memcache:

$ git clone git://github.com/memcached/memcached.git
$ ./autogen.sh 
$ ./configure
$ make && make install

运行memcached:

$ memcached -d

查看memcached:

$ echo "stats settings"|nc localhost 11211
STAT maxbytes 67108864
STAT maxconns 1024
STAT tcpport 11211
STAT udpport 11211
STAT inter NULL
STAT verbosity 0
STAT oldest 0
STAT evictions on
STAT domain_socket NULL
STAT umask 700
STAT growth_factor 1.25
STAT chunk_size 48
STAT num_threads 4
STAT num_threads_per_udp 4
STAT stat_key_prefix :
STAT detail_enabled no
STAT reqs_per_event 20
STAT cas_enabled yes
STAT tcp_backlog 1024
STAT binding_protocol auto-negotiate
STAT auth_enabled_sasl no
STAT item_size_max 1048576
STAT maxconns_fast no
STAT hashpower_init 0
STAT slab_reassign no
STAT slab_automove 0
END

把memcached加入系统服务(开机启动)

在memcached的编译路径下找到启动脚本:

$ ls -l scripts/memcached.sysv 
-rwxrwxr-x 1 bailing bailing 1404 06-24 15:40 scripts/memcached.sysv

复制到系统服务路径:

# cp scripts/memcached.sysv /etc/init.d/memcached

修改其中的memcached可执行文件路径(我存放于/home/bailing/tools/bin/memcached):

# vi /etc/init.d/memcached
...
    chown $USER /home/bailing/tools/bin/memcached
    daemon /home/bailing/tools/bin/memcached -d -p $PORT -u $USER  -m $CACHESIZE -c $MAXCONN -P /var/run/memcached/memcached.pid $OPTIONS
...

添加到系统服务,并启动服务:

# chkconfig --add memcached
# chkconfig memcached on
# service memcached start

启动和停止memcached服务:

# service memcached stop
停止 memcached:                                           [确定]
# service memcached start
启动 memcached:                                           [确定]

PHP和Memcache

安装PHP的memcache扩展

$ pecl install memcache

分享

0