redis linux-集群配置流程

一。配置修改

   1.在/usr/local/redis-3.2.7下新建目录

   cluster/6379

   ....

   cluster/6384

 由于redis集群需要3个master所以最少要6个服务所以需要6个文件夹 

2.在每个目录下拷贝redis.conf


   3.在redis linux-单个配置流程配置基础上 修改/usr/local/redis-3.2.7/cluster/6379/redis.conf

          logfile "/usr/local/redis-3.2.7/cluster/6379/redis-6379.log"

dir "/usr/local/redis-3.2.7/cluster/6379/"

721行:cluster-enabled  yes 

729行: cluster-config-file nodes-6379.conf

735行:cluster-node-timeout  5000


二。redis集群需要使用ruby,安装ruby


yum -y  install zlib ruby rubygems


安装ruby的redis

gem install redis


升级ruby安装的软件

gem update --system

gem update


查看ruby安装的软件的结合

gem list


三。启动所有redis服务

./redis-server /usr/local/redis-3.2.7/cluster/6379/redis.conf

     ......

     ./redis-server /usr/local/redis-3.2.7/cluster/6384/redis.conf

四.修改集群密码

打开:/usr/lib64/ruby/gems/1.8/gems/redis-3.3.3/lib/redis/client.rb

修改password为设置的密码


四。执行./redis-trib.rb create --replicas 1 ip:6379 ...... ip:6384


  如果成功会显示如下:

  


五:错误处理

  1.Node XXX:6380 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.

  处理方法:登录到对应server ./redis-cli -h 120.77.61.47 -p 6380

        清除数据:flashdb

  2.大部分启动问题可以删除/usr/local/redis-3.2.7/cluster/6379中除去redis.conf其他所有文件再启动


六。spring-data-redis配置

redis-cluster.properties

#JedisPoolConfig的参数

#最大连接数

redis.pool.maxTotal=30

#最大空闲时间

redis.pool.maxIdle=10

#每次最大连接数

redis.pool.numTestsPerEvictionRun=1024

#释放扫描的扫描间隔

redis.pool.timeBetweenEvictionRunsMillis=30000

#连接的最小空闲时间

redis.pool.minEvictableIdleTimeMillis=1800000

#连接控歘按时间多久后释放,当空闲时间>该值且空闲连接>最大空闲连接数时直接释放

redis.pool.softMinEvictableIdleTimeMillis=10000

#获得链接时的最大等待毫秒数,小于0:阻塞不确定时间,默认-1

redis.pool.maxWaitMillis=1500

#在获得链接的时候检查有效性,默认false

redis.pool.testOnBorrow=true

#在空闲时检查有效性,默认false

redis.pool.testWhileIdle=true

#连接耗尽时是否阻塞,false报异常,true阻塞超时,默认true

redis.pool.blockWhenExhausted=false

#RedisClusterConfiguration配置

redis.maxRedirects=5

#密码

redis.password=mju76yhN

#主机和端口号

redis.host1=120.77.61.XX

redis.port1=6379

redis.host2=120.77.61.XX

redis.port2=6380

redis.host3=120.77.61.XX

redis.port3=6381

redis.host4=120.77.61.XX

redis.port4=6382

redis.host5=120.77.61.XX

redis.port5=6383

redis.host6=120.77.61.XX

redis.port6=6384


spring-redis-cluster.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">


<!--引入配置文件 -->
<bean id="placeholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="order" value="1" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<list>
<value>classpath:properties/redis-cluster.properties</value>
</list>
</property>
</bean>


