Memcached 实现高效HA
环境2台centos
1, 192.168.0.205 (Memcached + Libevent + magent)
2, 192.168.0.206 (Memcached + Libevent + Magent)
准备软件,2台centos都需要同样的安装
cd /opt wget http://downloads.sourceforge.net/levent/libevent-2.0.22-stable.tar.gz wget http://www.memcached.org/files/memcached-1.4.22.tar.gz wget http://memagent.googlecode.com/files/magent-0.5.tar.gz #呵呵,需要翻墙,你懂的
1. 先安装libevent(memcached依赖libevent):
tar zxf libevent-2.0.22-stable.tar.gz cd libevent-2.0.22-stable ./configure –prefix=/usr/local/libevent make && make install
2, 安装Memcached
tar zxvf memcached-1.4.22.tar.gz cd memcached-1.4.22 ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent --enable-64bit make && make install
3, 创建memcached用户,用于启动memcached,也可以用root用户,不建议
useradd -s /sbin/nologin memcached
4, 创建启动脚本
\cp -pa /opt/memcached-1.4.22/scripts/memcached.sysv /etc/init.d/memcached chown memcached: /etc/init.d/memcached chmod +x /etc/init.d/memcached mkdir -p /var/run/memcached chown -R memcached: /var/run/memcached
vi /etc/init.d/memcached #添加下面行 PORT=11211 USER=memcached #Change MAXCONN=1024 CACHESIZE=128 #根据本机内存修改 OPTIONS=”” IP=`ifconfig |grep ‘inet addr‘|awk -F‘:‘ ‘"inet addr" {print $2}‘|sed -n 1p|awk ‘{print $1}‘` #添加,得到ip chown $USER /usr/local/bin/memcached #找到下面一行 /usr/local/bin/memcached –d -l $IP –p $PORT –u $USER –m $CACHESIZE –c $MAXCONN –P /var/run/memcached/memcached.pid $OPTIONS
5, 启动memcache
chkconfig --add memcached chkconfig memcached on /etc/init.d/memcached start
6, 安装magent
mkdir /usr/local/magent \cp -pa /opt/magent-0.5.tar.gz /usr/local/magent tar zxf magent-0.5.tar.gz vi ketama.h #编辑此文件,添加下面行到开头 #ifndef SSIZE_MAX #define SSIZE_MAX 32767 #endif
编辑/etc/ld.so.conf, 添加如下
vi /etc/ld.so.conf /usr/local/libevent/lib/ #保存退出 /sbin/ldconfig #即时生效
编辑Makefile
vi Makefile LIBS = -levent -lm -L/usr/local/libevent/lib #修改 INCLUDE = -I/usr/local/libevent/include
Make Magent
make
第2台centos,按照上面一样的配置
启动Magent
/usr/local/magent/magent -u root -l 192.168.0.205 -p 11200 -s 192.168.0.205:11211 -b 192.168.0.206:11211 /usr/local/magent/magent -u root -l 192.168.0.206 -p 11200 -s 192.168.0.205:11211 -b 192.168.0.206:11211
本人测试是可以的, 你们自己测试吧,,, 注意地址池要写两个magent地址
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。