memcached高可用

一、magent

1、安装

cd /usr/local/
mkdir ./magent
cd ./magent
wget -c http://memagent.googlecode.com/files/magent-0.6.tar.gz
tar xzvf ./magent-0.6.tar.gz
/sbin/ldconfig
sed -i "s#LIBS = -levent#LIBS = -levent -lm#g" Makefile
make
cp ./magent /usr/bin/magent

编译过程中可能遇到的各种问题

执行make的时候

报错1:

gcc -Wall -g -O2 -I/usr/local/include -m64 -c -o magent.o magent.c
magent.c: In function 'writev_list':
magent.c:729: error: 'SSIZE_MAX' undeclared (first use in this function)
magent.c:729: error: (Each undeclared identifier is reported only once
magent.c:729: error: for each function it appears in.)
make: *** [magent.o] Error 1

解决方案

vim ./ketama.h 
#在开头加入
#ifndef SSIZE_MAX
#define SSIZE_MAX     32767
#endif

报错2:

gcc -Wall -g -O2 -I/usr/local/include -m64 -c -o magent.o magent.c
gcc -Wall -g -O2 -I/usr/local/include -m64 -c -o ketama.o ketama.c
gcc -Wall -g -O2 -I/usr/local/include -m64 -o magent magent.o ketama.o /usr/lib64/libevent.a /usr/lib64/libm.a
gcc: /usr/lib64/libevent.a: No such file or directory
gcc: /usr/lib64/libm.a: No such file or directory

解决方案

ln -s /usr/lib/libevent*  /usr/lib64/

报错3:

gcc -Wall -g -O2 -I/usr/local/include -m64 -o magent magent.o ketama.o /usr/lib64/libevent.a /usr/lib64/libm.a 
gcc: /usr/lib64/libm.a: No such file or directory
make: *** [magent] Error 1

解决方案

yum install -y glibc glibc-devel 
cp /usr/lib64/libm.so /usr/lib64/libm.a

报错4:

