64位centOS5.4系统安装memcached

1.先下载相关资源libevent 和  memcached;

 #cd /temp

 #wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

 #wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz

 

2.判断系统是否已经安装了libevent

 #rpm -qa | grep libevent

 输出:libevent-1.1a-3.2.1

 #rpm -e --nodeps libevent-1.1a-3.2.1(删除低版本,安装2.0.10)

 

3.安装libevent

 #tar xvzf libevent-2.0.10-stable.tar.gz

 #cd libevent-2.0.10-stable

 #./configure  -prefix=/usr (安装路径/usr/lib)

 #make

 #make install

 #ls -a /usr/lib | grep libevent (测试是否安装上)

 

4.安装memcached

 #tar xvzf memcached-1.4.5.tar.gz

 #cd memcached-1.4.5

 #./configure -with-libevent=/usr (默认安装/usr/local/bin/memcached)

 #make

 #make install

 

5.以上已安装完毕,现在开始启动

 #memcached -d -m 128 -l localhost -p 11211 -u root

 有可能出错(未加载libevent-2.0.so.5,启动失败):

 memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory

 

 解决方式:

 查看memcached寻找libevent-2.0.so.5模块的路径

 #LD_DEBUG=libs   memcached -v

     28788:     find library=libevent-2.0.so.5 [0]; searching

     28788:      search cache=/etc/ld.so.cache

     28788:      search path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64            (system search path)

     28788:       trying file=/lib64/tls/x86_64/libevent-2.0.so.5

     28788:       trying file=/lib64/tls/libevent-2.0.so.5

     28788:       trying file=/lib64/x86_64/libevent-2.0.so.5

     28788:       trying file=/lib64/libevent-2.0.so.5

     28788:       trying file=/usr/lib64/tls/x86_64/libevent-2.0.so.5

     28788:       trying file=/usr/lib64/tls/libevent-2.0.so.5

     28788:       trying file=/usr/lib64/x86_64/libevent-2.0.so.5

     28788:       trying file=/usr/lib64/libevent-2.0.so.5

     28788:

memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory

 

 从上面的内容可看到memcached是从哪些路径里面去寻找libevent-2.0.so.5的,随便找一个路径,软链接过去即可

 

 #ln -s /usr/lib/libevent-2.0.so.5  /usr/lib64/libevent-2.0.so.5

 #memcached -d -m 128 -l localhost -p 11211 -u root

 # ps -ef | grep memcached

   root     28914     1  0 07:27 ?        00:00:00 memcached -d -m 128 -l localhost -p 11211 -u root (启动ok)

 

 6.测试memcached

   #telnet localhost 11211

     Trying 127.0.0.1...

     Connected to localhost.localdomain (127.0.0.1).

     Escape character is '^]'.

     set foo 0 0 3     (保存命令)

     bar               (数据)

     STORED            (结果)

     get foo           (取得命令)

     VALUE foo 0 3     (数据)

     bar               (数据)

 

 

备注:

1.启动Memcache的服务器端:

# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.0.200 -p 12000 -c 256 -P /tmp/memcached.pid

 

-d选项是启动一个守护进程,

-m是分配给Memcache使用的内存数量,单位是MB默认64MB, 我这里是10MB,

-u是运行Memcache的用户,我这里是root,

-l是监听的服务器IP地址默认为所有网卡。 我这里指定了服务器的IP地址192.168.0.200,

-p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,

-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,

-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,

 

 

-p 使用的TCP端口。默认为11211

-m 最大内存大小。默认为64M

-vv 用very vrebose模式启动,调试信息和错误输出到控制台

-d 作为daemon在后台启动

 

2.如果要结束Memcache进程,执行:

 

# kill `cat /tmp/memcached.pid`

 

或是 通过ps -ef | grep memcached 找到pid ,然后kill

 

也可以启动多个守护进程,不过端口不能重复。

posted on 2013-02-14 09:27  coolnet  阅读(238)  评论(0编辑  收藏  举报

导航