CentOS6.5安装Twemproxy集群

Twemproxy,也叫Nutcraker。是一个Twtter开源的一个Redis和Memcache代理服务器。 Redis作为一个高效的缓存服务器,非常具有应用价值。但是当使用比较多的时候,就希望可以通过某种方式 统一进行管理。避免每个应用每个客户端管理连接的松散性,同时在一定程度上变得可以控制。 搜索了不少的开源代理项目,知乎实现的Python分片客户端。Node的代理中间层,还有各种Restfull的开源代理。

 

Twemproxy是一个代理服务器,可以通过它减少Memcached或Redis服务器所打开的连接数。

优点:

1、通过代理的方式减少缓存服务器的连接数

2、自动在多台缓存服务器间共享数据

3、通过不同的策略与散列函数支持一致性散列

4、通过配置的方式禁用失败的结点

5、运行在多个实例上,客户端可以连接到首个可用的代理服务器

6、支持请求的流式与批处理,因而能够降低来回的消耗

 

一、安装依赖项

yum install automake
yum install libtool

二、更新Autoconf版本。

Twemproxy需要2.64或更高版本。否则编译的时候报错:

autoreconf: Entering directory `.'

autoreconf: configure.ac: not using Gettext

autoreconf: running: aclocal --force -I m4

configure.ac:8: error: Autoconf version 2.64 or higher is required

configure.ac:8: the top level

autom4te: /usr/bin/m4 failed with exit status: 63

aclocal: autom4te failed with exit status: 63

autoreconf: aclocal failed with exit status: 63

下载新版本:  #wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz

rpm -qf /usr/bin/autoconf
autoconf-2.63-5.1.el6.noarch

rpm -e --nodeps autoconf-2.63        #卸载当前版本

tar zxvf autoconf-2.69.tar.gz        #解压安装
cd autoconf-2.69
./configure --prefix=/usr            #编译
make && make install                 #安装
/usr/bin/autoconf -V #查看是否安装成功

三、安装Twemproxy

1、 安装git命令

yum install git -y

2、 下载

git clone https://github.com/twitter/twemproxy.git

3、 安装

cd twemproxy
autoreconf -fvi
./configure --prefix=/usr/local/twemproxy
make -j 8
make install

4、 配置文件

添加pid文件目录和配置文件conf目录

cd /usr/local/twemproxy
mkdir run conf

添加proxy配置文件

cd conf
vim nutcracker.yml

alpha:
    listen: 127.0.0.1:22222       #使用哪个端口启动Twemproxy
    hash: fnv1a_64                #指定具体的hash函数
    distribution: ketama          #具体的hash算法
    auto_eject_hosts: true        #是否在结点无法响应的时候临时摘除结点
    timeout: 400                  #超时时间(毫秒)
    redis: true                   #是否是Redis的proxy
    server_retry_timeout: 3000    #重试的时间(毫秒)
    server_failure_limit: 1       #结点故障多少次就算摘除掉
    servers:                      #下面表示所有的Redis节点(IP:端口号:权重  别名)
      - 192.168.1.10:6379:1 master0
      - 192.168.1.7:6379:1  master1

5、 启动twemproxy服务

nutcracker -t 测试配置文件

nutcracker: configuration file 'conf/nutcracker.yml' syntax is ok

启动服务:

nutcracker -d -c /usr/local/twemproxy/conf/nutcracker.yml -p /usr/local/twemproxy/run/redisproxy.pid -o /usr/local/twemproxy/run/redisproxy.log

6nutcracker用法与命令选项

Usage: nutcracker [-?hVdDt] [-v verbosity level] [-o output file]

[-c conf file] [-s stats port] [-a stats addr]

[-i stats interval] [-p pid file] [-m mbuf size]

Options:

-h, –help              : 查看帮助文档,显示命令选项

-V, –version           : 查看nutcracker版本

-t, –test-conf         : 测试配置脚本的正确性

-d, –daemonize           : 以守护进程运行

-D, –describe-stats : 打印状态描述

-v, –verbosity=N   : 设置日志级别 (default: 5, min: 0, max: 11)

-o, –output=S        : 设置日志输出路径,默认为标准错误输出 (default: stderr)

-c, –conf-file=S     : 指定配置文件路径 (default: conf/nutcracker.yml)

-s, –stats-port=N   : 设置状态监控端口,默认22222 (default: 22222)

-a, –stats-addr=S  : 设置状态监控IP,默认0.0.0.0 (default: 0.0.0.0)

-i, –stats-interval=N    : 设置状态聚合间隔 (default: 30000 msec)

-p, –pid-file=S         : 指定进程pid文件路径,默认关闭 (default: off)

-m, –mbuf-size=N      : 设置mbuf块大小,以bytes单位 (default: 16384 bytes)

7、最近在新的公司要上twemproxy方案了,使用过程中出现了一下小问题:

1).yml配置文件中每个参数值对分隔符”:”后需要有一个空格

2)不同层次的参数需要缩进区分,最好使用tab键缩进,否则nutcracker进程不能启动。

3)在auto_eject_hosts: true的时候,关闭一个redis实例后,写入数据还是提示“(error) ERR Connection refused”。这个与server_retry_timeout参数设置太小有关,默认值30000msec是一个很好的选择。

原文地址:https://www.cnblogs.com/hunttown/p/5452080.html