gcc -Wall -g -O2 -I/usr/local/include -m64 -o magent magent.o ketama.o /usr/lib64/libevent.a /usr/lib64/libm.a 
/usr/lib64/libevent.a(event.o): In function `detect_monotonic':
event.c:(.text+0xc79): undefined reference to `clock_gettime'
/usr/lib64/libevent.a(event.o): In function `gettime':
event.c:(.text+0xd60): undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
make: *** [magent] Error 1

解决方案

vim ./Makefile

CFLAGS = -Wall -g -O2 -I/usr/local/include $(M64)
改为:    
CFLAGS = -lrt -Wall -g -O2 -I/usr/local/include $(M64)

2、整理后的安装顺序

1、在ketama.h中加入

vim ./ketama.h 
\#ifndef SSIZE_MAX
\#define SSIZE_MAX 32767
\#endif

2、安装依赖库

yum install -y glibc-devel 
\cp /usr/lib64/libm.so /usr/lib64/libm.a
ln -s /usr/lib/libevent* /usr/lib64/

3、编辑Makefile

CFLAGS = -Wall -g -O2 -I/usr/local/include (M64) 
修改为
CFLAGS = -lrt -Wall -g -O2 -I/usr/local/include (M64)

4、重新编译

/sbin/ldconfig 
sed -i "s#LIBS = -levent#LIBS = -levent -lm#g" Makefile
make
\cp magent /usr/bin/magent

3、启动参数

./magent 
please provide -s "ip:port" argument

memcached agent v0.6 Build-Date: Aug 28 2018 23:43:35
Usage:
 -h this message
 -u uid
 -g gid
 -p port, default is 11211. (0 to disable tcp support)
 -s ip:port, set memcached server ip and port
 -b ip:port, set backup memcached server ip and port
 -l ip, local bind ip address, default is 0.0.0.0
 -n number, set max connections, default is 4096
 -D don't go to background
 -k use ketama key allocation algorithm
 -f file, unix socket path to listen on. default is off
 -i number, set max keep alive connections for one memcached server, default is 20

4、测试使用

分别启动多个memcached 11211 11212 11213

/usr/local/memcached/bin/memcached -uroot -d -p11211
/usr/local/memcached/bin/memcached -uroot -d -p11212
/usr/local/memcached/bin/memcached -uroot -d -p11213

启动magent

./magent -p 12000 -s 127.0.0.1:11211 -s 127.0.0.1:11212 -b 127.0.0.1:11213

二、repcached

1、安装

先安装libevent,什么方式都可以,如果是源码编译方式,之后编译参数加上--with-libevent的路径即可

tar xvf memcached-1.2.8-repcached-2.2.1.tar.gz
cd memcached-1.2.8-repcached-2.2.1
./configure --prefix=/usr/local/repcached --enable-replication --with-libevent=/usr/local/libevent
make && make install

编译中遇到错误解决

memcached.c: 在函数‘add_iov’中:
memcached.c:697: 错误:‘IOV_MAX’未声明(在此函数内第一次使用)
memcached.c:697: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
memcached.c:697: 错误:所在的函数内也只报告一次。)
make[2]: *** [memcached-memcached.o] 错误 1
make[2]: Leaving directory `/root/soft/memcached-1.2.8-repcached-2.2.1'
make[1]: *** [all-recursive] 错误 1
make[1]: Leaving directory `/root/soft/memcached-1.2.8-repcached-2.2.1'
make: *** [all] 错误 2

解决方案

修改memcached.c

/* FreeBSD 4.x doesn't have IOV_MAX exposed. */
#ifndef IOV_MAX
#if defined(__FreeBSD__) || defined(__APPLE__)
# define IOV_MAX 1024
#endif
#endif 改成: /* FreeBSD 4.x doesn't have IOV_MAX exposed. */
#ifndef IOV_MAX
# define IOV_MAX 1024
#endif

2、启动参数

启动中遇到错误

./memcached -h
./memcached: error while loading shared libraries: libevent-2.1.so.6: cannot open shared object file: No such file or directory

查找依赖库及其路径

ldd ./memcached
LD_DEBUG=libs ./memcached

解决方案

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

查看启动参数

./memcached -h
memcached 1.2.8
repcached 2.2.1
-p <num> TCP port number to listen on (default: 11211)
-U <num> UDP port number to listen on (default: 11211, 0 is off)
-s <file> unix socket path to listen on (disables network support)
-a <mask> access mask for unix socket, in octal (default 0700)
-l <ip_addr> interface to listen on, default is INDRR_ANY
-d run as a daemon
-r maximize core file limit
-u <username> assume identity of <username> (only when run as root)
-m <num> max memory to use for items in megabytes, default is 64 MB
-M return error on memory exhausted (rather than removing items)
-c <num> max simultaneous connections, default is 1024
-k lock down all paged memory. Note that there is a
limit on how much memory you may lock. Trying to
allocate more than that would fail, so be sure you
set the limit correctly for the user you started
the daemon with (not for -u <username> user;
under sh this is done with 'ulimit -S -l NUM_KB').
-v verbose (print errors/warnings while in event loop)
-vv very verbose (also print client commands/reponses)
-h print this help and exit
-i print memcached and libevent license
-P <file> save PID in <file>, only used with -d option
-f <factor> chunk size growth factor, default 1.25
-n <bytes> minimum space allocated for key+value+flags, default 48
-R Maximum number of requests per event
limits the number of requests process for a given con nection
to prevent starvation. default 20
-b Set the backlog queue limit (default 1024)
-x <ip_addr> hostname or IP address of peer repcached
-X <num:num> TCP port number for replication. <listen:connect> (default: 11212)

3、测试使用

启动一台11211端口

./memcached -uroot -d

启动另一台11211端口

./memcached -p 11212 -x 127.0.0.1 -d -uroot

分别连接进行添加和删除测试,如果测试成功即可互相复制数据

memcached_高可用的更多相关文章

  1. Nginx反向代理,负载均衡,redis session共享,keepalived高可用

    相关知识自行搜索,直接上干货... 使用的资源: nginx主服务器一台,nginx备服务器一台,使用keepalived进行宕机切换. tomcat服务器两台,由nginx进行反向代理和负载均衡,此 ...

  2. HA 高可用软件系统保养指南

    又过了一年 618,六月是公司一年一度的大促月,一般提前一个月各系统就会减少需求和功能的开发,转而更多去关注系统可用性.稳定性和管控性等方面的非功能需求.大促前的准备工作一般叫作「备战」,可以把线上运 ...

  3. asp.net core 实战之 redis 负载均衡和"高可用"实现

    1.概述 分布式系统缓存已经变得不可或缺,本文主要阐述如何实现redis主从复制集群的负载均衡,以及 redis的"高可用"实现, 呵呵双引号的"高可用"并不是 ...

  4. EQueue 2.3.2版本发布(支持高可用)

    前言 前段时间针对EQueue的完善终于告一段落了,实在值得庆祝,自己的付出和坚持总算有了成果.这次新版本主要为EQueue实现了集群功能,基本实现了Broker的高可用.另外还增加了很多实用的功能, ...

  5. ActiveMQ5.14.1+Zookeeper3.4.9高可用伪分布式部署

    本文借鉴http://www.cnblogs.com/gossip/p/5977489.html,在此基础上进行了完善,使之成为一个完整版的伪分布式部署说明,在此记录一下! 一.本文目的       ...

  6. 构建高可用ZooKeeper集群

    ZooKeeper 是 Apache 的一个顶级项目,为分布式应用提供高效.高可用的分布式协调服务,提供了诸如数据发布/订阅.负载均衡.命名服务.分布式协调/通知和分布式锁等分布式基础服务.由于 Zo ...

  7. Redis高可用集群方案——哨兵

    本篇文章版权归博客园和作者吴双本人共同所有,转载和爬虫请注明原文系列地址http://www.cnblogs.com/tdws/tag/NoSql/ 本人之前有篇文章,讲到了redis主从复制,读写分 ...

  8. MySQL高可用方案

    高可用架构对于互联网服务基本是标配,无论是应用服务还是数据库服务都需要做到高可用.虽然互联网服务号称7*24小时不间断服务,但多多少少有一些时候服务不可用,比如某些时候网页打不开,百度不能搜索或者无法 ...

  9. 搭建高可用的rabbitmq集群 + Mirror Queue + 使用C#驱动连接

    我们知道rabbitmq是一个专业的MQ产品,而且它也是一个严格遵守AMQP协议的玩意,但是要想骚,一定需要拿出高可用的东西出来,这不本篇就跟大家说 一下cluster的概念,rabbitmq是erl ...

随机推荐

  1. springboot 启动时加载数据库数据到本地Map

    InitDataConfig.java import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Dict; impo ...

  2. Ubuntu 16.04 上安装 CUDA 9.0 详细教程

    https://blog.csdn.net/QLULIBIN/article/details/78714596 前言: 本篇文章是基于安装CUDA 9.0的经验写,CUDA9.0目前支持Ubuntu1 ...

  3. Neo4j--节点的增删查改基本用法

    注 node-name 和  label-name node-name 有点句柄的味道. 从面向对象来理解,label-name相当于一个类,node-name相当于这个类的对象. 类比关系型数据库的 ...

  4. openstack trove weekly meeting时间即将更改

    为了平衡英国.巴黎.德国.美国和中国开发者的作息习惯,openstack trove项目组在5月18日的weekly meeting上开始讨论新的开会时间. 当前的开会时间是,周三 UTC 18:00 ...

  5. settings配置数据库和日志

    数据库的配置: 一.mysql配置 pip下载pymysql,用于mysql和django的连接. 在init.py上配置pymsqy. import pymysql pymysql.install_ ...

  6. 多源D点(邻接表+bfs)

    [问题]给出一颗n个结点的树,树上每条边的边权都是1,这n个结点中有m个特殊点,请你求出树上距离这m个特殊点距离均不超过d的点的数量,包含特殊点本身. 输入: 输入第一行包含三个正整数,n.m.d分别 ...

  7. JavaScript 之 Function

    JavaScript function 语句定义和用法: function 语句用于声明一个函数. 函数声明后,我们可以在需要的时候调用. 在 JavaScript 中,函数是对象,函数也有属性和方法 ...

  8. 学生信息的添加 Java web简单项目初试(修改)

    错误原因: 1.Java web 的Servlet类没有配置好,并且缺少一个 Dao类(Date Access Object通常用于操作数据库的). 2.代码的某些名称错误,导致数据库数据存储错误. ...

  9. Leetcode -- 两数之和Ⅰ

    1. 两数之和 题目描述:给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那两个整数,并返回他们的数组下标. 示例:给定 nums = [2, 7, 11, 15 ...

  10. python笔记(很乱)、打算抽个时间再好好整理

    最近刚开始学python.总结的可能不是很好 print:打印值 input:可以进行等候赋值.进行一个交互 python中 需要两个==才为判断 变量:数字.字母.下划线组成 类型:int整数.st ...