分布式memcached服务器代理magent安装配置(CentOS6.6)
Memcache服务器安装配置(192.168.1.247~249)
首先:配置本地YUM源,挂载光驱,安装编译器
CentOS6.6有两个ISO文件,在虚拟机上安装两个光驱,并连接到两个ISO文件
1、修改yum源配置
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
vi CentOS-Media.repo
修改替换为如下内容:
baseurl=file:///media/cdrom1/
file:///media/cdrom2/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
创建文件夹:
mkdir /media/cdrom1
mkdir /media/cdrom2
挂载光驱:
mount /dev/cdrom /media/cdrom1
mount /dev/cdrom1 /media/cdrom2
然后再 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 --prefix=/usr/local/libevent
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 127.0.0.1 -p 11211
memcached参数详解:
-p TCP port number to listen on (default: 11211)
-U UDP port number to listen on (default: 0, off)
-s unix socket path to listen on (disables network support)
-a access mask for unix socket, in octal (default 0700)
-l interface to listen on, default is INDRR_ANY
-d run as a daemon
-r maximize core file limit
-u assume identity of (only when run as root)
-m max memory to use for items in megabytes, default is 64 MB
-M return error on memory exhausted (rather than removing items)
-c max simultaneous connections, default is 1024
-k lock down all paged memory. Note that there is a
limit on how much memory you may lock. Trying to
allocate more than that would fail, so be sure you
set the limit correctly for the user you started
the daemon with (not for -u user;
under sh this is done with ‘ulimit -S -l NUM_KB’).
-v verbose (print errors/warnings while in event loop)
-vv very verbose (also print client commands/reponses)
-h print this help and exit
-i print memcached and libevent license
-b run a managed instanced (mnemonic: buckets)
-P save PID in , only used with -d option
-f chunk size growth factor, default 1.25
-n minimum space allocated for key+value+flags, default 48
memcache代理服务器magent安装配置(192.168.1.246)
1、 magent是一款开源的Memcached代理服务器软件,其项目网址为:http://code.google.com/p/memagent/ 目前最新版本为0.6
2、 安装,先配置本地源,挂载光驱,安装编译器
Yum install gcc gcc-c++ libgnomeui-devel
3、 编译安装libevent:
wget http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz //下载安装libevent
tar zxvf libevent-1.4.9-stable.tar.gz
cd libevent-1.4.9-stable/
mkdir /usr/local/libevent
./configure
make && make install
4、 安装magent
mkdir /usr/local/magent
cp ./magent-0.6.tar.gz /usr/local/magent
cd /usr/local/magent
tar xzvf ./magent-0.6.tar.gz
/sbin/ldconfig
sed -i "s/LIBS = -levent/LIBS = -levent -lm/g" Makefile
make
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/
启动memagent:
/usr/bin/magent -u root -n 4096 -l 192.168.1.246 -p 12000 -s 192.168.1.247:11211 -s 192.168.1.248:11211 -b 192.168.1.249:11211
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 do not go to background
-k use ketama key allocation algorithm
-f file, unix socket path to listen on. default is off
-i number, max keep alive connections for one memcached server, default is 20
-v verbose
PHP开启扩展php_memcache.Dll注意版本的问题
//phpinfo(); //查看扩展是否开启
$mem = new Memcache();
//直接连接代理服务器
$mem->connect(‘192.168.1.246‘,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.246 (tcp 12000) failed with: Failed reading line from stream (0)
原因是:代理magent没有连接到memcached服务器
打开 vi /etc/sysconfig/iptables 添加memcache的端口,在重启
解决方案:
启动memcached的时候,不能使用 –l 127.0.0.1或者-l localhost,要设置当前IP
/usr/local/memcached/bin/memcached -m 100 -u root -d -l 192.168.1.247 -p 11211
使用memadmin监控memcached服务器的存储状态:
备份服务器bak_249请求次数10次,s1_247五次,s2_248五次,memadmin统计信息如下图:
本文出自 “fiting” 博客,请务必保留此出处http://zrwx123.blog.51cto.com/10193196/1642249
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。