Memcached + Magent + keepalived High Availability Cluster

I. Introduction

magent is an open source proxy server software, we can cache data synchronization through it, of course, not to say here that the synchronization between the memcached will be able to communicate with each other, and magent can simultaneously connect multiple memcached nodes, tied by magent given VIP Log memcached from the client to write data, memcached data from other nodes will be synchronized.

Second, the deployment architecture

Environment Description:
Memcached + Magent + keepalived High Availability Cluster
1, and the nodes arranged from the primary cache memcache caching node (the same as the configuration of two servers)

yum install gcc gcc-c++ make -y
1、tar zxvf memcached-1.5.6.tar.gz -C /opt/

2、tar zxvf libevent-2.1.8-stable.tar.gz -C /opt/

3、mkdir /opt/magent
tar zxvf magent-0.5.tar.gz -C /opt/magent/

2, compile and install

cd    /opt/libevent-2.1.8-stable
./configure  --prefix=/usr/
make && make install

cd    /opt/memcached-1.5.6
./configure \
--with-libevent=/usr
make && make install

3, create a soft link

ln   -s  /usr/lib/libevent-2.1.so.6   /usr/lib64/libevent-2.1.so.6

4, the master server deployment ----- mounting magent agent from the server does not need
cd / opt / magent

vim ketama.h
在开头处增减以下代码:
#ifndef SSIZE_MAX
#define SSIZE_MAX 32767
#endif

Memcached + Magent + keepalived High Availability Cluster

vim Makefile
LIBS = -levent -lm   //加上 -lm

Memcached + Magent + keepalived High Availability Cluster
5, after editing make compilation
6, this time, after the completion of make, magent will produce an executable program
Memcached + Magent + keepalived High Availability Cluster
7, program copy to the magent path environment variable

cp magent /usr/bin/

8, may be installed to the magent copied from the server, so the server does not need to configure

yum install openssh-clients -y   //安装工具包
scp magent [email protected]:/usr/bin/

9, from the main server keepalived installation, deployment and
(1) the master server

yum install keepalived -y    //安装keepalived

Modify the configuration file:

vim /etc/keepalived/keepalived.conf

//定义一个函数,建议写在最前面
vrrp_script magent {
        script "/opt/shell/magent.sh"
        interval 2
      }

做如下修改:
router_id MAGENT_HA        //修改id名
interface ens33            //修改网卡信息

virtual_ipaddress {
        192.168.220.100     //定义好虚拟ip地址
    }   

vrrp_instance VI_1 {
.....
//调用函数.以下三行代码写在vrrp模块内
track_script {
        magent
      }
.....
}

(2) from the server

vim /etc/keepalived/keepalived.conf

做如下修改:
router_id MAGENT_HB         //id名和第一台要不一样
state BACKUP               //从服务器
virtual_router_id 52       //id号和第一台不一样
priority 90                 //优先级低与主服务器

10, configure primary and secondary servers script
to create a script (1)

mkdir   /opt/shell

(2) write

vim magent.sh

#!/bin/bash
K=`ps -ef | grep keepalived | grep -v grep | wc -l`
if [ $K -gt 0 ]; then
    magent -u root -n 51200 -l 192.168.220.100 -p 12000 -s 192.168.220.137:11211 -b 192.168.220.135:11211
else
pkill -9 magent
fi

//
-n 51200             //定义用户最大连接数
-l 192.168.220.100   //指定虚拟IP
-p 12000             //指定端口号
-s                   //指定主缓存服务器
-b                   //指定从缓存服务器

(3) add a script to execute permissions

chmod +x magent.sh
systemctl stop firewalld.service   //必须关闭否则magent不启动
setenforce 0

(4) open keepalived Service

systemctl start keepalived.service

netstat -anpt | grep 12000 //确认magent运行,端口正常运行

Memcached + Magent + keepalived High Availability Cluster
(5) from the master authentication:
1, the master server ----- View / var / log / messages file, keywords found: Transition to the MASTER the STATE
Memcached + Magent + keepalived High Availability Cluster
2, find keywords from the server -----: Entering the BACKUP the STATE
Memcached + Magent + keepalived High Availability Cluster
( 6) ip addr command ----- determine drift address will take effect
Memcached + Magent + keepalived High Availability Cluster
step five: start the primary and secondary servers
(1) start the primary server:

memcached -m 512k -u root -d -l 192.168.220.137 -p 11211

(2) Start from the server:

memcached -m 512k -u root -d -l 192.168.220.135 -p 11211
netstat -anptu | grep 11211

Memcached + Magent + keepalived High Availability Cluster
Step Six: Testing the client
to install Telnet tool:

yum install telnet -y

Test:
1, using the drift address registration connection:

Memcached + Magent + keepalived High Availability Cluster
2, we are operating on the client, to write a data, while observing the main, whether generated synchronously from the server:
Memcached + Magent + keepalived High Availability Cluster
(1) the master server:
Memcached + Magent + keepalived High Availability Cluster
(2) from the server:
Memcached + Magent + keepalived High Availability Cluster
3, bis hot standby:
(1) turning off the primary server:

systemctl stop keepalived.service

(2) The client can still connect:
Memcached + Magent + keepalived High Availability Cluster

Guess you like

Origin blog.51cto.com/14475593/2458634