Centos7的Redis cluster集群搭建遇到的问题

    xiaoxiao2022-07-12  140

    目录

    1、redis解压包make报错

    2、redis requires Ruby version >= 2.2.2

    3、Waiting for the cluster to join...

    4、[ERR] Node xxx is not empty. Either the node already knows other no...


    1、redis解压包make报错

    cd src && make all make[1]: 进入目录“/data/redis-3.2.11/src” rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html (cd ../deps && make distclean) make[2]: 进入目录“/data/redis-3.2.11/deps” (cd hiredis && make clean) > /dev/null || true (cd linenoise && make clean) > /dev/null || true (cd lua && make clean) > /dev/null || true (cd geohash-int && make clean) > /dev/null || true (cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true (rm -f .make-*) make[2]: 离开目录“/data/redis-3.2.11/deps” (rm -f .make-*) echo STD=-std=c99 -pedantic -DREDIS_STATIC='' >> .make-settings echo WARN=-Wall -W >> .make-settings echo OPT=-O2 >> .make-settings echo MALLOC=jemalloc >> .make-settings echo CFLAGS= >> .make-settings echo LDFLAGS= >> .make-settings echo REDIS_CFLAGS= >> .make-settings echo REDIS_LDFLAGS= >> .make-settings echo PREV_FINAL_CFLAGS=-std=c99 -pedantic -DREDIS_STATIC='' -Wall -W -O2 -g -ggdb -I../deps/geohash-int -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src - DUSE_JEMALLOC -I../deps/jemalloc/include >> .make-settings echo PREV_FINAL_LDFLAGS= -g -ggdb -rdynamic >> .make-settings (cd ../deps && make hiredis linenoise lua geohash-int jemalloc) make[2]: 进入目录“/data/redis-3.2.11/deps” (cd hiredis && make clean) > /dev/null || true (cd linenoise && make clean) > /dev/null || true (cd lua && make clean) > /dev/null || true (cd geohash-int && make clean) > /dev/null || true (cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true (rm -f .make-*) (echo "" > .make-cflags) (echo "" > .make-ldflags) MAKE hiredis cd hiredis && make static make[3]: 进入目录“/data/redis-3.2.11/deps/hiredis” gcc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g - ggdb net.c make[3]: gcc:命令未找到 make[3]: *** [net.o] 错误 127 make[3]: 离开目录“/data/redis-3.2.11/deps/hiredis” make[2]: *** [hiredis] 错误 2 make[2]: 离开目录“/data/redis-3.2.11/deps” make[1]: [persist-settings] 错误 2 (忽略) CC adlist.o /bin/sh: cc: 未找到命令 make[1]: *** [adlist.o] 错误 127 make[1]: 离开目录“/data/redis-3.2.11/src” make: *** [all] 错误 2

    编译redis的tar.gz时候,先安装 c++相关包,需要先执行命令 :

    yum install gcc-c++

    2、redis requires Ruby version >= 2.2.2

    安装redis的时候,很多教程都是让直接执行 yum install ruby, 但是Centos7的yum 支持的ruby版本为2.0.0,再执行gem install redis  时,就会报这个错。则需要提升ruby的版本,有如下三种方式(具体可参见http://www.cnblogs.com/ding2016/p/7903147.html):

    1)、重新指定安装源(我用了这种方式,比较简单

    yum install centos-release-scl-rh # 会在/etc/yum.repos.d/目录下多出一个CentOS-SCLo-scl-rh.repo源

    yum install rh-ruby23  -y      # yum安装ruby

    scl  enable  rh-ruby23 bash      # 必要一步

    ruby -v                                 # 查看安装版本

    2)、可以使用 离线下载ruby包的形式安装

    3)、先安装rvm,再升级ruby

    一定不要用rvm方式安装,坑死了,后面还有很多问题。

     

    3、Waiting for the cluster to join...

       

    [root@localhost src]# ./redis-trib.rb create --replicas 1 192.168.31.220:7001 192.168.31.220:7002 192.168.31.147:7003 192.168.31.147:7004 192.168.31.109:7005 192.168.31.109:7006 >>> Creating cluster >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 192.168.31.220:7001 192.168.31.147:7003 192.168.31.109:7005 Adding replica 192.168.31.147:7004 to 192.168.31.220:7001 Adding replica 192.168.31.220:7002 to 192.168.31.147:7003 Adding replica 192.168.31.109:7006 to 192.168.31.109:7005 M: 94fbbeba149e6a2173f5bdca67172c146a905895 192.168.31.220:7001 slots:0-5460 (5461 slots) master S: c511fa8328b339f56d4be1b028ecef731ea909f0 192.168.31.220:7002 replicates ce9c7eba97475450332a121843ec3a125efe1dcd M: ce9c7eba97475450332a121843ec3a125efe1dcd 192.168.31.147:7003 slots:5461-10922 (5462 slots) master S: 987d268f8172305942c5b18ead8fafa03d359eef 192.168.31.147:7004 replicates 94fbbeba149e6a2173f5bdca67172c146a905895 M: ca14e60a255922b4e05a02361e8476b4310422d3 192.168.31.109:7005 slots:10923-16383 (5461 slots) master S: eb085c7254ec3a04a3941282c7b465baccea9d4d 192.168.31.109:7006 replicates ca14e60a255922b4e05a02361e8476b4310422d3 Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join.................................... ........................................................

        执行ruby命令组成集群时,集群之间会通过总线端口(节点端口+1000为总线端口,如当前节点的端口为7001则该总线端口为17001)进行通信,若各服务器之前的端口的防火墙没有打开则会一直处理 join 中。需要关闭防火墙,或者打开防火墙端口,一般生产环境最好不要关闭防火墙,则在每台服务器执行命令:

    firewall-cmd --zone=public --add-port=7001/tcp --permanent

     

    4、[ERR] Node xxx is not empty. Either the node already knows other no...

    [root@localhost src]# ./redis-trib.rb create --replicas 1 192.168.31.220:7001 192.168.31.220:7002 192.168.31.147:7003 192.168.31.147:7004 192.168.31.109:7005 192.168.31.109:7006 >>> Creating cluster [ERR] Node 192.168.31.220:7001 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.

        由于上一步没有打开端口就去执行 ./redis-trib.rb create --replicas 1 命令,后面我直接用 Ctrl + c关闭了上一步,开启端口后,又去执行上面的命令时,就会出现该问题。需要执行以下步骤:

    1)、删除每个redis节点的备份文件,数据库文件和集群配置文件

    包括appendonly.aof、dump.rdb、node_xxx.conf等信息,需要根据每个节点的 redis.conf 配置文件的配置位置去删除,我这边只删除了dir目录下的文件就ok了,如下:

    dir /usr/local/redis-cluster/redis-1/7001 # 文件夹下创建的信息等,也需要进行删除

    2)、使用redis-cli 命令为每个节点执行以下命令

    先使用命令 ./redis-cli -c -h 192.168.31.1 -p 7001 方式链接到每一个节点,再执行:

    flushdb

    cluster reset

    3)、最后再去执行刚才的 ./redis-trib.rb命令

     

    最新回复(0)