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