Redis支持cluster和sentinel同时配置吗?

bing_chuan 发布于 2016/05/27 15:37
阅读 499
收藏 1

今天折腾了一天,以前sentinel配置在spring已经成功。

<bean id="redisSentinelConfiguration"
          class="org.springframework.data.redis.connection.RedisSentinelConfiguration">
        <property name="master">
            <bean class="org.springframework.data.redis.connection.RedisNode">
                <property name="name" value="master1"></property>
            </bean>
        </property>
        <property name="sentinels">
            <set>
                <bean class="org.springframework.data.redis.connection.RedisNode">
                    <constructor-arg index="0" value="127.0.0.1" />
                    <constructor-arg index="1" value="26301" />
                </bean>
                <bean class="org.springframework.data.redis.connection.RedisNode">
                    <constructor-arg index="0" value="127.0.0.1" />
                    <constructor-arg index="1" value="26302" />
                </bean>
                <bean class="org.springframework.data.redis.connection.RedisNode">
                    <constructor-arg index="0" value="127.0.0.1" />
                    <constructor-arg index="1" value="26303" />
                </bean>
            </set>
        </property>
    </bean>



配置cluster后就抛异常(原因是分片 moved异常),因为集群会分片,每个节点都会指定不同的槽位,当发现不是自己负责的槽位就会转发到另一个节点去处理。

node1主配置

# Redis configuration file example
################################## INCLUDES ###################################
# include /path/to/local.conf
# include /path/to/other.conf
################################ GENERAL  #####################################
daemonize yes
pidfile /var/run/redis_master_6301.pid
port 6301
tcp-backlog 511
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1
# unixsocket /tmp/redis.sock
# unixsocketperm 700
timeout 0
tcp-keepalive 0
loglevel notice
logfile "/Users/lbc/run/logs/log_master_6301.log"
databases 16
################################ SNAPSHOTTING  ################################
save ""
# save 900 1
# save 300 10
# save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum no
dbfilename dump_6301.rdb
dir /Users/lbc/run/data
################################# REPLICATION #################################
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
# repl-ping-slave-period 10
# repl-timeout 60
repl-disable-tcp-nodelay no
# repl-backlog-size 1mb
# repl-backlog-ttl 3600
slave-priority 100
# min-slaves-to-write 3
# min-slaves-max-lag 10
################################## SECURITY ###################################
# rename-command CONFIG ""
################################### LIMITS ####################################
# maxclients 10000
# maxmemory <bytes>
# maxmemory-policy noeviction
# maxmemory-samples 5
############################## APPEND ONLY MODE ###############################
appendonly no
appendfilename "appendonly_6301.aof"
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
################################ LUA SCRIPTING  ###############################
lua-time-limit 5000
################################ REDIS CLUSTER  ###############################
cluster-enabled yes
cluster-config-file /Users/lbc/config/nodes-6301.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128
################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0
############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""
############################### ADVANCED CONFIG ###############################
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
已经启动
cluster-enabled yes
从配置我就不贴了,配置了3主3从3 sentinel

主端口6301  7302 8303,从端口:6315,6316,6317  ,sentinel端口:26301,26302,26303,

然后使用

CLUSTER MEET 127.0.0.1 7302
CLUSTER MEET 127.0.0.1 8303
用命令让他们加入集群,然后分别指定槽位

7848e1a4829add5598d49244a7c7d09361f61cf5 127.0.0.1:6301 myself,master - 0 0 2 connected 0-5000
6e65e7d77de1b8cbd01baffa3ffcf437766925a8 127.0.0.1:7302 master - 0 1464358411253 1 connected 5001-10000
9ceb8b8772d50d3468692ddab42013614d8c6d70 127.0.0.1:8303 master - 0 1464358412061 0 connected 1001-16383

到此配置结束,大神们,你们是怎么配置结合的?我使用的是org.springframework.data.redis框架(1.7.1)。

加载中
返回顶部
顶部