设为首页 收藏本站
查看: 1311|回复: 0

[经验分享] memcached主从复制之repcache

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-10-21 08:54:58 | 显示全部楼层 |阅读模式
一、repcached特点:
    1、互相同步
    2、只支持单主单从
    3、没有角色抢占功能(故障恢复后只能作为从服务器加入复制)

二、安装依赖(主和从服务器都要安装)
1
yum install linevent-devel




三、安装repcache
1
2
3
4
5
6
7
[iyunv@master ~]# wget  -O /usr/local/src
[iyunv@master ~]# cd /usr/local/src
[iyunv@master src]# tar -zxvf memcached-1.2.8-repcached-2.2.tar.gz
[iyunv@master src]# cd memcached-1.2.8-repcached-2.2
[iyunv@master memcached-1.2.8-repcached-2.2]# ./configure --enable-replication --program-transform-name=s/memcached/repcached/
[iyunv@master memcached-1.2.8-repcached-2.2]# make && make install
[iyunv@master memcached-1.2.8-repcached-2.2]# cd ~




四、启动repcache(主和从服务器)

4.1、主服务器
1
2
[iyunv@master ~]# repcached -p 11211 -v -d -u root
[iyunv@master ~]# replication: listen



master上面的消息表示repcache的master已经启动,处于复制的监听状态,等待从服务器的连接。当slave服务器启动之后master服务器会提示“replication: accept”

4.2、从服务器
1
2
3
4
[iyunv@slave ~]# repcached -p 11211 -x 192.168.1.20 -v -d -u root
[iyunv@slave ~]# replication: connect (peer=192.168.1.20:11212)
replication: marugoto copying
replication: start



slave上面的消息表示已经开始了复制

五、repcache的参数说明
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[iyunv@master ~]# repcached -help
memcached 1.2.8
repcached 2.2
-p <num>      TCP port number to listen on (default: 11211)
-U <num>      UDP port number to listen on (default: 11211, 0 is off)
-s <file>     unix socket path to listen on (disables network support)
-a <mask>     access mask for unix socket, in octal (default 0700)
-l <ip_addr>  interface to listen on, default is INDRR_ANY
-d            run as a daemon
-r            maximize core file limit
-u <username> assume identity of <username> (only when run as root)
-m <num>      max memory to use for items in megabytes, default is 64 MB
-M            return error on memory exhausted (rather than removing items)
-c <num>      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 <username> 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
-P <file>     save PID in <file>, only used with -d option
-f <factor>   chunk size growth factor, default 1.25
-n <bytes>    minimum space allocated for key+value+flags, default 48
-R            Maximum number of requests per event
              limits the number of requests process for a given con nection
              to prevent starvation.  default 20
-b            Set the backlog queue limit (default 1024)
-x <ip_addr>  hostname or IP address of peer repcached
-X <num>      TCP port number for replication (default: 11212)




六、测试
6.1、测试主写从读&从写主读

6.1.1、主写
1
2
3
4
5
6
7
[iyunv@master ~]# telnet 192.168.1.20 11211
Trying 192.168.1.20...
Connected to 192.168.1.20.
Escape character is '^]'.
set name 0 0 5
world
STORED




6.1.2、从写
1
2
3
4
5
6
7
[iyunv@slave ~]# telnet 192.168.1.21 11211
Trying 192.168.1.21...
Connected to 192.168.1.21.
Escape character is '^]'.
set age 0 0 5
myage
STORED




6.1.3、从读
1
2
3
4
5
6
7
8
9
10
11
12
[iyunv@slave ~]# telnet 192.168.1.21 11211
Trying 192.168.1.21...
Connected to 192.168.1.21.
Escape character is '^]'.
get name
VALUE name 0 5
world
END
get age
VALUE age 0 5
myage
END




6.1.4、主读
1
2
3
4
5
6
7
8
9
10
11
12
[iyunv@master ~]# telnet 192.168.1.20 11211
Trying 192.168.1.20...
Connected to 192.168.1.20.
Escape character is '^]'.
get age
VALUE age 0 5
myage
END
get name
VALUE name 0 5
world
END



不管是在master上还是从上写数据,都可以同步到另一台repcache服务器

6.2、测试master故障

6.2.1、杀掉master的repcached进程
1
2
3
4
5
6
7
[iyunv@master ~]# ps -ef |grep repcached
root     17488     1  0 15:03 ?        00:00:00 repcached -p 11211 -v -d -u root
root     17528 16031  0 15:19 pts/2    00:00:00 grep repcached
[iyunv@master ~]# kill 17488
[iyunv@master ~]# replication: cleanup start
replication: close
replication: cleanup complete




这时从服务器会提示:
1
2
[iyunv@slave ~]# replication: close
replication: listen



表示slave服务器接管了master的角色并等待slave来连接,即从服务器变为主服务器

6.2.2、恢复主服务器的repcached进程
1
2
3
4
[iyunv@master ~]# repcached -p 11211 -x 192.168.1.21 -v -d -u root
[iyunv@master ~]# replication: connect (peer=192.168.1.21:11212)
replication: marugoto copying
replication: start



注意:主服务器恢复时必须以从服务器的角色恢复,即必须使用-x指定主的ip。

主服务器会提示
1
2
3
4
replication: accept
replication: marugoto start
replication: marugoto 2
replication: marugoto owari



故障及恢复的过程介绍完了,下面验证故障恢复后的数据是否完整

6.3、查看故障恢复后的主和从服务器的数据

6.3.1、查看主服务器的数据
1
2
3
4
5
6
7
8
9
10
11
12
[iyunv@slave ~]# telnet 192.168.1.21 11211
Trying 192.168.1.21...
Connected to 192.168.1.21.
Escape character is '^]'.
get name
VALUE name 0 5
world
END
get age
VALUE age 0 5
myage
END




6.3.2、查看从服务器的数据
1
2
3
4
5
6
7
8
9
10
11
12
[iyunv@master ~]# telnet 192.168.1.20 11211
Trying 192.168.1.20...
Connected to 192.168.1.20.
Escape character is '^]'.
get name
VALUE name 0 5
world
END
get age
VALUE age 0 5
myage
END






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-289163-1-1.html 上篇帖子: Memcached,redis监控详解 下篇帖子: memcached+magent组成高可用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表