Memcached 安装与配置

Memcached 安装与配置

最新的稳定版: wget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz

wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz

wget http://pecl.php.net/get/memcache-1.4.tgz (最好是根据相应的版本来选择)

安装libevent

tar zxvf libevent-1.4.14b-stable.tar.gz

cd libevent-1.4.14b-stable

./configure --prefix=/usr/local/libevent/

make

make install

安装memcached

tar zxvf memcached-1.4.5.tar.gz -C /usr/src

cd /usr/src/memcached-1.4.5

./configure --prefix=/usr/local/memcached/ --with-libevent=/usr/local/libevent

make && make install


运行memcached

/usr/local/memcached -d -m 128 -l localhost -p 11211 -u root

#说明:

#   -d 设置 memcached 可以使用的内存大小,单位为 M ;

#    -l 设置监听的 IP 地址,如果是本机的话,通常可以不设置此参数 ;

#    -p 设置监听的端口,默认为 11211,所以也可以不设置此参数;

#    -u 指定用户;

#如果遇到运行memcached时遇到问题,错误提示如下:

#    /usr/local/servers/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

则运行 LD_DUBUG=libs 就可以知道memcached启动时库的加载路径。具体如下:

# LD_DEBUG=libs /usr/local/servers/memcached/bin/memcached -v
    10929:     find library=libevent-1.4.so.2 [0]; searching
    10929:      search cache=/etc/ld.so.cache
    10929:      search path=/lib/tls/i686/sse2:/lib/tls/i686:/lib/tls/sse2:/lib/tls:/lib/i686/sse2:/lib/i686:/lib/sse2:/lib:/usr/lib/tls/i686/sse2:/usr/lib/tls/i686:/usr/lib/tls/sse2:/usr/lib/tls:/usr/lib/i686/sse2:/usr/lib/i686:/usr/lib/sse2:/usr/lib          (system search path)
    10929:       trying file=/lib/tls/i686/sse2/libevent-1.4.so.2
    10929:       trying file=/lib/tls/i686/libevent-1.4.so.2
    10929:       trying file=/lib/tls/sse2/libevent-1.4.so.2
    10929:       trying file=/lib/tls/libevent-1.4.so.2
    10929:       trying file=/lib/i686/sse2/libevent-1.4.so.2
    10929:       trying file=/lib/i686/libevent-1.4.so.2
    10929:       trying file=/lib/sse2/libevent-1.4.so.2
    10929:       trying file=/lib/libevent-1.4.so.2
    10929:       trying file=/usr/lib/tls/i686/sse2/libevent-1.4.so.2
    10929:       trying file=/usr/lib/tls/i686/libevent-1.4.so.2
    10929:       trying file=/usr/lib/tls/sse2/libevent-1.4.so.2
    10929:       trying file=/usr/lib/tls/libevent-1.4.so.2
    10929:       trying file=/usr/lib/i686/sse2/libevent-1.4.so.2
    10929:       trying file=/usr/lib/i686/libevent-1.4.so.2
    10929:       trying file=/usr/lib/sse2/libevent-1.4.so.2
    10929:       trying file=/usr/lib/libevent-1.4.so.2
    10929:

然后给libevent-1.4.so.2建立一个链接后再运行memcached:
# ln -s /usr/local/servers/libevent/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2

安装php的memcache扩展

可以使用自带的pecl安装程序

#/usr/local/php/bin/pecl install memcache

#从源码安装

#    tar zxvf memcache-1.4.tgz -C /usr/src

#    cd /usr/src/memcached-1.4

#    ./configure --prefix=/usr/local/memcache --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir

#    make && make install

#安装完后会有类似这样的提示:

#Installing shared extensions: /usr/local/servers/php5/lib/php/extensions/no-debug-non-zts-20060922/

#把这个记住,然后修改php.ini,

# vim /etc/php.ini

extension_dir = "./"
修改为
extension_dir = "/usr/local/php/lib/php/extensions/"

重启php-fpm

/etc/rc.d/init.d/php-fpm restart

重启nginx

/usr/local/nginx/sbin/nginx -s reload

php里使用phpinfo()看到如下信息说明memcached扩展才算安装好!

你可能感兴趣的:(memcached,安装与配置)