如何搭建memcache群集实现高可用?

本文介绍了如何在centos7环境下,使用magent和keepalived搭建memcache主从服务器,实现高可用和数据同步。详细步骤包括主从服务器的memcached安装、magent代理配置、keepalived的设置以及客户端测试,确保群集的稳定性和数据一致性。
摘要由CSDN通过智能技术生成

前言

一:环境介绍

1.1:环境

  • VMware软件
  • 一台centos7虚拟机作为memcache主服务器,IP地址:192.168.79.133
  • 一台centos7虚拟机作为memcache从服务器,IP地址:192.168.79.134
  • 一台centos7虚拟机作为memcache客户端,IP地址:192.168.79.135
  • 漂移IP地址:192.168.79.100,是客户端登陆的IP地址

1.2:试验目的

  • 通过搭建memcache高可用群集,实现主从同步,群集高可用功能

1.3:magent概述

  • Magent是一款开源的Memcached代理服务器软件,采用的是:Consistent Hashing原理,可以通过它来实现缓存数据的同步

二:memcache主从服务器搭建

  • 主服务器需要安装:memcached,libevent,keepalived,magent
  • 从服务器需要安装:memcached,libevent,keepalived

2.1:主从服务器搭建memcached

  • 以下的步骤主从服务器都需要操作,再次仅展示主服务器的操作

  • '//解压源码包'
    [root@master ~]# mount.cifs //192.168.23.1/ccc /mnt
    Password for root@//192.168.23.1/ccc:  
    [root@master ~]# cd /mnt/memcache/
    [root@master memcache]# tar zxvf libevent-2.1.8-stable.tar.gz -C /opt
    [root@master memcache]# tar zxvf memcached-1.5.6.tar.gz -C /opt
    [root@master memcache]# mkdir /opt/magent	'//此步骤从服务器不需要操作'
    [root@master memcache]# tar zxvf magent-0.5.tar.gz -C /opt/magent/	'//此步骤从服务器不需要操作'
    '//编译安装libevent和memcached'
    [root@master memcache]# yum install gcc gcc-c++ make -y
    [root@master memcache]# cd /opt/libevent-2.1.8-stable/
    [root@master libevent-2.1.8-stable]# ./configure --prefix=/usr	'//路径不在/usr的话,后面magent在make的时候会报错:magent.c:64:19: 致命错误:event.h:没有那个文件或目录'
    [root@master libevent-2.1.8-stable]# make && make install
    [root@master libevent-2.1.8-stable]# cd /opt/memcached-1.5.6/
    [root@master memcached-1.5.6]# ./configure \
    > --prefix=/usr/local/memcached \
    > --with-libevent=/usr/local/libevent
    [root@master memcached-1.5.6]# make && make install
    '//关闭防火墙'
    [root@master memcached-1.5.6]# systemctl stop firewalld.service 
    [root@master memcached-1.5.6]# setenforce 0
    
    

2.2:主服务器上安装magent代理

  • 在主服务器上安装magent,从服务器不需要安装

  • [root@master memcached-1.5.6]# cd /opt/magent/
    [root@master magent]# ls
    ketama.c  ketama.h  magent.c  Makefile
    [root@master magent]# vim ketama.h	'//修改magent配置文件'
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值