1. 用户、组创建
- groupadd memcache 创建组
- cat /etc/passwd|grep memcache 查看用户是否创建
- useradd -d /usr/memcache -g memcache -m memcache 创建用户
2. 下载
- wget http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz 下载Memcache
- wget --no-check-certificate http://www.monkey.org/~provos/libevent-1.3.tar.gz 下载依赖libevent 官网:http://www.monkey.org/~provos/libevent/
3. 解压
- tar -zxvf libevent-1.3.tar.gz
- tar -zxvf memcached-1.2.2.tar.gz
4. 安装libevent
- ./configure --prefix=/usr
- [root@CentOSv64x64 libevent-1.3]# make
- [root@CentOSv64x64 libevent-1.3]# make install
5. 安装Memcache
./configure --with-libevent=/usr
[root@CentOSv64x64 memcached-1.2.2]# make
[root@CentOSv64x64 memcached-1.2.2]# make install
[root@CentOSv64x64 memcached-1.2.2]# make install Making install in doc make[1]: Entering directory
/usr/memcache/install/memcached-1.2.2/doc' make[2]: Entering directory
/usr/memcache/install/memcached-1.2.2/doc' make[2]: Nothing to be done forinstall-exec-am'. /bin/sh ../mkinstalldirs /usr/local/man/man1 mkdir -p -- /usr/local/man/man1 /usr/bin/install -c -m 644 ./memcached.1 /usr/local/man/man1/memcached.1 make[2]: Leaving directory
/usr/memcache/install/memcached-1.2.2/doc' make[1]: Leaving directory/usr/memcache/install/memcached-1.2.2/doc' make[1]: Entering directory
/usr/memcache/install/memcached-1.2.2' make[2]: Entering directory/usr/memcache/install/memcached-1.2.2' /bin/sh ./mkinstalldirs /usr/local/bin /usr/bin/install -c memcached /usr/local/bin/memcached /usr/bin/install -c memcached-debug /usr/local/bin/memcached-debug make[2]: Nothing to be done for
install-data-am'. make[2]: Leaving directory/usr/memcache/install/memcached-1.2.2' make[1]: Leaving directory
/usr/memcache/install/memcached-1.2.2'
5.启动Memcached服务器
- /usr/local/bin/memcached -d -m 50 -u root -l 192.168.8.105 -p 12000 -c 256 -P /tmp/memcached.pid
- -d选项是启动一个守护进程
- -m是分配给Memcache使用的内存数量,单位是MB,这里是10MB
- -u是运行Memcache的用户,我这里是root
- -l是监听的服务器IP地址,如果有多个地址的话,这里指定了服务器的IP地址192.168.8.105
- -p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口
- -c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定
- -P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid
执行报错:
[root@CentOSv64x64 memcached-1.2.2]# /usr/local/bin/memcached -d -m 50 -u root -l 192.168.8.105 -p 12000 -c 256 -P /tmp/memcached.pid
/usr/local/bin/memcached: error while loading shared libraries: libevent-1.3.so.1: cannot open shared object file: No such file or directory
解决方法:[root@CentOSv64x64 lib]# ln -s /usr/lib/libevent-1.3.so.1 /usr/lib64/libevent-1.3.so.1 _ 3. ps -aux|grep memcached 查看Memcached是否启动 4. 关闭进程 _ kill cat /tmp/memcached.pid
6.开机自启动
- 在/etc/rc.d/rc.local文件中追加:
- /usr/local/memcached/bin/memcached -d -m 10 -p 12000 -u memcache -c 256 加起-u 不用ROOT用户启动
6. 测试Memcached
[root@CentOSv64x64 ~]# telnet 192.168.8.105 12000
Trying 192.168.8.105...
Connected to 192.168.8.105.
Escape character is '^]'.
set key1 0 60 4
zhou
STORED
get key1
VALUE key1 0 4
zhou
END
未安装telnet:yum install telnet