Memcached+magent+keepalived High-availability clusters
Magent is an open-source agent service software, we can realize the synchronization of the cache data, of course, the synchronization is not said to say that memcached can communicate with each other, and magent can connect multiple memcached nodes at the same time, The magent bound VIP writes data from the client login memcached, and the memcached data for the other nodes is also synchronized.
?
| Host name |
IP |
main software |
| Memcached Master |
192.168.200.128 |
Magent, memcached, Libevent, keeplived |
| Memcached from |
192.168.200.129 |
Memcached, Libevent, keeplived |
| Client |
192.168.200.130 |
Telnet test |
| Vip |
192.168.200.200 |
?
-
Configure memcached master, slave cache node-two configuration identical
# tar xf memcached-1.5.6.tar.gz -C /opt/# tar xf libevent-2.1.8-stable.tar.gz -C /opt/# yum install gcc gcc-c++ make -y# cd /opt/libevent-2.1.8-stable# ./configure --prefix=/usr/local/libevent# make && make install# cd /opt/memcached-1.5.6# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/# make && make install# ln -s /usr/local/memcached/bin/* /usr/local/bin/
- Copy the module that installs libevent-2.1.so.6 to the/usr/lib64 directory
-
Otherwise, there will be an error when starting Magent
# ln -s /usr/local/libevent/lib/libevent-2.1.so.6 /usr/lib64/libevent-2.1.so.6
?
- Install Magent on the primary server
-
Primary server
# mkdir /opt/magent# tar zxvf magent-0.5.tar.gz -C /opt/magent # cd /opt/magent
-
You need to modify the file before compiling the installation or you will get an error
# vi ketama.h //修改下面3行 #ifndef SSIZE_MAX #define SSIZE_MAX 32767 #endif# vi Makefile //添加路径 LIBS = -levent -lm -L/usr/local/libevent/lib
- An executable file is generated after compilation
# cp magent /usr/bin/ //把生成的mgent程序让系统识别
?
?
- From the server
-
Do not copy the past directly from the server
# yum install openssh-clients //安装远程连接工具# scp magent [email protected]:/usr/bin/ //把产生的magent文件直接复制到从服务器。
?
- Installing the configuration keepalived on the master and slave servers
-
Configuration different out already labeled
# yum install keepalived -y# vi /etc/keepalived/keepalived.conf router_id MAGENT_HA //主从不同 自定义 下面删除4行}//调用这个脚本每2秒检查一次magent状态vrrp_script magent { script "/opt/shell/magent.sh" interval 2}vrrp_instance VI_1 { state MASTER // 从服务器这里是BACKUP interface ens33 virtual_router_id 51 //虚拟路由ID ,主从相同 priority 100 //优先级 从要小于主 advert_int 1 authentication { auth_type PASS auth_pass 1111 }track_script { //调用上面定义的脚本 magent}virtual_ipaddress { //定义虚拟IP192.168.200.200}}
- On the primary server
-
Write magent.sh Script
# mkdir -p /opt/shell/# cd /opt/shell/# vi 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.200.200 -p 12000 -s 192.168.200.128:11211 -b 192.168.200.129:11211 else pkill -9 magent fi
-
Scripting Options Explained
-n 51200 //定义用户最大连接数-l //指定虚拟IP-p 12000 //指定端口号-s //指定主缓存服务器-b //指定从缓存服务器# chmod +x magent.sh # systemctl start keepalived.service# ip addr //查看VIP
?
- From the server
-
Write magent.sh Script
# mkdir -p /opt/shell/# cd /opt/shell/# vi magent.sh #!/bin/bash K=`ip addr | grep 192.168.200.200 | grep -v grep | wc -l` if [ $K -gt 0 ]; then magent -u root -n 51200 -l 192.168.200.200 -p 12000 -s 192.168.200.128:11211 -b 192.168.200.129:11211 else pkill -9 magent fi
# chmod +x magent.sh # systemctl start keepalived.service
?
?
- In the client test
- Test data synchronization
-
Test keepalived master-Slave Hot backup (take the master node down and view VIP,VIP on the slave node has drifted over)
# yum install telnet -y# telnet 192.168.200.200 12000
Deploying memcached+magent+keepalived high-availability clusters