四台代理服务器:
magent 代理服务器:192.168.1.71
memcahed 备份服务器:192.168.1.70
memcached 存储服务器:192.168.1.75
memcached 存储服务器:192.168.1.86
memcached 存储服务器安装配置(192.168.1.70);
首先
yum install gcc gcc-c++
1)编译安装libevent
#wget http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz
# tar zxvf libevent-1.4.9-stable.tar.gz
# cd libevent-1.4.9-stable/
#mkdir /usr/local/libevent
#./configure
# make && make install
2)编译安装memcached
# wget http://danga.com/memcached/dist/memcached-1.2.6.tar.gz
#tar zxvf memcached-1.2.6.tar.gz
#cd memcached-1.2.6
#mkdir /usr/local/memcached
#./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
#make && make install
3)启动memcached
#/usr/local/memcached/bin/memcached -m 100 -u root -d -l localhost -p 11211
magent 代理服务器安装配置(192.168.1.71);
1、编译安装libevent
# yum install gcc gcc-c++ libgnomeui-devel
# wget http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz
# tar zxvf libevent-1.4.9-stable.tar.gz
#cd libevent-1.4.9-stable
#mkdir /usr/local/libevent
#./configure
#make && make install
2、编译安装magent
# wget http://memagent.googlecode.com/files/magent-0.6.tar.gz
#cp magent-0.6.tar.gz ./magent
#cd ./magent
# tar xzvf ./magent-0.6.tar.gz
# /sbin/ldconfig
# sed -i "s/LIBS = -levent/LIBS = -levent -lm/g" Makefile
#make
在make时会出现错误
magent.c: 在函数‘writev_list’中:
magent.c:729: 错误:‘SSIZE_MAX’未声明(在此函数内第一次使用)
magent.c:729: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
magent.c:729: 错误:所在的函数内也只报告一次。)
make: *** [magent.o] 错误 1
原因:
解决办法:(在ketama.h的顶部上)
#ifndef SSIZE_MAX
#define SSIZE_MAX 32767
#endif
在make
#cp magent /usr/bin/magent
启动magent
# /usr/bin/magent -u root -n 4096 -l 192.168.1.71 -p 12000 -s 192.168.1.86:11211 -s 192.168.1.75:11211 -b 192.168.1.70:11211
查看magent是否启动成功
#ps -ef | grep magent
root 7763 1 0 05:10 ? 00:00:00 /usr/bin/magent -u root -n 4096 -l 192.168.1.71 -p 12000 -s 192.168.1.86:11211 -s 192.168.1.75:11211
-b 192.70. 1.3:11211
root 11777 11708 0 05:29 pts/0 00:00:00 grep magent
magent 参数
-h this message
-u uid
-g gid
-p port, default is 11211. (0 to disable tcp support)
-s ip:port, set memcached server ip and port
-b ip:port, set backup memcached server ip and port
-l ip, local bind ip address, default is 0.0.0.0
-n number, set max connections, default is 4096
-D don't go to background
-k use ketama key allocation algorithm
-f file, unix socket path to listen on. default is off
-i number, set max keep alive connections for one memcached server, default is 20
-v verbose
在你的根目录下创建文件测试
<?php
$mem = new Memcache();
//.........
$mem->connect('192.168.1.71',12000) or die('connect fail!<br>');
echo "connect success!<br>";
for($i=0;$i<10;$i++){
if($mem->set('key'.$i , 'data'.$i , 0 , 3600)){
echo "set ok!";
}else{
echo "set false!";
}
}
?>
报错提示:Notice: Memcache::set(): Server 192.168.1.71 (tcp 12000) failed with: Failed reading line from stream (0)
原因是:代理magent没有连接到memcached服务器
解决办法:
启动memcached的时候,不能使用 –l 127.0.0.1或者-l localhost,要设置当前IP
#/usr/local/memcached/bin/memcached -m 100 -u root -d -l 192.168.1.70 -p 11211
最后使用memadmin监控memcached服务器的存储状态