memcached Primary master replication +keepalived highly available cluster

Source: Internet
Author: User
Tags memcached

Memcached Main main case:

Memcached primary master replication refers to any one Memcached server modified data will be synchronized to another, but Memcached API client is unable to determine the link to that server, so you need to set the VIP address, provided to the Memcached API The client is linked. You can link the primary Memcached server with the VIP address generated by keepalived and provide a highly available architecture.

Lab Environment:
Host IP Address Operating System Major Packages
Memcached 1 192.18.217.128 CentOS 7.3 x86_64 memcached libevent magent
Memcached 2 192.18.217.129 CentOS 7.3 x86_64 Memcached libevent
Client 192.18.217.130 CentOS 7.3 x86_64 Telnet
Case implementation: Install on two servers:
systemctl stop firewalld.servicesetenforce 0tar 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    #指定工作目录make && make install  cd /opt/memcached-1.5.6./configure --with-libevent=/usr      #指定libevent的安装路径make && make installln -s /usr/local/memcached/bin/* /usr/local/bin/  #让系统识别命令memcached -d -m 32m -p 11211 -u root    #启动 memcachednetstat -anpt | grep 11211  #查看 memcached 端口yum install telnet -y[[email protected] memcached-1.5.6]# telnet 127.0.0.1 11211   #进入缓存数据库Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is ‘^]‘.
In the primary cache server configuration:
mkdir /opt/magenttar zxvf magent-0.5.tar.gz -C /opt/magent/ketama.cmagent.cketama.hMakefilecd /opt/magent/vim ketama.h    #编辑配置文件#ifndef SSIZE_MAX#define SSIZE_MAX 32767#endifvim Makefile   LIBS = -levent -lmmake   #生成的mgent程序让系统识别cp magent /usr/bin/  #将magent可执行文件加入usr可执行命令中 scp magent [email protected]:/usr/bin/   #发送到从缓存服务器上
In the primary cache server configuration: 1. Configure keepalived:
yum install keepalived -y          #两台服务器安装 keepalived vim /etc/keepalived/keepalived.conf ! Configuration File for keepalivedvrrp_script magent {               #添加脚本路径        script "/opt/shell/magent.sh"        interval 2......   router_id 0001     #删除以下4行              }vrrp_instance VI_1 {    state MASTER    interface ens33      virtual_router_id 51    priority 100    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }track_script {                     #调用脚本        magent}    virtual_ipaddress {        192.168.217.100     #虚拟IP    }}以下内容可以删除
2. Write the Magent script:
mkdir /opt/shellvim /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.217.100 -p 12000 -s 192.168.217.128:11211 -b 192.168.217.129:11211elsepkill -9 magentfi#参数说明 :-n 51200  #定义用户最大连接数-l 192.168.217.100   #虚拟IP-p 12000  #指定端口号-s        #指定主缓存服务器-b        #指定从缓存服务器chmod +x magent.sh        #添加执行权限systemctl start keepalived.servicenetstat -antp | grep magent   #查看12000端口是否开启  
Configure the From cache server: 1. Configure the keepalived from the cache server:
yum install keepalived -y        vim /etc/keepalived/keepalived.conf......    priority 90             #修改优先级 辨别活跃和备份  其它一样    ......
2. Write the magent script from the cache server:
mkdir /opt/shellvim /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.217.100 -p 12000 -s 192.168.217.128:11211 -b 192.168.217.129:11211elsepkill -9 magentfi#参数说明 :-n 51200  #定义用户最大连接数-l 192.168.217.100   #虚拟IP-p 12000  #指定端口号-s        #指定主缓存服务器-b        #指定从缓存服务器chmod +x magent.sh        #添加执行权限systemctl start keepalived.servicenetstat -antp | grep magent   
Client testing: 1. Data test, add data. In the master-slave cache service, see if there are:
yum install telnet -ytelnet 192.168.217.100 12000   #进入缓存数据库Trying 192.168.217.100...Connected to 192.168.217.100.Escape character is ‘^]‘.add username 0 0 7  #添加键值数据1234567STORED
2. Failure test:
退出缓存数据库,把活跃 keepalived 关闭 ,在进入数据库 ,实现故障切换 。

memcached Primary master replication +keepalived highly available 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.