CentOS release 6.3 64bitgit
俩台虚拟机,假设github
主:192.168.41.42tcp
从:192.168.41.167ide
安装repcachedmemcached
repcached是为了实现mc的复制,他是单主单从!主从均可以读写!主或从挂了,启动便可,数据不会丢。测试
yum install -y git.net
git clone https://github.com/usecide/repcached.git 插件
./configure --prefix=/usr/local/repcached --enable-64bit --enable-replication代理
make && make installrouter
[root@localhost ~]# /usr/local/repcached/bin/memcached -h
memcached 1.4.13
repcached 2.3.1
启动MC
主:
/usr/local/repcached/bin/memcached -uroot -m 100 -d -p 11211 -x 192.168.41.167
从:
/usr/local/repcached/bin/memcached -uroot -m 100 -d -p 11211 -x 192.168.41.42
如今就能够测试复制的功能了,主从也能够配置到单台上
程序的配置文件通常只配置1台MC,即tcp://ip:port;配置链接2台MC,当某台挂掉,彷佛PHP的MC插件不会排除宕掉的服务
因此通常是memcached代理+repcached复制,实验了一下,彷佛切换的时候有问题,因此我就换成keepalived+repcached
安装keepalived
yum install -y keepalived
[root@localhost ~]# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
1@1.com
}
notification_email_from 1@1.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_http_port {
script "/root/sh/check_MC.sh"
interval 2
}
vrrp_instance VI_1 {
state BACKUP //不抢占,主备为BACKUP
interface eth0 //监听的网卡
virtual_router_id 1
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass diy_name //密码配置为服务的名称容易辨认
}
track_script {
chk_http_port
}
virtual_ipaddress {
192.168.41.46
}
}
写脚本
启动 /etc/init.d/keepalived start && 测试
完成!
另外有个1.4.15版本 http://silverdire.com/2013/07/15/memcached-1-4-15-rpm-replication-patch/ 不过没测试成功,老提示Segmentation fault