Spring之Redis集群搭建

1.创建cluster文件夹并拷贝6个redis的配置文件redis.conf到cluster

Spring之Redis集群搭建 Spring之Redis集群搭建

其它文件是运行时生成的,先不要管,看画红色框的文件,然后修改配置

2.修改配置文件

redis6001.conf

Spring之Redis集群搭建 Spring之Redis集群搭建 Spring之Redis集群搭建 Spring之Redis集群搭建 Spring之Redis集群搭建

其它文件如redis6002.conf是相同的设置,只是把端口改为6002和集群配置文件改为nodes-6002,依次类推。。。

3.创建shell脚本

开启Redis节点并创建集群

Spring之Redis集群搭建

输入yes

注意:如果想要外网访问,在创建Redis集群时,要用外网IP:端口号

关闭Redis节点

Spring之Redis集群搭建

查看集群信息

Spring之Redis集群搭建

4.pom.xml

Spring之Redis集群搭建

5.redis配置

<context:property-placeholder location="classpath:jdbc.properties,classpath:redis.properties" /> <!--redis配置-->         <!--redis连接池配置-->     <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">         <property name="maxIdle" value="${redis.maxIdle}" />         <property name="maxTotal" value="${redis.maxActive}" />         <property name="maxWaitMillis" value="${redis.maxWait}" />         <property name="testOnBorrow" value="${redis.testOnBorrow}" />         <!-- 每次释放连接的最大数目 -->         <property name="numTestsPerEvictionRun" value="1024" />         <!-- 释放连接的扫描间隔(毫秒) -->         <property name="timeBetweenEvictionRunsMillis" value="30000" />     </bean>     <bean id="redisHost1" class="redis.clients.jedis.HostAndPort">         <constructor-arg name="host" value="${redis.host1}" />         <constructor-arg name="port" value="${redis.port1}" />     </bean>     <bean id="redisHost2" class="redis.clients.jedis.HostAndPort">         <constructor-arg name="host" value="${redis.host2}" />         <constructor-arg name="port" value="${redis.port2}" />     </bean>     <bean id="redisHost3" class="redis.clients.jedis.HostAndPort">         <constructor-arg name="host" value="${redis.host3}" />         <constructor-arg name="port" value="${redis.port3}" />     </bean>     <bean id="redisHost4" class="redis.clients.jedis.HostAndPort">         <constructor-arg name="host" value="${redis.host4}" />         <constructor-arg name="port" value="${redis.port4}" />     </bean>     <bean id="redisHost5" class="redis.clients.jedis.HostAndPort">         <constructor-arg name="host" value="${redis.host5}" />         <constructor-arg name="port" value="${redis.port5}" />     </bean>     <bean id="redisHost6" class="redis.clients.jedis.HostAndPort">         <constructor-arg name="host" value="${redis.host6}" />         <constructor-arg name="port" value="${redis.port6}" />     </bean>     <bean id="redisCluster" class="redis.clients.jedis.JedisCluster">         <constructor-arg name="nodes">             <set>                 <ref bean="redisHost1" />                 <ref bean="redisHost2" />                 <ref bean="redisHost3" />                 <ref bean="redisHost4" />                 <ref bean="redisHost5" />                 <ref bean="redisHost6" />             </set>         </constructor-arg>         <constructor-arg name="poolConfig">             <ref bean="jedisPoolConfig" />         </constructor-arg>      </bean>

6.redis.properties 

redis.host1=192.168.1.203 redis.port1=6001 redis.host2=192.168.1.203 redis.port2=6002 redis.host3=192.168.1.203 redis.port3=6003 redis.host4=192.168.1.203 redis.port4=6004 redis.host5=192.168.1.203 redis.port5=6005 redis.host6=192.168.1.203 redis.port6=6006 redis.maxIdle=50 redis.maxActive=100 redis.maxWait=5000 redis.testOnBorrow=true
  

版权声明:玥玥 发表于 2021-04-28 9:11:31。
转载请注明:Spring之Redis集群搭建 | 女黑客导航