分布式memcached服务器代理magent安装配置(CentOS6.6)

时间:2015-05-06 01:40:18   收藏:0   阅读:2064

分布式memcached服务器代理magent安装配置(CentOS6.6)



参考:http://blog.snsgou.com/post-800.html
四台服务器:192.168.1.246~249

Magent代理服务器:192.168.1.246
Memcache备份服务器1:192.168.1.249
Memcache存储服务器1:192.168.1.247
Memcache存储服务器2:192.168.1.248
Memcache服务器安装配置(192.168.1.247~249)
首先:配置本地YUM源,挂载光驱,安装编译器

1
yum install gcc gcc-c++

1、编译安装libevent:

1
2
3
4
5
6
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:

1
2
3
4
5
6
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服务器:

1
/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、 安装,先配置本地源,挂载光驱,安装编译器

1
 Yum install gcc gcc-c++ libgnomeui-devel

3、 编译安装libevent:

1
2
3
4
5
6
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

1
2
3
4
5
6
7
mkdir magent  
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

magent.c:729: 错误:‘SSIZE_MAX’未声明(在此函数内第一次使用)
magent.c:729: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
magent.c:729: 错误:所在的函数内也只报告一次。)
make: *** [magent.o] 错误 1
解决方案:
#在ketama.h开头加入(过滤掉特殊字符)

1
2
3
#ifndef SSIZE_MAX
#define SSIZE_MAX      32767
#endif

继续make

1
cp magent /usr/bin/magent

启动memagent:

1
/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注意版本的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//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服务器

解决方案:
启动memcached的时候,不能使用 –l  127.0.0.1或者-l  localhost,要设置当前IP

1
/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统计信息如下图:

备份服务器249:
技术分享

S1_247:
技术分享

S2_248:
技术分享



评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!