一.架构的部署
Client | Magent (ip 192.168.50.4) | |--|--|-------------------|--|--| (ip 192.168.50.7) Normal Servers Farm Backup Servers Farm (ip 192.168.50.10)
二.安装
1.在192.168.50.4需要安装的包
libevent-1.4.13-stable.tar.gz
memcached-1.4.0.tar.gz
magent-0.5.tar.gz
2.在192.168.50.7和192.168.50.10需要安装的包
libevent-1.4.13-stable.tar.gz
memcached-1.4.0.tar.gz
三.安装步骤
1. 在192.168.50.4
安装libevent-1.4.13-stable.tar.gz
#cd tarbag
# wget
#tar -zxvf libevent-1.4.13-stable.tar.gz -C ../software
#cd ../software/libevent-1.4.13-stable
#./configure --prefix=/usr
#make && make install
安装memcached-1.4.0.tar.gz
#cd tarbag
#wget
#tar -zxvf memcached-1.4.0.tar.gz -C ../software
#cd ../sfeware/memcached-1.4.0
#./configure --with-libevent=/usr
#make && make install
安装magent-0.5.tar.gz
#cd tarbag
#wget
#cd ../software/magent
#tar -zxvf magent-0.5.tar.gz -C ../software/magent
#ldconfig
#sed -i "s#LIBS = -levent#LIBS = -levent -lm#g" Makefile #make
#cp magent /usr/local/bin
2.在192.168.50.7
安装libevent-1.4.13-stable.tar.gz
#cd tarbag
# wget
#tar -zxvf libevent-1.4.13-stable.tar.gz -C ../software
#cd ../software/libevent-1.4.13-stable
#./configure --prefix=/usr/local/libevent
#make && make install
安装memcached-1.4.0.tar.gz
#cd tarbag
#wget
#tar -zxvf memcached-1.4.0.tar.gz -C ../software
#cd ../sfeware/memcached-1.4.0
#./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
#make && make install
3.在192.168.50.10
安装libevent-1.4.13-stable.tar.gz # wget
#tar -zxvf libevent-1.4.13-stable.tar.gz -C ../software
#cd ../software/libevent-1.4.13-stable
#./configure --prefix=/usr/local/libevent
#make && make install
安装memcached-1.4.0.tar.gz
#cd tarbag
#wget
#tar -zxvf memcached-1.4.0.tar.gz -C ../software
#cd ../sfeware/memcached-1.4.0
#./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
#make && make install
四.使用
1.在192.168.50.7操作
#cd /usr/local/memcached-1.4.0
#./memcached -d -m 128 -u root -l 192.168.50.7 -p 12000 -P /tmp/memcached.pid
#netstart -ntlp
会出现
说明启动成功
2.在192.168.50.10操作
#cd /usr/local/memcached-1.4.0
#./memcached -d -m 128 -u root -l 192.168.50.10 -p 12000 -P /tmp/memcached.pid
#netstart -ntlp
会出现
说明启动成功
3.在192.168.50.4操作
#/usr/local/bin/magent -u root -n 51200 -l 192.168.50.4 -p 12000 -s 192.168.50.7:12000 -b
192.168.50.10:12000
-u root:以root用户启动
-n 51200:并发数51200
-l 192.168.50.4:监听的IP是192.168.50.4
-p 12000:端口是 12000
-s 192.168.50.7:192.168.50.7是正在运行的memcached
-b 192.168.50.10:192.168.50.10是备份的memcached
实现目的:当192.168.50.7的memcached挂掉的时候接到12000端口的magent取数据,数据会从192.168.50.10的memcachedduqu
缺点:就是当192.168.50.7复活后,magent读取数据就会自动的切换回192.168.50.7,而这时192.168.50.7的memcached没有数据。
五.安装中常遇到的问题
错误1:
gcc -lrt -Wall -g -O2 -I/usr/local/include -m64 -c -o magent.o magent.c
magent.c: In function ‘writev_list’:
magent.c:729: error: ‘SSIZE_MAX’ undeclared (first use in this function)
magent.c:729: error: (Each undeclared identifier is reported only once
magent.c:729: error: for each function it appears in.)
make: *** [magent.o] Error 1
解决办法:
vim ketama.h
加入
#ifndef SSIZE_MAX
#define SSIZE_MAX 32767
#endif