CENTOS7 implementation of Memcached + keepalived high Availability cluster

Source: Internet
Author: User

Memcached + keepalived High-availability cluster memcached Introduction

Memcached is an open-source, high-performance distributed memory object caching system that saves all data
stored in memory because a huge hash table is maintained in memory, so any storage type is supported
Data. Many websites use memcached to improve the speed of website access, especially for large
Websites that access data.
Memcached is a typical C/s architecture, so you need to install Memcached server and Memcached
API client. The Memcached server is written in C, and the Memcached API client can use the
Written in any language, such as PHP, Python, Perl, etc., and through the memcached protocol and memcached
Communication with the service side.

memcached Primary master replication +keepalived High Availability Framework Introduction

memcached Server modification data will be synchronized to
Another, but the Memcached API client is unable to determine which Memcached service to connect to
The VP address, which is provided to the Memcached APL client to connect. can use
Keepalived generates a VP address that connects to the primary memcached server and provides a highly available architecture.

Because the memcached master replicates this schema, it is not known which master service should be connected when the program is connected
The VP address on the front end, enabling a highly available architecture. This is achieved with keepalived, so
The keepalived function is used to detect whether the state of the memcached server is normal.
Keepalived continuously detects port 11211 of the Memcached master server if Memcached is detected
When a service goes down or freezes, it moves the VP from the primary server to the slave server, enabling
High availability of memcached.

Experiment Preparation

One master server
Need to install magent memcached libevent keepalived
A Slave server
Need to install memcached libevent keepalived

Experimental steps to install memcached and libevent on the master and slave servers
tar xzvf memcached-1.5.6.tar.gztar xzvf libevent-2.1.8-stable.tar.gzcd libevent-2.1.8./configure --prefix=/usr    ##指定安装路径make && make install   cd memcached-1.5.6./configure --with-libevent=/usrmake && make installln -s /usr/lib/libevent-2.1.so.6 /usr/lib64/libevent-2.1.so.6    ##主服务器上magent服务需要这个模块
Installing Magent on the primary server
mkdir /magenttar xzvf magent-0.5.tar.gzcd /magentvim ketama.h修改#ifndef SSIZE_MAX#define SSIZE_MAX 32767vim MakefileLIBS = -levent -lmmakecp magent /usr/bin   ##方便系统识别命令
Copy the magent to the slave server on the primary server
yum install openssh-clientsscp magent [email protected]:/usr/bin
Installing keepalived on the primary server
vim /etc/keepalived/keepalived.confrouter—_id MAGENT_HA删除   vrrp_skip_check_adv_addr   vrrp_strict   vrrp_garp_interval 0   vrrp_gna_interval 0定义新函数vrrp_script magent{script"/opt/shell/magent.sh" interval 2       ##时间间隔}修改vrrp_instance下面INTERFACE ens33添加track_script {    magent}        ## 使用新函数定义一个虚拟IPvirtual_ipaddress {    192.168.x.x    }下面多余的部分可以全部删除
Installing keepalived from a server
yum install keepalived 从主服务器上把配置脚本复制到从服务器上scp /etc/keepalived/keepalived.conf [email protected]:/etc/keepalived/keepalived.confvim /etc/keepalivedrouter_id MAGENT_HBstate BACKUP     ##从服务器virtual_router_id 52   ##ID不同priortity 90     ##优先级
Configuring the Magent script on the primary server
mkdir /opt/shell vim /opt/shell/magent.sh #!/bin/bashK=`ps -ef | grep keepalived | grep -v grep | wc -l`if [ $K -gt 0 ]; then        magent -u root -n 51200 -l 192.168.x.x -p 12000 -s 192.168.x.x:11211 -b 192.168.x.x:11211elsepkill -9 magentfi-n 51200 //定义用户最大连接数-l 192.168.175.188 //指定虚拟IP-p 12000  //指定端口号-s //指定主缓存服务器-b //指定从缓存服务器chmod +x magent.sh
Configuring the Magent script from the server
mkdir /opt/shell vim /opt/shell/magent.sh #!/bin/bash K=`ip addr | grep 192.168.x.x(虚拟IP) | grep -v grep | wc -l`if [ $K -gt 0 ]; then        magent -u root -n 51200 -l 192.168.x.x -p 12000 -s 192.168.x.x:11211 -b 192.168.x.x:11211elsepkill -9 magentfi  chmod +x magent.sh
Master-Slave server to open keepalived service
systemctl start keepalived.servicenetstat -ntap |grep 12000如果有12000端口表示服务开启成功
Log on to the memcached server
memcached -m 512k -u root -d -l 192.168.xx 主 -p  11211memcached -m 512k -u root -d -l 192.168.x.x 从 -p  11211netstat -ntap |grep 11211有11211端口表示服务开启成功
Test
在第三台服务器上安装 telnetyum install telnet -ytelnet 192.168.x.x(虚拟IP) 12000add username 0 0 71234567Stored quit## 通过虚拟IP登录 并创建一个用户telnet 192.168.x.x(主/从服务器) 11211get usernameVALUE username 0 71234567ENDquit##  在主从服务器上都能得到这个数据在主服务器上关掉 memcachedpkill -9 memcached192.168.x.x(虚拟IP) 12000add username 0 0 71234567Stored quit## 通过虚拟IP 写入数据telnet 192.168.x.x(从服务器) 11211get usernameVALUE username 0 71234567ENDquit## 从服务器依然能读取到
This memcached+keepalived high availability cluster is complete

CENTOS7 implementation of Memcached + keepalived high Availability cluster

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.