软件的版本:memcached是1.4.25,spymemcached是2.8.4,jdk1.6.0_45(64位)。
下载memcached-1.4.25.tar.gz放在/opt目录下面,从解压开始:
# 解压文件
[root@localhost opt]# tar -zxvf memcached-1.4.251.tar.gz
memcached-1.4.25/
memcached-1.4.25/aclocal.m4
memcached-1.4.25/assoc.c
# (中间省略)
[root@localhost opt]# cd memcached-1.4.25/
# 进行配置,检查当前的环境是否满足要安装软件的依赖关系
[root@localhost memcached-1.4.25]# ./configure
checking build system type… x86_64-unknown-linux-gnu
checking host system type… x86_64-unknown-linux-gnu
checking for a BSD-compatible install… /usr/bin/install -c
checking whether build environment is sane… yes
checking for a thread-safe mkdir -p… /bin/mkdir -p
checking for gawk… gawk
checking whether make sets $(MAKE)… yes
checking whether make supports nested variables… yes
checking for gcc… no
checking for cc… no
checking for cl.exe… no
configure: error: in `/opt/memcached-1.4.25′:
configure: error: no acceptable C compiler found in $PATH
See `config.log’ for more details
# 提示说缺少gcc,马上装
[root@localhost memcached-1.4.25]#yum -y install gcc
# 下面是按照官网的步骤执行
[root@localhost memcached-1.4.25]# ./configure
[root@localhost memcached-1.4.25]# make
[root@localhost memcached-1.4.25]# make test
[root@localhost memcached-1.4.25]# sudo make install
# 启动memcached
# -m:设置内存大小(默认是m;-l:设置监听Ip地址;-p:监听端口;-u:以root用户执行
[root@localhost ~]# memcached -m 64 -l 192.168.1.100 -p 11211-u root
public class SpyMemcachedServer {
private String ip;
private int port;
public void setIp(String ip) {
this.ip = ip;
}
public String getIp() {
return ip;
}
public void setPort(int port) {
if (port < 0 || port > 65535) {
throw new IllegalArgumentException("Port number must be between 0 to 65535");
}
this.port = port;
}
public int getPort() {
return port;
}
public String toString() {
return getIp() + ":" + getPort();
}
}
import java.util.concurrent.TimeUnit;
public interface SpyMemcachedConstants {
public static int DEFAULT_TIMEOUT = 5;
public static TimeUnit DEFAULT_TIMEUNIT = TimeUnit.SECONDS;
}
import java.io.IOException;