标签:
同一物理机部署6个Redis进程,7001、7002、7003端口为Master进程、7004、7005、7006端口为Slave进程。多机部署时注意配对的Master和Slave不在同一物理机上即可。
1. 下载源代码文件redis-3.0.0.tar.gz
2. 解压tar -xzvf redis-3.0.0..tar.gz
3. 进入目录 cd redis-3.0.0
4. 编译make
5. 安装 make install
6. 创建6个目录用来存放每个进程的配置文件和数据mkdir 7001至7006
7. cp redis.conf 7001/至7006/文件夹下
至此7001至7006这6个目录下均有redis.conf配置件。
6个redis.conf配置文件相同,注意修改下黄色字体部分的内容即可,其他都相同
配置选项 |
值 |
描述 |
daemonize |
yes |
|
logfile |
"/opt/log/redis-7001.log" |
|
databases |
1 |
|
dir |
/opt/oracle/redis-3.0.0/7001 |
用来存放数据的地方 |
cluster-enabled |
yes |
|
cluster-config-file |
/opt/oracle/redis-3.0.0/7001/nodes.conf |
|
cluster-node-timeout |
15000 |
|
cluster-migration-barrier |
1 |
|
cluster-require-full-coverage |
yes |
只要集群中有一对Master-Slave不可用时,整个集群不可用 |
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxTotal" value="30" /> <property name="maxIdle" value="10" /> <property name="minIdle" value="10" /> <property name="blockWhenExhausted" value="true"></property> <property name="maxWaitMillis" value="3000" /> <property name="testOnBorrow" value="false" /> <property name="testOnReturn" value="false" /> <property name="testWhileIdle" value="false" /> </bean> <bean id="jedisCluster" class="redis.clients.jedis.JedisCluster"> <constructor-arg index="0"> <set> <bean class="redis.clients.jedis.HostAndPort"> <constructor-arg index="0" value="192.168.126.131" /> <constructor-arg index="1" value="7001" type="int" /> </bean> <bean class="redis.clients.jedis.HostAndPort"> <constructor-arg index="0" value="192.168.126.131" /> <constructor-arg index="1" value="7002" type="int" /> </bean> <bean class="redis.clients.jedis.HostAndPort"> <constructor-arg index="0" value="192.168.126.131" /> <constructor-arg index="1" value="7003" type="int" /> </bean> <bean class="redis.clients.jedis.HostAndPort"> <constructor-arg index="0" value="192.168.126.131" /> <constructor-arg index="1" value="7004" type="int" /> </bean> <bean class="redis.clients.jedis.HostAndPort"> <constructor-arg index="0" value="192.168.126.131" /> <constructor-arg index="1" value="7005" type="int" /> </bean> <bean class="redis.clients.jedis.HostAndPort"> <constructor-arg index="0" value="192.168.126.131" /> <constructor-arg index="1" value="7006" type="int" /> </bean> </set> </constructor-arg> <constructor-arg index="1" value="15000" type="int"></constructor-arg> <constructor-arg index="2" ref="jedisPoolConfig"></constructor-arg> </bean>
@Test public void test8(){ System.out.println(jedisCluster); for(int i=0;i<1000;i++){ jedisCluster.set(""+i, ""+i); } //使用是不用关闭的,JedisCluster内部会自动关闭 }
标签:
原文地址:http://my.oschina.net/u/1274122/blog/402292