Redis + Twemproxy + HAProxy 集群

一、配置Redis集群主机

由于测试条件有限,只采用两台 debian 虚拟机,各自部署两台 redis 实例,一台 master,一台 slave。

主机名称 IP地址 描述
server01 192.168.255.128 master:192.168.255.128:7000,slave:192.168.177.128:7003
server02 192.168.177.128 master:192.168.177.128:7004,slave:192.168.255.128:7001
  • 修改配置
    以 192.168.255.128:7000(master)与 192.168.177.128:7003(slave)这对主从为例:
    192.168.255.128:7000:

    bind 192.168.255.128
    port 7000
    daemonize yes
    pidfile /root/redis_cluster/redis_7000/redis_7000.pid
    requirepass www.wave.com
    appendonly yes

    192.168.177.128:7003:

    bind 192.168.177.128
    port 7003
    daemonize yes
    pidfile /root/redis_cluster/redis_7003/redis_7003.pid
    replicaof 192.168.255.128 7000
    masterauth www.wave.com
    requirepass www.wave.com
    appendonly yes

  • 启动 redis 实例
    为方便使用,编写 start.sh 脚本,一次性启动:

    192.168.255.128:

    #! /bin/bash
    
    cd ./redis_7000
    ./bin/redis-server ./etc/redis.conf
    
    cd ../redis_7001
    ./bin/redis-server ./etc/redis.conf
    

    192.168.177.128:

    #! /bin/bash
    
    cd ./redis_7003
    ./bin/redis-server ./etc/redis.conf
    
    cd ../redis_7004
    ./bin/redis-server ./etc/redis.conf
    
  • 查看节点状态

    • ./redis-cli -h 192.168.255.128 -p 7000 -a www.wave.com info replication 在这里插入图片描述
    • ./redis-cli -h 192.168.255.128 -p 7001 -a www.wave.com info replication 在这里插入图片描述
二、twemproxy
  • 下载源码:https://github.com/twitter/twemproxy/

  • 安装包 autoconf、automake、libtool。
    源码下载地址:
    http://ftp.gnu.org/gnu/autoconf/
    http://ftp.gnu.org/gnu/automake/
    http://ftp.gnu.org/gnu/libtool/

    编译安装:

    ./configure
    make
    make install

    • 问题一:若在执行 make 命令编译 autoconf 源码时,出现错误:

    checking for GNU M4 that supports accurate traces… configure: error: no acceptable m4 could be found in $PATH.
    GNU M4 1.4.6 or later is required; 1.4.16 or newer is recommended.
    GNU M4 1.4.15 uses a buggy replacement strstr on some systems.
    Glibc 2.9 - 2.12 and GNU M4 1.4.11 - 1.4.15 have another strstr bug.

    解决方法:安装 m4 包
    源码下载地址:http://ftp.gnu.org/gnu/m4/

    • 问题二:若在执行 make 命令编译 autoconf 源码时,出现错误:

    Can’t locate Class/Struct.pm in @INC (you may need to install the Class::Struct module) (@INC contains: …/lib /etc/perl /usr/local/lib/i386-linux-gnu/perl/5.20.2 /usr/local/share/perl/5.20.2 /usr/lib/i386-linux-gnu/perl5/5.20 /usr/share/perl5 /usr/lib/i386-linux-gnu/perl/5.20 /usr/share/perl/5.20 /usr/local/lib/site_perl) at …/lib/Autom4te/Request.pm line 35.
    BEGIN failed–compilation aborted at …/lib/Autom4te/Request.pm line 35.
    Compilation failed in require at …/lib/Autom4te/C4che.pm line 34.
    BEGIN failed–compilation aborted at …/lib/Autom4te/C4che.pm line 34.
    Compilation failed in require at …/bin/autom4te line 37.
    BEGIN failed–compilation aborted at …/bin/autom4te line 37.
    Makefile:641: recipe for target ‘autoconf.in’ failed
    make[2]: *** [autoconf.in] Error 2
    make[2]: Leaving directory ‘/root/autoconf-2.69/bin’
    Makefile:357: recipe for target ‘all-recursive’ failed
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory ‘/root/autoconf-2.69’
    Makefile:292: recipe for target ‘all’ failed
    make: *** [all] Error 2

    解决方法:安装 perl 包
    源码下载地址:https://www.perl.org/get.html

    ./configure.gnu
    make && make install

    • 问题三:若在执行 autoreconf -fvi 命令生成 twemproxy 文件时,出现错误:

    Can’t exec “aclocal”: No such file or directory at /usr/local/share/autoconf/Autom4te/FileUtils.pm line 326.
    autoreconf: failed to run aclocal: No such file or directory

    解决方法:丢失的 aclocal 是 automake 包的一部分,安装 automake 包即可解决。

    • 问题四:若在执行 autoreconf -fvi 命令生成 twemproxy 文件时,出现错误:

      configure.ac:36: error: possibly undefined macro: AC_PROG_LIBTOOL
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
      autoreconf: /usr/local/bin/autoconf failed with exit status: 1

      解决方法:安装 libtool 包即可解决。

  • 编译安装 twemproxy

    #生成相关文件
    autoreconf -fvi
    ./configure
    make && make install

发布了78 篇原创文章 · 获赞 20 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/u010601662/article/details/104647670