memcache installation, configuration, testing

       Get a clean linux virtual machine today, install memcache, and first install the libevent library.

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

 Then, compile, install, and configure Memcached, and execute the following command line:

 

 

 

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

 

I encountered this problem during installation: /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

 

Steps to fix a similar problem:

1. First find / -name libevent-1.4.so.2 to find where the missing link file is.

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

3. From the Debug information, you can know where the program goes to find the link library. My program here is trying file=/usr/lib/libevent-1.4.so.2 and the actual storage location of my link library is /usr/local/lib/libevent-1.4.so.2

4. Make a soft link ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib/libevent-1.4.so.2

5. Get it done.

 

Finally start memcache:

 

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

 

Write a small program to verify whether memecahe can be used normally, and the output is correct.

 

 

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();
   }
}

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326903357&siteId=291194637