CentOS Builds redis-cluster Cluster

Preparations for Cluster Construction
Create redis-cluster directory under / usr/local

mkdir /usr/local/redis-cluster

Previously, if you installed a stand-alone version, you could copy the installed directory.
Installation reference for stand-alone version
Copy the redis directory as a whole into redis-cluster and rename it redis01

cp -r redis redis-cluster/redis01

Enter redis01 and delete the original dump.rdb backup file

Modify redis.conf VI redis.conf

Delete # before cluster-enabled yes
wq preservation
To the redis-cluster directory, copy redis01 to the current directory

cp -r redis01 redis02

At least six redis are required to form a cluster (three masters, three backups)

Modify port port 7001-7006 of redis.conf in turn
Create a batch startAll.sh file in the redis-cluster directory

Set startAll.sh as an executable file

chmod +x startAll.sh

In the same way, create a file shutdownAll.sh to close the redis cluster

Start cluster


View process

ps aux | grep -i redis

Cluster building
To build redis cluster, we need to use ruby script and install ruby running environment.
Install ruby

yum install ruby
yum install rubygems

Upload redis-3.0.0.gem (I can find it without this file) to Linux and install it

gem install redis-3.0.0.gem

Copy the redis-trib.rb script file under redis-3.0.0/src to / usr/local/redis-cluster

cp redis-3.0.0/src/redis-trib.rb /usr/local/redis-cluster

Run the script

/ redis-trib.rb create-replicas 1 server address: 7001 server address: 7002 server address: 7003
Server Address: 7004 Server Address: 7005 Server Address: 7006

./redis-trib.rb create --replicas 1

Input yes to start building clusters

The following picture appears and the building is completed.

Linking Clusters with redis-cli

redis01/bin/redis-cli -p 700x -c

Viewing Cluster Information

cluster info

View Cluster Nodes

cluster nodes

Test link redis-cluster cluster cluster

    public void testJedisCluster() throws Exception{
        //Create a jedisCulster object and construct the parameter Set type. Each element in the set is HostAndPort type.
        Set<HostAndPort> nodes = new HashSet<>();
        //Adding nodes to a collection
        nodes.add(new HostAndPort("",7001));
        nodes.add(new HostAndPort("",7002));
        nodes.add(new HostAndPort("",7003));
        nodes.add(new HostAndPort("",7004));
        nodes.add(new HostAndPort("",7005));
        nodes.add(new HostAndPort("",7006));
        //Using JedisCluster directly to operate redis, with connection pools, jedisCluster objects can be singletons
        JedisCluster jedisCluster = new JedisCluster(nodes);
        jedisCluster.set("testCluster", "jedis-cluster-test");
        //Close connection pool

We still need to pay attention to the problem of firewalls. Configuration of firewalls is as follows

Restart firewall service iptables restart

Keywords: Redis Ruby yum Linux

Added by lookielookies on Mon, 20 May 2019 03:45:24 +0300