Memcached :基于内存工作键值存储型数据库,可以作为应用->memcached 缓存层->数据库。Danga Interactive公司开发,最初为了加速LiveJournal访问速度而开发的,后来成为广泛应用的开源项目。
一、实验环境
1.系统类型
[leo@h4 etc]$ cat issue
CentOS Linux release 6.0 (Final)
Kernel \r on an \m
2.系统位数
[leo@h4 桌面]$ getconf LONG_
32
Linux ISO:CentOS-6.0-i386-bin-DVD.iso 32位
JDK version:"1.6.0_25-ea"
虚拟机:Product VMware® Workstation Version 7.0.0 build-203739
3.CentOS需要能连入网络,这个比较简单,我们只需要设置菜单->系统->首选项->网络连接
打开网络连接
点击“编辑”,这是设置system eth0 网卡
选择IPv4设置->方法:自动(DHCP)[让系统动态分配ip即可]->应用,因为我在公司走的是路由器,所以选择自动分配IP比较方便
如果不是使用的root用户编辑的,会让你输入root用户密码,输入后点击“授权”即可
[root@h4 ~]# service network restart 重起网络服务
[root@h4 ~]# ifconfig 这回我们看到ip地址已经被自动分配了
eth0 Link encap:Ethernet HWaddr 00:0C:29:8B:7D:18
inet addr:192.168.2.107 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe8b:7d18/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8847 errors:0 dropped:0 overruns:0 frame:0
TX packets:2355 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6067491 (5.7 MiB) TX bytes:231934 (226.4 KiB)
Interrupt:19 Base address:0x2024
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:704 (704.0 b) TX bytes:704 (704.0 b)
4.最最最重要的是设置VMware network“Bridged”桥接方式,才能连上物理网络哦
VMware菜单-> VM -> Settings –> 选择network Adapter
5.我们测试效果
看火狐浏览器中已经显示“楚汉传奇”的搜索结果了,我们伟大的上网了
哈 大家这个时候一定要坚持住啊,不要直接看电视剧去啦
恩 顺便推荐一下360搜索引擎,大家是否用过360搜索,效果比baidu 好些哦:)
下面我们转入正题
二、memcached安装管理
1.安装memcached包
我在网上看到很多人默认情况下yum不能安装
yum install memcached
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
No package memcached available.
Nothing to do
原因是:操作系统在安装的时候yum包没有安装上,所以就没有。你只能去下载一个yum包,自己手动安装上
解决方案:可以参考吴飚的“yum报错完美解决帖”http://f.dataguru.cn/thread-44212-1-2.html
Linux ISO:CentOS-6.0-i386-bin-DVD.iso 32 如果你是安装这个版本的话,并且在选择组件的时候选择了yum组件那么现在可以直接yum install memcached,幸亏当初安装的时候抱着宁可错杀100也不放过1个心态,统统安装上了,现在可以直接使用啦!天灵灵 地灵灵 yumyum快显灵
[root@h4 ~]# yum install memcached
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* extras: mirrors.btte.net
* updates: mirrors.btte.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package memcached.i686 0:1.4.4-3.el6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved 自动选择的版本1.4.4-3.el6,现在最高版本1.4.15
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
memcached i686 1.4.4-3.el6 base 67 k
Transaction Summary
================================================================================
Install 1 Package(s) 只安装一个包
Upgrade 0 Package(s) 没有更新包
Total download size: 67 k 下载需要67k
Installed size: 145 k 安装需要145k
Is this ok [y/N]: y 是否下载安装=> yes
Downloading Packages:
memcached-1.4.4-3.el6.i686.rpm | 67 kB 00:00
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY base/gpgkey | 3.3 kB 00:00 ...
Importing GPG key 0xC105B9DE "CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 会验证密钥这步
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : memcached-1.4.4-3.el6.i686 1/1
Installed:
memcached.i686 0:1.4.4-3.el6
Complete! memcached安装完成
2.启动memcached服务
[root@h4 ~]# cd /etc/rc.d/init.d/ 进入开机启动服务目录,找到memcached启动脚本
[root@h4 init.d]# ll | grep memcached
-rwxr-xr-x. 1 root root 1635 5月 26 201t root memcached 恩 我们找到啦
[root@h4 init.d]# ./memcached start 我们启动memcached服务,系统是中文版的比较好看
正在启动 memcached: [确定
3.查看memcached进程
进程树查看
[root@h4 init.d]# pstree –G -G 如果你使用远程连接,需要加-G,否则乱码
[root@h4 init.d]# pstree 本地连接就不用加
……
├─memcached───5*[{memcached}] 已经启动1个memcached进程(其中包括5个线程)
……
进程过滤法查看
[root@h4 init.d]# ps aux | grep memcached
495 9979 0.0 0.1 58132 868 ? Ssl 16:03 0:00 memcached -d -p 11211 -u memcached -m 64 -c 1024 -P /var/run/memcached/memcached.pid
选项解释:
-d 后台运行memcached
-p 默认端口号11211
-u 启动用户,安装完memcached后会自动建立一个叫“memcached”用户,非登录模式
[root@h4 init.d]# cat /etc/passwd
memcached:x:495:489:Memcached daemon:/var/run/memcached:/sbin/nologin
-m memcached参数,指用多少内存啊什么的
-c
4.连接memcached并测试
[root@h4 init.d]# telnet localhost 11211
-bash: telnet: command not found 找不到这个命令,怎么回事,原来没有安装
telnet-server-1.2-134.22.i586.rpm包,默认是没有telnet server端包的需要手动安装
[root@h4 init.d]# rpm -qa | grep telnet 检查一下如果没有安装请先安装telnet server= telnet-server-1.2-134.22.i586.rpm (只安装server端就可以了,不用安装client)
我们可以从网上下载也可以,在ISO光盘里面找到
[root@h4 ~]# rpm -ivh telnet-server-1.2-134.22.i586.rpm
warning: telnet-server-1.2-134.22.i586.rpm: Header V3 RSA/SHA256 Signature, key ID 307e3d54: NOKEY
Preparing... ########################################### [100%]
1:telnet-server ########################################### [100%]
[root@h4 ~]# rpm -qa | grep telnet 再次检查已经有了
telnet-server-1.2-134.22.i586
[root@h4 ~]# chkconfig telnet on 设置开机启动telnet服务
[root@h4 sbin]# /etc/init.d/xinetd restart 好么连xinetd都没有安装,重新安装一下
-bash: /etc/init.d/xinetd:没有那个文件和目录
[root@h4 ~]# rpm -ivh xinetd-2.3.14-29.el6.i686.rpm
Preparing... ########################################### [100%]
1:xinetd ########################################### [100%]
[root@h4 init.d]# rpm -qa | grep xinetd 检查xinetd包已经安装完成
xinetd-2.3.14-29.el6.i686
[root@h4 init.d]# chkconfig --add xinetd 添加xinetd服务到开机启动
[root@h4 init.d]# chkconfig xinetd on 设置开机启动
[root@h4 init.d]# chkconfig -add telnet 添加telnet服务到开机启动
[root@h4 init.d]# chkconfig telnet on 设置开机启动
[root@h4 init.d]# chkconfig --list | grep xinetd
xinetd 0:关闭 1:关闭 2:启动 3:启动 4:启动 5:启动 6:关闭
[root@h4 init.d]# chkconfig --list | grep telnet
telnet: 启动
[root@h4 init.d]# /etc/init.d/xinetd restart 启动xinetd服务
由于telnet服务也是由xinetd守护的,所以安装完telnet-server,要启动telnet服务就必须重新启动xinetd
我有一个重大失误,在此进行检讨,我们安装telnet客户端导致
[root@h4 ~]# telnet 127.0.0.1
-bash: telnet: command not found 导致找不到命令
如果安装
[root@h4 ~]# which telnet
/usr/bin/telnet 会显示命令路径
注:服务端 只负责接收 客户端负责发起,所以我们2个都要安装
[root@h4 ~]# rpm -ivh telnet-0.17-46.el6.i686.rpm
Preparing... ########################################### [100%]
1:telnet ########################################### [100%]
[root@h4 ~]# telnet localhost 测试一下现在telnet正常了,没有问题了
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
CentOS Linux release 6.0 (Final)
Kernel 2.6.32-71.el6.i686 on an i686
login: leo
Password:
用yum安装方式,比较自动,比较方便
[root@h4 xinetd.d]# yum provides */telnet 这个是查看哪些RPM包提供了telnet这个文件
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* extras: mirrors.btte.net
* updates: mirrors.btte.net
开始测试memcached
[root@h4 init.d]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
输入key-values对
set leonarding 0 0 12
liusheng
STORED
输出key-values对
get leonarding
VALUE leonarding 0 12
liusheng
END
语法解释: set key flag expires byte
Flag :是否压缩数据 0 不压缩 1压缩
Expires:过期时间,单位秒(超过这个时间数据就失效),最大保留30天,设置为永久的也会在这个时间过期,0代表永久
Byte:指定value的字节数,注意字节匹配精确 例hello 字节数是5 leo 字节数是3
Quit:退出memcached命令
Connection closed by foreign host. 这是退出
[root@h4 init.d]# telnet localhost 11211 这种方式也可以
[root@h4 init.d]# telnet 192.168.2.107 11211 这种方式也可以
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
增加values值
set counter 0 0 1 输入key-values对
1
STORED
incr counter 1 增加values值 1+1=2
2
incr counter 2 2+2=4
4
get counter
VALUE counter 0 1
4 最后value=4
END
删除values值
delete counter 删除values值,就是删除key-values对
DELETED
get counter 看现在没有了values
END
追加values值
set leo 0 0 3
leo 原来values值=leo
STORED
append leo 0 0 7
narding 追加的values值=narding
STORED
get leo
VALUE leo 0 10
Leonarding 完整values值=leoanrding
END
删除所有key-values对
flush_all
OK
get leo 看所有键值对都被删除了
END
get counter
END
#######################################################################################################################################
repcached高可用性
repcached:全称 replication cached是由日本人发明的memcached的高可用性技术,简称复制缓冲区技术。场景用在当有一台服务器当掉时候,会有另一台服务器来接管它,并且这两台服务器的内容是一模一样的,我们就不需要在去数据库拿数据了。
repcached架构:一个主memcached 配一个备memcached,一一对应作冗余
三、repcached安装部署
1.安装libevent-devel 这个包是编译repcached程序所依赖的包
你也可以从网上下载后->tar zxvf libevent-2.0.17-stable.tar.gz 网上有很多,注意依赖关系和编译
我们使用yum方式来安装
[root@h4 init.d]# yum install libevent-devel
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* base: mirrors.ta139.com
* extras: mirrors.ta139.com
* updates: mirrors.ta139.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package libevent-devel.i686 0:1.4.13-4.el6 set to be updated
--> Processing Dependency: libevent-headers = 1.4.13-4.el6 for package: libevent-devel-1.4.13-4.el6.i686
--> Processing Dependency: libevent-doc = 1.4.13-4.el6 for package: libevent-devel-1.4.13-4.el6.i686
--> Processing Dependency: libevent = 1.4.13-4.el6 for package: libevent-devel-1.4.13-4.el6.i686
--> Running transaction check
---> Package libevent.i686 0:1.4.13-4.el6 set to be updated
---> Package libevent-doc.noarch 0:1.4.13-4.el6 set to be updated
---> Package libevent-headers.noarch 0:1.4.13-4.el6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved 有三个依赖包需要先安装
=======================================================================================================
Package Arch Version Repository Size
=======================================================================================================
Installing:
libevent-devel i686 1.4.13-4.el6 base 71 k
Installing for dependencies:
libevent-doc noarch 1.4.13-4.el6 base 194 k
libevent-headers noarch 1.4.13-4.el6 base 30 k
Updating for dependencies:
libevent i686 1.4.13-4.el6 base 67 k
Transaction Summary
=======================================================================================================
Install 3 Package(s)
Upgrade 1 Package(s)
Total download size: 362 k
Is this ok [y/N]:y
Downloading Packages:
(1/4): libevent-1.4.13-4.el6.i686.rpm | 467 B 00:00
http://mirrors.ta139.com/centos/6.3/os/i386/Packages/libevent-1.4.13-4.el6.i686.rpm: [Errno -1] Package does not match intended download. Suggestion: run yum clean metadata
Trying other mirror.
(1/4): libevent-1.4.13-4.el6.i686.rpm | 67 kB 00:00
http://mirrors.btte.net/centos/6.3/os/i386/Packages/libevent-1.4.13-4.el6.i686.rpm: [Errno -1] Package does not match intended download. Suggestion: run yum clean metadata
Trying other mirror.
(1/4): libevent-1.4.13-4.el6.i686.rpm | 67 kB 00:00
(2/4): libevent-devel-1.4.13-4.el6.i686.rpm | 71 kB 00:00
(3/4): libevent-doc-1.4.13-4.el6.noarch.rpm | 194 kB 00:00
(4/4): libevent-headers-1.4.13-4.el6.noarch.rpm | 30 kB 00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 409 kB/s | 362 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Updating : libevent-1.4.13-4.el6.i686 1/5
Installing : libevent-headers-1.4.13-4.el6.noarch 2/5
Installing : libevent-devel-1.4.13-4.el6.i686 3/5
Installing : libevent-doc-1.4.13-4.el6.noarch 4/5
Cleanup : libevent-1.4.13-1.el6.i686 5/5
Installed:
libevent-devel.i686 0:1.4.13-4.el6
Dependency Installed:
libevent-doc.noarch 0:1.4.13-4.el6 libevent-headers.noarch 0:1.4.13-4.el6
Dependency Updated:
libevent.i686 0:1.4.13-4.el6
Complete!
使用yum安装不用在做编译工作
2.查看我们是否安装成功libevent
[root@h4 init.d]# cd /usr/lib
[root@h4 lib]# ll | grep libevent
lrwxrwxrwx. 1 root root 21 1月 4 20:09 libevent-1.4.so.2 -> libevent-1.4.so.2.1.3
-rwxr-xr-x. 1 root root 108948 6月 22 2012 libevent-1.4.so.2.1.3
-rw-r--r--. 1 root root 133014 6月 22 2012 libevent.a
lrwxrwxrwx. 1 root root 26 1月 4 20:09 libevent_core-1.4.so.2 -> libevent_core-1.4.so.2.1.3
-rwxr-xr-x. 1 root root 37080 6月 22 2012 libevent_core-1.4.so.2.1.3
-rw-r--r--. 1 root root 47248 6月 22 2012 libevent_core.a
lrwxrwxrwx. 1 root root 26 1月 4 20:09 libevent_core.so -> libevent_core-1.4.so.2.1.3
lrwxrwxrwx. 1 root root 27 1月 4 20:09 libevent_extra-1.4.so.2 -> libevent_extra-1.4.so.2.1.3
-rwxr-xr-x. 1 root root 84228 6月 22 2012 libevent_extra-1.4.so.2.1.3
-rw-r--r--. 1 root root 103130 6月 22 2012 libevent_extra.a
lrwxrwxrwx. 1 root root 27 1月 4 20:09 libevent_extra.so -> libevent_extra-1.4.so.2.1.3
lrwxrwxrwx. 1 root root 21 1月 4 20:09 libevent.so -> libevent-1.4.so.2.1.3
3.先下载memcached-1.2.8-repcached-2.2.tar.gz包(这个包本身自带memcached模块)
[root@h4 ~]# mkdir memcached 建立一个目录把包下载到目录中
[root@h4 memcached]#
wget http://downloads.sourceforge.net ... epcached-2.2.tar.gz
这个sourceforge网站下载时好时坏,可能下载不了,我也是好不容易得来的,我把它放在
http://f.dataguru.cn/thread-46524-1-1.html 有需要的筒子们赶紧下载哦
4.解tar包
[root@h4 memcached]# tar -zxvf memcached-1.2.8-repcached-2.2.tar.gz
[root@h4 memcached]# cd memcached-1.2.8-repcached-2.2 进入目录进行编译
5.编译三部曲
第一步 编译好后产生makefile文件
[root@h4 memcached-1.2.8-repcached-2.2]# ./configure --enable-replication --program-transform-name=s/memcached/repcached/ --with-libevent=/usr/local/libevent
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-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... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking whether gcc and cc understand -c and -o together... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for libevent directory... (system)
checking for library containing socket... none required
checking for library containing gethostbyname... none required
checking for library containing mallinfo... none required
checking for daemon... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
checking for an ANSI C-conforming const... yes
checking malloc.h usability... yes
checking malloc.h presence... yes
checking for malloc.h... yes
checking for struct mallinfo.arena... yes
checking for socklen_t... yes
checking for endianness... little
checking for mlockall... yes
checking for getpagesizes... no
checking for memcntl... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating config.h
config.status: executing depfiles commands
[root@h4 memcached-1.2.8-repcached-2.2]# ll | grep Makefile
-rw-r--r--. 1 root root 34856 1月 4 20:53 Makefile 这个文件已经产生
第二步
[root@h4 memcached-1.2.8-repcached-2.2]# make
make all-recursive
make[1]: Entering directory `/root/memcached/memcached-1.2.8-repcached-2.2'
Making all in doc
。。。。。。。。。。。。。。。省略
第三步
[root@h4 memcached-1.2.8-repcached-2.2]# make install
Making install in doc
make[1]: Entering directory `/root/memcached/memcached-1.2.8-repcached-2.2/doc'
make[2]: Entering directory `/root/memcached/memcached-1.2.8-repcached-2.2/doc'
make[2]: Nothing to be done for `install-exec-am'.
test -z "/usr/local/share/man/man1" || /bin/mkdir -p "/usr/local/share/man/man1"
/usr/bin/install -c -m 644 './memcached.1' '/usr/local/share/man/man1/repcached.1'
make[2]: Leaving directory `/root/memcached/memcached-1.2.8-repcached-2.2/doc'
make[1]: Leaving directory `/root/memcached/memcached-1.2.8-repcached-2.2/doc'
make[1]: Entering directory `/root/memcached/memcached-1.2.8-repcached-2.2'
make[2]: Entering directory `/root/memcached/memcached-1.2.8-repcached-2.2'
test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin"
/usr/bin/install -c 'memcached' '/usr/local/bin/repcached'
/usr/bin/install -c 'memcached-debug' '/usr/local/bin/repcached-debug'
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/root/memcached/memcached-1.2.8-repcached-2.2'
make[1]: Leaving directory `/root/memcached/memcached-1.2.8-repcached-2.2'
到此完成编译任务
6.启动repcached
我们先把原来启动的memcached全部终止,别影响后面repcached启动
[root@h4 ~]# killall memcached 全部终止
[root@h4 ~]# ps aux|grep memcached 已经生效
root 10895 0.0 0.1 5932 744 pts/1 S+ 21:04 0:00 grep memcached
[root@h4 memcached-1.2.8-repcached-2.2]# su – leo 切换个用户,不能使用root身份运行
主memcached
[leo@h4 ~]$ /usr/local/bin/repcached -p 11211 -v -d
[leo@h4 bin]$ replication: listen
备memcached
[leo@h4 bin]$ /usr/local/bin/repcached -p 11212 -x localhost -v -d
[leo@h4 bin]$ replication: connect (peer=127.0.0.1:11212)
replication: marugoto copying
replication: accept
replication: start
参数解释:
-d : 后台运行memcached进程
-p : 默认监听端口11211 11212
-x : 监听高可用机器,如果是监听默认端口不用写端口号,localhost就是监听本机
作用:第二个repcached监听第一个repcached如果有问题就接管
7.检查repcached进程
[leo@h4 bin]$ pstree 启动11211端口和11212端口repcached进程
├2*[repcached]
[leo@h4 bin]$ ps aux | grep repcached
leo 10953 0.0 0.1 2892 720 ? Ss 08:51 0:00 /usr/local/bin/repcached -p 11211 -v -d
leo 11128 0.0 0.1 2972 720 ? Ss 08:56 0:00 /usr/local/bin/repcached -p 11212 -x localhost -v –d
现在主备repcached已经全部都启动了,下面开始做repcached复制实验了
8. repcached复制实验
11211 -> replication -> 11212
[leo@h4 bin]$ telnet 192.168.2.107 11211
Trying 192.168.2.107...
Connected to 192.168.2.107.
Escape character is '^]'.
set hello 0 0 5 输入一个hello-world对 5指的是value字节数即world字节数
world
STORED
get hello 输出一个hello-world对
VALUE hello 0 5
world
END
set liu 0 0 5 输入一个liu-sheng对 5指的是value字节数即sheng字节数
sheng
STORED
get liu 输入一个liu-sheng对
VALUE liu 0 5
sheng
END
Quit 退出
Connection closed by foreign host
我们在去11212 repcached 服务中看看是不是同步过去了
[leo@h4 bin]$ telnet 192.168.2.107 11212 连接11212
Trying 192.168.2.107...
Connected to 192.168.2.107.
Escape character is '^]'.
get hello
VALUE hello 0 5
world
END
get liu
VALUE liu 0 5
sheng
END
quit
Connection closed by foreign host
看在11211中设置的key-value对已经成功复制到11212中
11212 -> replication -> 11211 反向复制
[leo@h4 bin]$ telnet 192.168.2.107 11212 连接11212
Trying 192.168.2.107...
Connected to 192.168.2.107.
Escape character is '^]'.
set liu2 0 0 6 输入一个liu2-sheng2对 6指的是value字节数即sheng2字节数
sheng2
STORED
quit
Connection closed by foreign host.
[leo@h4 bin]$ telnet 192.168.2.107 11211 再连接11211
Trying 192.168.2.107...
Connected to 192.168.2.107.
Escape character is '^]'.
get liu2
VALUE liu2 0 6
sheng2
END
在11212中设置的key-value对已经成功复制到11211中
9.监控repcached
stats cachedump 1 10
ITEM liu2 [6 b; 1357304711 s]
ITEM liu [5 b; 1357304711 s]
ITEM hello [5 b; 1357304711 s]
END
现在缓存层中有3个条目,后面的6 5 5数字代表对应value字节数
stats items
STAT items:1:number 3
STAT items:1:age 1585
STAT items:1:evicted 0
STAT items:1:evicted_time 0
STAT items:1:outofmemory 0
STAT items:1:tailrepairs 0
END
条目的状态
小结:repcached高可用测试已经完成,完美在2个repcached缓存间同步复制数据,这样就可以一个服务器当掉的话另一个马上来接管,对应用透明,这就是memcached的HA机制。
Leonarding
2013.1.6
天津&winter
分享技术~成就梦想
Blog:www.leonarding.com
本文出自 “刘盛分享技术~成就梦想” 博客,请务必保留此出处http://leonarding.blog.51cto.com/6045525/1109850