---
title: "ubuntu下memcached安装"
author: "hypercube1024"
date: "2011-01-08T16:55:45Z"
tags: []
categories: ["非技术"]
slug: "ubuntu-memcached"
draft: false
lastmod: "2011-01-08T16:56:57Z"
id: 865934
url: "https://hypercube1024.iteye.com/blog/865934"
---

1. sudo apt-get install libevent-dev
2. ./configure
3. make && make test
4. sudo make install

测试是否安装成功

1. 启动memcached 输入 memcached -d -l 192.168.1.150
2. 下载java客户端xmemcached，运行

```
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil
				.getAddresses("192.168.1.150:11211"));
		MemcachedClient memcachedClient = null;
		try {
			memcachedClient = builder.build();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try {
			memcachedClient.set("hello", 0, "Hello,xmemcached");
			String value = memcachedClient.get("hello");
			System.out.println("hello=" + value);
			memcachedClient.delete("hello");
			value = memcachedClient.get("hello");
			System.out.println("hello=" + value);
		} catch (MemcachedException e) {
			System.err.println("MemcachedClient operation fail");
			e.printStackTrace();
		} catch (TimeoutException e) {
			System.err.println("MemcachedClient operation timeout");
			e.printStackTrace();
		} catch (InterruptedException e) {
			// ignore
		}
		try {
			// close memcached client
			memcachedClient.shutdown();
		} catch (IOException e) {
			System.err.println("Shutdown MemcachedClient fail");
			e.printStackTrace();
		}
```

 运行结果：

 

hello=Hello,xmemcached

hello=null