redis 哨兵模式注意事项

sentinel 配置

开启远程连接

 

使用阿里云服务器

142.19.35.253 为阿里局域网ip

172.19.35.283 为网ip

部署机器的ip

bind 142.19.35.253
开启远程连接
protected-mode no

设置主节点,如果需要远程连接 此处的ip需要使用外部ip使用

sentinel monitor mymaster 172.19.35.283 6379 2

 

代码使用Spring Data redis

<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxTotal" value="2048" />
        <property name="maxIdle" value="200" />
        <property name="numTestsPerEvictionRun" value="1024" />
        <property name="timeBetweenEvictionRunsMillis" value="30000" />
        <property name="minEvictableIdleTimeMillis" value="-1" />
        <property name="softMinEvictableIdleTimeMillis" value="10000" />
        <property name="maxWaitMillis" value="1500" />
        <property name="testOnBorrow" value="true" />
        <property name="testWhileIdle" value="true" />
        <property name="testOnReturn" value="false" />
        <property name="jmxEnabled" value="true" />
        <property name="blockWhenExhausted" value="false" />
    </bean>

    <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="mymaster">
                </property>
            </bean>
        </property>
        <property name="sentinels">
            <set>
                <bean class="org.springframework.data.redis.connection.RedisNode">
                    <constructor-arg name="host" value="172.19.35.283" />
                    <constructor-arg name="port" value="26379" />
                </bean>
              <bean class="org.springframework.data.redis.connection.RedisNode">
                    <constructor-arg name="host" value="172.19.35.283" />
                    <constructor-arg name="port" value="26380" />
                </bean>
                <bean class="org.springframework.data.redis.connection.RedisNode">
                    <constructor-arg name="host" value="172.19.35.283" />
                    <constructor-arg name="port" value="26381" />
                </bean>
            </set>
        </property>
    </bean>
    <bean id="redisConnectionFactory"
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
        p:password="11223344">
        <constructor-arg name="sentinelConfig" ref="redisSentinelConfiguration"></constructor-arg>
        <constructor-arg name="poolConfig" ref="jedisPoolConfig"></constructor-arg>
        <property name="database" value="6" />
        <property name="timeout" value="20000" />
    </bean>
    
    <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
        <property name="connectionFactory" ref="redisConnectionFactory" />
        <!-- 序列化方式 建议key/hashKey采用StringRedisSerializer。 -->
        <property name="keySerializer">
            <bean
                class="org.springframework.data.redis.serializer.StringRedisSerializer" />
        </property>
        <property name="hashKeySerializer">
            <bean
                class="org.springframework.data.redis.serializer.StringRedisSerializer" />
        </property>
        <property name="valueSerializer">
            <bean
                class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
        </property>
        <property name="hashValueSerializer">
            <bean
                class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
        </property>
    </bean>
 

 

遇到的问题,sentinel monitor mymaster 172.19.35.283 6379 2 此处的ip开始设置为局域网ip。程序连接超时,修改为外网ip后正常

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值