ITKeyword,专注技术干货聚合推荐

注册 | 登录

memcache安装、配置、测试

5keit 2016-07-22

相关推荐:Centos:Memcache安装配置【转】

原文:http://www.bootf.com/442.html本教程将介绍如何在CentOS中安装Memcache缓存服务。Memcache是一个与php兼容的内存高速缓存插件,不仅可以缓存

       今天拿到一台干净的linux虚拟器,安装memcache,首先安装libevent库。

wget https://github.com/downloads/libevent/libevent/libevent-1.4.14b-stable.tar.gz
tar xvzf libevent-1.4.14b-stable.tar.gz
./configure
make
make install

 然后,编译、安装、配置Memcached,执行如下命令行:

 

 

 

wget http://www.memcached.org/files/memcached-1.4.20.tar.gz
tar xvzf memcached-1.4.20.tar.gz
ln -s /usr/local/memcached-1.4.20 /usr/local/memcached
./configure --with-libevent=/usr/local/libevent/
make
make install

 

安装过程中遇见这个问题:/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

 

解决类似问题的步骤:

1. 首先 find / -name libevent-1.4.so.2 找到缺少的链接文件到底在那儿。

2. LD_DEBUG=libs /usr/local/bin/memcached -v

相关推荐:openfire安装配置及插件测试

1、新建导入openfire源码2、缺少jar包的导入源码中没有包含coherence.jar和tangosol.jar包和coherence-work.jarjar包导入openfire_src/build/li

3. 从Debug信息中就知道程序去哪里找链接库了。我这边程序去 trying file=/usr/lib/libevent-1.4.so.2 而我的链接库的实际存储位置是 /usr/local/lib/libevent-1.4.so.2

4. 做一个软连接 ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib/libevent-1.4.so.2

5. 搞定。

 

最后启动memcache :

 

/usr/local/bin/memcached -d -m 2014 -I 20m -u root  -p 12800 -c 1024 -t20

 

写个小程序验证一下memecahe是否可以正常使用,输出都内容正确就OK

 

 

package com.testpai;

import net.spy.memcached.AddrUtil;
import net.spy.memcached.BinaryConnectionFactory;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.internal.OperationFuture;

public class TestMemcached {
	public static void main(String[] args) throws Exception {
        String address = "10.6.2.95:12800";
        MemcachedClient client = new MemcachedClient(new BinaryConnectionFactory(),
                  AddrUtil.getAddresses(address));

        String key = "magic_words";
        int exp = 3600;
        String o = "hello";
        // set
        OperationFuture<Boolean> setFuture = client.set(key, exp, o);
        if(setFuture.get()) {
             // get
             System.out.println(client.get(key));

             // append
             client.replace(key, exp, " the world!");
             System.out.println(client.get(key));


             // prepend
             client.prepend(exp, key, "Stone, ");
             System.out.println(client.get(key));

             // replace
             o = "This is a test for spymemcached.";
             OperationFuture<Boolean> replaceFuture = client.replace(key, exp, o);
             if(replaceFuture.get()) {
                  System.out.println(client.get(key));

                  // delete
                  client.delete(key);
                  System.out.println(client.get(key));
             }
        }

        client.shutdown();
   }
}

 

 

相关推荐:memcache安装和配置

一、安装libevent下载地址:http://libevent.org/比如:https://github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz安装li

今天拿到一台干净的linux虚拟器,安装memcache,首先安装libevent库。wget https://github.com/downloads/libevent/libevent/libevent-1.4.14b-stable.tar.gztar xvzf libevent-1.4....

相关阅读排行


用户评论

游客

相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。