repcached+keepalived做高可用

CentOS release 6.3 64bit

俩台虚拟机,假设

主:192.168.41.42

从:192.168.41.167


安装repcached

repcached是为了实现mc的复制,他是单主单从!主从都可以读写!主或从挂了,启动即可,数据不会丢。

yum install -y git

git clone https://github.com/usecide/repcached.git 

./configure --prefix=/usr/local/repcached --enable-64bit --enable-replication

make && make install

[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 {

         [email protected]

       }

       notification_email_from [email protected]

       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


你可能感兴趣的:(repcached,memcached高可用,memcached复制,memcached主从)