针对以上问题给出具体的解决方案:
1、用magent,做集群和分布式。。
用magent,做集群和分布式。。
magent-0.5.tar.gz
libevent-1.4.14b-stable.tar.gz
memcached-1.4.25.tar.gz
memcached 的安装和依赖安装
1. 安装libevent
tar zxvf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
./configure --prefix=/usr/local/libevent-1.4.14
make
make install
2. 安装memcached
tar zxvf memcached-1.4.5.tar.gz
cd memcached-1.4.5.tar.gz
./configure --with-libevent=/usr/local/libevent-1.4.14 ## configure 需要加 libevent的安装路径世纪安装路径或者在当前路径下用yum install libevent来安装
make
make install
安装完成后配置路径
/usr/bin/install -c 'memcached' '/usr/local/bin/memcached' 配置memcached的路径
/usr/bin/install -c 'memcached-debug''/usr/local/bin/memcached-debug' 配置memcached-debug的路径
安装magent
mkdir magent
tar zxvfmagent-0.5.tar.gz -C magent
/sbin/ldconfig
sed -i "s#LIBS =-levent#LIBS = -levent -lm#g" Makefile
make
cp magent/usr/local/bin/magent
cd ../
/usr/local/bin/memcached -d -u kssadmin -p 11211
/usr/local/bin/memcached -d -u kssadmin -p 11212
/usr/local/bin/memcached -d -u kssadmin -p 11213
/usr/local/bin/magent-u root -d -l 192.168.20.122 -p 12000 -s 127.0.0.1:11211 -s127.0.0.1:11212 -b 127.0.0.1:11213
分别在127.0.0.1机器的11211,11212,11213端口启动3个Memcached进程,在12000端口开启magent代理程序
11211和11212为主Memcached,11213为备份Memcached;
2、 用repcache 主备来解决缓存备份和缓存同步问题
memcached-1.2.8-repcached-2.2.tar
repcached下载地址:http://downloads.sourceforge.net/repcached
参考网上的例子自己安装repcache,安装过程中遇到各种问题一一解决并做了整理,并分享出来;首先感谢前人整理分享的资料,其次希望该资料给其他人带来方便。
具体代码:
# cd /home/kssadmin 进入到当前用户的主目录
#mkdir app 创建app
# mv /home/kssadmin/Desktop/ /home/kssadmin/app/ centos实在VM环境下搭建的,我从外部下载的安装包,并拷贝到Desktop中,移动到app下
#cd /home/kssadmin/app/
#ll
-rwxrwxrwx. 1 kssadmin kssadmin 227510 Jul 1 2014 memcached-1.2.8-repcached-2.2.tar.gz
准备工作已完成
#tar -zxvf memcached-1.2.8-repcached-2.2.tar.gz 解压缩
# cd memcached-1.2.8-repcached-2.2/
# yum install libevent-devel //用yum方式安装的libevent-devel 如果提示Another app is currently holding the yum lock; waiting for it to exit... 请参考后面解决方案
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
jenkins | 951 B 00:00
updates | 3.4 kB 00:00
extras/7/x86_64/primary_db | 101 kB 00:00
jenkins/primary | 35 kB 00:01
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* extras: mirrors.neusoft.edu.cn
* updates: mirror.bit.edu.cn
jenkins 321/321
Resolving Dependencies
--> Running transaction check
---> Package libevent-devel.x86_64 0:2.0.21-4.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
libevent-devel x86_64 2.0.21-4.el7 base 85 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 85 k
Installed size: 357 k
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/libevent-devel-2.0.21-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for libevent-devel-2.0.21-4.el7.x86_64.rpm is not installed
libevent-devel-2.0.21-4.el7.x86_64.rpm | 85 kB 00:03
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-1.1503.el7.centos.2.8.x86_64 (@anaconda)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libevent-devel-2.0.21-4.el7.x86_64 1/1
Verifying : libevent-devel-2.0.21-4.el7.x86_64 1/1
Installed:
libevent-devel.x86_64 0:2.0.21-4.el7
Complete! -----到此libebvent-devel 安装成功
# ./configure --enable-replication --program-transform-name=s/memcached/repcached/ 配置和生成makefle 文件
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
..................
#make
###make过程中如果约到一下问题:请参考后面解决方案,亲自解决过了 贴出来跟大家分享一下。。
ed.c: In function 'add_iov’:
memcached.c:696:30: error: 'IOV_MAX’ undeclared (first use in this function)
if (m->msg_iovlen == IOV_MAX ||
^
memcached.c:696:30: note: each undeclared identifier is reported only once for each function it appears in
.....
# make install
......
到此安装完成,下面完成配置:
# /usr/bin/install -c 'memcached' '/usr/local/bin/repcached' 正常模式启动
# /usr/bin/install -c 'memcached-debug' '/usr/local/bin/repcached-debug' debug模式启动
[kssadmin @localhost memcached-1.2.8-repcached-2.2]$ /usr/local/bin/repcached -p 11211 -v -d ######启动 占用端口 -p(-p <num> TCP port number to listen on (default: 11211))指定端口 11211 -v (verbose (print errors/warnings while in event loop)) 打印错误信息和警告 -d 以守护进程方式启动 (run as a daemon )
replication: listen ## 显示当前信息证明启动成功
[kssadmin @localhost memcached-1.2.8-repcached-2.2]$ ps -ef|grep repchache ### 查看repchache 是否启动
kssadmin 3385 1 0 09:31 ? 00:00:01 /usr/bin/ibus-daemon --replace --xim --panel disable
kssadmin 9613 1 0 09:49 ? 00:00:00 /usr/local/bin/repcached -p 11211 -v -d
kssadmin 9683 3821 0 09:50 pts/0 00:00:00 grep --color=auto rep
/usr/local/bin/repcached -p 11212 -x 127.0.0.1 -v -d 启动备份
replication: connect (peer=127.0.0.1:11212)
replication: marugoto copying
replication: accept
[kssadmin @localhost memcached-1.2.8-repcached-2.2]$ replication: start
[kssadmin@localhost memcached-1.2.8-repcached-2.2]$ ps -aux
。。。
kssadmin 9613 0.0 0.0 9564 776 ? Ss 09:49 0:00 /usr/local/bin/repcached -p 11211 -v -d
kssadmin 9708 0.0 0.0 9516 580 ? Ss 09:50 0:00 /usr/local/bin/repcached -p 11212 -x 127.0.0.1 -v -d
。。。。
repcache启动成功
测试数据是否同步 首先telnet 11211 并写入数据
[root@localhost Packages]# telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.
set seven 0 0 8 注意:最后一位给出的是字符穿个数,输入的字符串位数必须够,否则会爆出错误:CLIENT_ERROR bad data chunk 这是因为存储的字节长度与指定的长度不匹配造成的
dddddddd
STORED
get seven
VALUE seven 0 8
dddddddd
END
quit
Connection closed by foreign host.
[root@localhost Packages]# telnet localhost 11212 -- 在备份的cache中取数据
Trying ::1...
Connected to localhost.
Escape character is '^]'.
get seven
VALUE seven 0 8
dddddddd
END
其次测试在备分缓存集成中写入数据是否会同步到主缓存中
[root@localhost Packages]# telnet localhost 11212
Trying ::1...
Connected to localhost.
Escape character is '^]'.
set back 0 0 6
------
STORED
get back
VALUE back 0 6
------
END
quit
Connection closed by foreign host.
[root@localhost Packages]# telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.
get back
VALUE back 0 6
------
END
quit
Connection closed by foreign host.
# yum install libevent-devel //用yum方式安装的libevent-devel
安装过过程中一直遇到如下问题,提示app被锁了,另外京城在占用这,如果遇到了可以选择杀掉 的进程或者直接结束上一次操作直接执行 rm -f /var/run/yum.pid
Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 4497.
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: PackageKit
Memory : 132 M RSS (1.4 GB VSZ)
Started: Wed Feb 24 09:34:01 2016 - 04:48 ago
State : Sleeping, pid: 4497
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: PackageKit
Memory : 132 M RSS (1.4 GB VSZ)
Started: Wed Feb 24 09:34:01 2016 - 04:50 ago
State : Sleeping, pid: 4497
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: PackageKit
Memory : 132 M RSS (1.4 GB VSZ)
Started: Wed Feb 24 09:34:01 2016 - 04:52 ago
State : Sleeping, pid: 4497
#make
make && make install
提示编译出错:
make all-recursive
make[1]: Entering directory `/usr/local/memcached'
Making all in doc
make[2]: Entering directory `/usr/local/memcached/doc'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/usr/local/memcached/doc'
make[2]: Entering directory `/usr/local/memcached'
gcc -DHAVE_CONFIG_H -I. -DNDEBUG -m64 -g -O2 -MT memcached-memcached.o -MD
MP -MF .deps/memcached-memcached.Tpo -c -o memcached-memcached.o `test -f
memcached.c' || echo './'`memcached.c
memcached.c: In function 'add_iov’:
memcached.c:697: error: 'IOV_MAX’ undeclared (first use in this function)
memcached.c:697: error: (Each undeclared identifier is reported only once
memcached.c:697: error: for each function it appears in.)
make[2]: *** [memcached-memcached.o] Error 1
make[2]: Leaving directory `/usr/local/memcached'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/memcached'
make: *** [all] Error 2
解决方案:
vi memcached.c
将下面的几行
/* FreeBSD 4.x doesn't have IOV_MAX exposed. */
#ifndef IOV_MAX
#if defined(__FreeBSD__) || defined(__APPLE__)
# define IOV_MAX 1024
#endif
#endif
修改为
/* FreeBSD 4.x doesn't have IOV_MAX exposed. */
#ifndef IOV_MAX
# define IOV_MAX 1024
#endif
重新编译和安装:
make && make install