Redis cluster installation and Java applications

Source: Internet
Author: User
Tags download redis redis cluster install redis

The first is to install redis3.0 under LinuxBelow is the success of my installation in CentOS 6.5. The content is mainly the content of http://redisdoc.com/topic/cluster-tutorial.html and some methods of dealing with the pits. Redis Cluster Deployment documentation (CENTOS6 System) (to enable the cluster to function at least 3 primary nodes, here we will create 6 Redis nodes, of which three are the primary node, three are the slave nodes, the corresponding Redis node corresponding to the IP and port relationship) 127.0.0.1 : 7000

127.0.0.1:7001

127.0.0.1:7002

127.0.0.1:7003

127.0.0.1:7004

127.0.0.1:7005

1: Download Redis. Download 3.0. version 0, previous 2. The cluster mode is not supported (3.0.3 is deployed on the server)

: https://github.com/antirez/redis/archive/3.0.0-rc2.tar.gz

2: Upload server, unzip, compile

TAR-ZXVF redis-3.0.0-rc2.tar.gz

MV Redis-3.0.0-rc2.tar.gz redis3.0

cd/usr/local/redis3.0

Make

Make install


3: Create the directory required by the cluster

Mkdir-p/usr.local/cluster

Cd/usr.local/cluster

mkdir 7000

mkdir 7001

mkdir 7002

mkdir 7003

mkdir 7004

mkdir 7005

4: Modify configuration file redis.conf

Cp/usr/local/redis3.0/redis.conf/usr.local/cluster

VI redis.conf

# #修改配置文件中的下面选项

Port 7000

Daemonize Yes

cluster-enabled Yescluster-config-file nodes.conf This way the official said this configuration, but it is best to cluster-config-file nodes-7000.conf such a son, is the nodes-port number. form of conf

Cluster-node-timeout 5000

AppendOnly Yes finally configures the location of log logfile "/data/logs/redis.7000.log" I use the port number to differentiate,

# #修改完redis These configuration entries in the. conf configuration file, copy the configuration file to the 7000/7001/7002/7003/7004/7005 directory, respectively.

cp/usr/local/cluster/redis.conf/usr/local/cluster/7000

cp/usr/local/cluster/redis.conf/usr/local/cluster/7001

cp/usr/local/cluster/redis.conf/usr/local/cluster/7002

cp/usr/local/cluster/redis.conf/usr/local/cluster/7003

cp/usr/local/cluster/redis.conf/usr/local/cluster/7004

cp/usr/local/cluster/redis.conf/usr/local/cluster/7005

# #注意: To modify the port parameter in the redis.conf file under the 7001/7002/7003/7004/7005 directory after the copy is complete, change the name of the corresponding folder

If you want to add a listener sentinel.conf, the method and add redis.conf similar to the modified parameter is the first: Port 27000 is the original port before adding 2 second: Sentinel Monitor MyMaster 192.168.1.223 7000 25: Start each of the 6 Redis instances separately

cd/usr/local/cluster/7000

Redis-server redis.conf

cd/usr/local/cluster/7001

Redis-server redis.conf

cd/usr/local/cluster/7002

Redis-server redis.conf

cd/usr/local/cluster/7003

Redis-server redis.conf

cd/usr/local/cluster/7004

Redis-server redis.conf

cd/usr/local/cluster/7005

Redis-server redis.conf

# #启动之后使用命令查看redis的启动情况ps-ef|grep Redis

6: Execute redis Create cluster command to create cluster

CD/USR/LOCAL/REDIS3.0/SRC./REDIS-TRIB.RB Create--replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005(Java test here, show too many redirection, resolve to change 127.0.0.1 to ip,./ REDIS-TRIB.RB Create--replicas 1 192.168.1.223:7000 192.168.1.223:7001 192.168.1.223:7002 192.168.1.223:7003 192.168.1.223:7004 192.168.1.223:7005) (This is the right one)

6.1 error occurs when executing the above command, because it is the Ruby script that is executed and requires the environment of Ruby

Error content:/usr/bin/env:ruby:no such file or directory

So you need to install Ruby's environment, it is recommended to use Yum install Ruby installation

Yum Install Ruby

6.2 Then perform the 6th step of the creation of the cluster command, but also error, the lack of rubygems components, using Yum installation If this time the report can not be downloaded from an IP, similar to first execute this code sed-i ' s/192.168.1.127/ 172.20.1.11/g '/etc/yum.repos.d/*

Error content:

./redis-trib.rb:24:in ' require ': No such file to load--rubygems (Loaderror)

From./redis-trib.rb:24

Yum Install RubyGems
Error content:6.3 Execute the 6th step again with an error indicating that Redis could not be loaded because of the lack of the Redis and Ruby interfaces, using the GEM installation

/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in ' Gem_original_require ': No such file to load--Redis ( Loaderror)

From/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in ' require '

From./redis-trib.rb:25

Gem Install Redis

6.4 Execute the 6th step command again, normal execution

Enter Yes, and the configuration is complete.

This is where the Redis cluster is built successfully!

7: Use the REDIS-CLI command to enter the cluster environment

Redis-cli-c-P 7000

View status with cluster info

8: If external access is not available, internal accessprocessing Method One: Check whether the iptables port number, not open,configure it in the iptables in/etc/sysconfigTreatment method Two: Direct shutdown service iptables stop The second is to integrate into the project. SPRINGMVC frame. First Pom.xml file:

<spring.version>4.2.3.RELEASE</spring.version> Spring-data-redis 1.7.0 is supported for more than 4.1 versions
<jackson.version>2.6.4</jackson.version> Support spring4.2.3
<jackson-dataformat-xml.version>2.6.3</jackson-dataformat-xml.version> Support spring4.2.3
<jedis.version>2.8.0</jedis.version> currently supports Redis cluster comparison new version (Https://github.com/xetorthio/jedis)
<springdataredis.version>1.7.0.M1</springdataredis.version> support for Redis clusters (http://projects.spring.io/ spring-data-redis/)

Second applicationcontext-redis.xml configuration file:

<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xmlns:context= "Http://www.springframework.org/schema/context"
xmlns:p= "http://www.springframework.org/schema/p"
Xsi:schemalocation= "Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-3.0.xsd ">

<context:property-placeholder location= "Classpath:jdbc.properties"/>

<bean id= "Jedisconnectionfactory" class= " Org.springframework.data.redis.connection.jedis.JedisConnectionFactory ">
<constructor-arg name= "Clusterconfig" ref= "Redisclusterconfiguration" ></constructor-arg>
</bean>

<bean id= "clusterRedisNodes1" class= "Org.springframework.data.redis.connection.RedisNode" >
<constructor-arg value= "${redis.ip}"/>
<constructor-arg value= "${redis.port}" type= "int"/>
</bean>
<!--setter Mode injection--
<bean id= "Redisclusterconfiguration" class= " Org.springframework.data.redis.connection.RedisClusterConfiguration ">
<property name= "Clusternodes" >
<set>
<ref bean= "ClusterRedisNodes1"/>
</set>
</property>
</bean>
<bean id= "Redistemplate" class= "Org.springframework.data.redis.core.RedisTemplate" >
<property name= "ConnectionFactory" ref= "Jedisconnectionfactory" ></property>
<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.StringRedisSerializer"/>
</property>
<property name= "Hashvalueserializer" >
<bean class= "Org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>
</property>
</bean>

</beans>

Third

In the class

@Autowired
protected Redistemplate redistemplate;

Then Redistemplate.opsforvalue (). Set ("foo", "Test");

Redis cluster installation and Java applications

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.