<!--配置 jedis pool -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<!-- 最大连接数 -->
<property name="maxTotal" value="${redis.pool.maxTotal}" />
<!-- 最大空闲时间 -->
<property name="maxIdle" value="${redis.pool.maxIdle}" />
<!-- 每次最大连接数 -->
<property name="numTestsPerEvictionRun" value="${redis.pool.numTestsPerEvictionRun}" />
<!-- 释放扫描的扫描间隔 -->
<property name="timeBetweenEvictionRunsMillis" value="${redis.pool.timeBetweenEvictionRunsMillis}" />
<!-- 连接的最小空闲时间 -->
<property name="minEvictableIdleTimeMillis" value="${redis.pool.minEvictableIdleTimeMillis}" />
<!-- 连接控歘按时间多久后释放,当空闲时间>该值且空闲连接>最大空闲连接数时直接释放 -->
<property name="softMinEvictableIdleTimeMillis" value="${redis.pool.softMinEvictableIdleTimeMillis}" />
<!-- 获得链接时的最大等待毫秒数,小于0:阻塞不确定时间,默认-1 -->
<property name="maxWaitMillis" value="${redis.pool.maxWaitMillis}" />
<!-- 在获得链接的时候检查有效性,默认false -->
<property name="testOnBorrow" value="${redis.pool.testOnBorrow}" />
<!-- 在空闲时检查有效性,默认false -->
<property name="testWhileIdle" value="${redis.pool.testWhileIdle}" />
<!-- 连接耗尽时是否阻塞,false报异常,true阻塞超时 默认:true -->
<property name="blockWhenExhausted" value="${redis.pool.blockWhenExhausted}" />
</bean>




<!--配置RedisClusterConfiguration -->
<bean id="redisClusterConfiguration"
class="org.springframework.data.redis.connection.RedisClusterConfiguration">
<property name="maxRedirects" value="${redis.maxRedirects}"></property>
<property name="clusterNodes">
<set>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="${redis.host1}" />
<constructor-arg name="port" value="${redis.port1}" />
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="${redis.host2}" />
<constructor-arg name="port" value="${redis.port2}" />
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="${redis.host3}" />
<constructor-arg name="port" value="${redis.port3}" />
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="${redis.host4}" />
<constructor-arg name="port" value="${redis.port4}" />
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="${redis.host5}" />
<constructor-arg name="port" value="${redis.port5}" />
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="${redis.host6}" />
<constructor-arg name="port" value="${redis.port6}" />
</bean>
</set>
</property>
</bean>


<!--配置JedisConnectionFactory -->
<bean id="jedisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="password" value="${redis.password}"/>
<constructor-arg name="poolConfig" ref="jedisPoolConfig" />
<constructor-arg name="clusterConfig" ref="redisClusterConfiguration" />
</bean>


<!--redisTemplate -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory" />
</bean>


</beans>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux Redis集群配置是一种在Linux操作系统上配置Redis集群的方法,它可以提供高可用性和横向扩展性。下面是一种常见的Redis集群配置方式: 1. 安装Redis:首先,在每个节点上安装Redis服务器。你可以从Redis官方网站下载最新版本的Redis,并按照官方文档进行安装。 2. 配置节点:在每个节点上,你需要编辑Redis配置文件redis.conf。你可以使用文本编辑器打开该文件,并进行以下配置: - 设置节点的端口号和绑定IP地址。 - 启用集群模式,设置cluster-enabled为yes。 - 设置集群节点超时时间,cluster-node-timeout。 - 设置集群的名称,cluster-announce-ip和cluster-announce-port。 3. 创建集群:选择一个节点作为主节点,使用redis-cli工具创建一个Redis集群。打开终端,执行以下命令: ``` redis-cli --cluster create <node1>:<port1> <node2>:<port2> ... <nodeN>:<portN> --cluster-replicas <replicas> ``` 其中,<node1>:<port1>等是节点的IP地址和端口号,<replicas>是每个主节点对应的从节点数量。 4. 添加节点:在集群创建后,你可以通过以下命令向集群添加更多的节点: ``` redis-cli --cluster add-node <new_node>:<port> <existing_node>:<port> ``` 其中,<new_node>:<port>是要添加的新节点的IP地址和端口号,<existing_node>:<port>是已存在的节点的IP地址和端口号。 5. 扩展集群:如果你想扩展集群,可以使用以下命令将一个从节点升级为主节点: ``` redis-cli --cluster reshard <node>:<port> ``` 其中,<node>:<port>是要升级的从节点的IP地址和端口号。 6. 监控集群:你可以使用redis-cli工具或者Redis的监控工具来监控Redis集群的状态和性能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值