redis3.2.8 cluster installation

[root@yunboce ]# tar -zxvf redis-3.2.8.tar.gz
[root@yunboce cluster]# cd redis-3.2.8
[root@yunboce cluster]#make
[root@yunboce cluster]#cd src
[root@yunboce cluster]# make install
[root@yunboce src]# mkdir /opt/cluster/redis_bin
[root@yunboce src]# cp redis* /opt/cluster/redis_bin/
[root@yunboce src]# ls /opt/cluster/redis_bin/
  redis-check-aof    redis-check-aof.o  redis-check-rdb.c  redis-cli       redis-server
redis-benchmark      redis-check-rdb     redis-sentinel  redis-trib.rb
[root@yunboce cluster]# cd redis_bin/
[root@yunboce redis_bin]# ls
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server  redis-trib.rb
[root@yunboce redis_bin]# chmod +x redis*
[root@yunboce redis_bin]# ll
总用量 34032
-rwxr-xr-x 1 root root 5574263 9月  12 16:18 redis-benchmark
-rwxr-xr-x 1 root root   22225 9月  12 16:18 redis-check-aof
-rwxr-xr-x 1 root root 7823906 9月  12 16:18 redis-check-rdb
-rwxr-xr-x 1 root root 5703131 9月  12 16:18 redis-cli
-rwxr-xr-x 1 root root 7823906 9月  12 16:18 redis-sentinel
-rwxr-xr-x 1 root root 7823906 9月  12 16:18 redis-server
-rwxr-xr-x 1 root root   60852 9月  12 16:18 redis-trib.rb
[root@yunboce redis_bin]# cd ..
[root@yunboce cluster]# ls
7000  7001  7002  7003  7004  7005  redis-3.2.8  redis-3.2.8.tar.gz  redis_bin
[root@yunboce cluster]# mv 7005 redis_bin/
[root@yunboce cluster]# llTotal
usage 1520
drwxrwxr-x 6 root root 4096 Feb 12 2017 redis-3.2.8
-rw-r--r-- 1 root root 1547237 Sep 12 15:41 redis-3.2.8.tar.gz
drwxr-xr-x 8 root root 4096 Sep 12 16:24 redis_bin
[root@yunboce cluster]#
[root@yunboce cluster]#
[root@yunboce cluster]# cd redis_bin
[root@yunboce cluster]#make 7000
[root@yunboce cluster]#cp /opt/cluster/redis-3.2.8/redis.conf /opt/cluster/redis_bin/7000/redis.conf
Modify redis The contents of .conf are as follows:
daemonize yes //redis runs
pidfile in the background /var/run/redis_7000.pid //pidfile corresponds to 7000, 7001, 7002, 7003
port 7000 //Port 7000,7002,7003
cluster-enabled yes //Enable the cluster and remove the comment #
cluster-config-file nodes_7000.conf //Cluster configuration The configuration file will automatically generate 7000,7001,7002
cluster-node- timeout 5000 //The request timeout setting of 5 seconds is enough
bind 192.168.6.24 127.0.0.1 //Binding id (note that the local id must be the first)
appendonly yes //Aof log is turned on if necessary, it will be turned on every time Write operations record a log
logfile "/var/log/redis/7000.log"

7001 7002 7003 7004 7005 The operation is the same as 7000
[root@yunboce redis_bin]# ls
7000 7001 7002 7003 7004 7005 redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server redis-trib.rb
[root@yunboce redis_bin]#
redis-sentinel  redis-server   
[root@yunboce redis_bin]# ./redis-server 7000/redis.conf
[root@yunboce redis_bin]# ./redis-server 7001/redis.conf
[root@yunboce redis_bin]# ./redis-server 7002/redis.conf
[root@yunboce redis_bin]# ./redis-server 7003/redis.conf
[root@yunboce redis_bin]# ./redis-server 7004/redis.conf
[root@yunboce redis_bin]# ./redis-server 7005/redis.conf
[root@yunboce redis_bin]#
[root@yunboce redis_bin]# ps -ef|grep redis
root     23389     1  0 16:24 ?        00:00:00 ./redis-server 192.168.6.24:7000 [cluster]
root     23393     1  0 16:24 ?        00:00:00 ./redis-server 192.168.6.24:7001 [cluster]
root     23424     1  0 16:25 ?        00:00:00 ./redis-server 192.168.6.24:7002 [cluster]
root     23428     1  0 16:25 ?        00:00:00 ./redis-server 192.168.6.24:7003 [cluster]
root     23432     1  0 16:25 ?        00:00:00 ./redis-server 192.168.6.24:7004 [cluster]
root     23436     1  0 16:25 ?        00:00:00 ./redis-server 192.168.6.24:7005 [cluster]
root     23440 16719  0 16:25 pts/10   00:00:00 grep redis
[root@yunboce redis_bin]#  netstat -tnlp | grep redis

[root@yunboce redis_bin]# yum -y install ruby ruby-devel rubygems rpm-build 
[root@yunboce redis_bin]# gem install redis
ERROR:  Error installing redis:
        redis requires Ruby version >= 2.2.2.
[root@yunboce redis_bin]# rvm list known
[root@yunboce redis_bin]#
[root@yunboce redis_bin]#
[root@yunboce redis_bin]# sudo yum install curl

[root@yunboce redis_bin]# curl -L get.rvm.io | bash -s stable
  % Total % Received % Xferd Average Speed ​​Time Time Time Time Current
                                 Dload Upload Total Spent Left Speed
​​100 24090 100 24090 0 0 10411 0 0:00:02 0:00:02 --:--:-- 185k
Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz .asc gpg:
Signature created on Mon Sep 11 04:59:21 CST 2017, using RSA, key number BF04FF17
gpg: Unable to check signature: No public key
Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found. Assuming you trust Michal Papis import the mpapis public key (downloading the signatures).

GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.3.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:

    gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

or if it fails:

    command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -

the key can be compared with:

    https://rvm.io/mpapis.asc
    https://keybase.io/mpapis

NOTE: GPG version 2.1.17 has a bug which cause failures during fetching keys from remote server. Please downgrade or upgrade to newer version (if available) or use the second method described above.

[root@yunboce redis_bin]# command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import
gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <[email protected]>" imported
gpg: total processed: 1
gpg: Imported: 1 (RSA: 1)
gpg: No absolute trusted keys found
[root@yunboce redis_bin]# curl -L get.rvm.io | bash -s stable
  % Total % Received % Xferd Average Speed ​​Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 24090 100 24090 0 0 11593 0 0:00:02 0:00:02 --:--:-- 11593
Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc
gpg: Signature created on Mon Sep 11 04:59:21 CST 2017 , using RSA, key number BF04FF17
gpg: good signature from "Michal Papis (RVM signing) <[email protected]>"
gpg: aka "Michal Papis <[email protected]>"
gpg: also i.e. "[jpeg image of size 5015]"
gpg: WARNING: This key is not certified by a trusted signature!
gpg: There is no evidence that this signature belongs to its purported holder.
Master key fingerprint: 409B 6B17 96C2 7546 2A17 0311 3804 BB82 D39D C0E3 Subkey
fingerprint: 62C9 E5F4 DA30 0D94 AC36 166B E206 C29F BF04 FF17
GPG verified '/usr/local/rvm/archives/rvm-1.29.3.tig
Creating group 'rvm'

Installing RVM to /usr/local/rvm/
            source /etc/profile
Installation of RVM in /usr/local/rvm/ is almost complete:

  * First you need to add all users that will be using rvm to 'rvm' group,
    and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.

  * To start using RVM you need to run `source /etc/profile.d/rvm.sh`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
[root@yunboce redis_bin]#





[root@yunboce redis_bin]# source /usr/local/rvm/scripts/rvm
查看ruby  版本
[root@yunboce redis_bin]# rvm list known
# MRI Rubies

查看当前版本
[root@yunboce redis_bin]#ruby -v
插入 ruby2.3.3
[root@yunboce redis_bin]# rvm install 2.3.3
Searching for binary rubies, this might take some time.
No binary rubies available for: centos/6/x86_64/ruby-2.3.3.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for centos.
Installing requirements for centos.
Installing required packages: libffi-devel, libyaml-devel.......
Requirements installation successful.
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.3.3, this may take a while depending on your cpu(s)...
ruby-2.3.3 - #downloading ruby-2.3.3, this may take a while depending on your connection...

curl: (35) SSL connect error
There was an error(35).
Checking fallback: https://ftp.ruby-lang.org/pub/ruby/2.3/ruby-2.3.3.tar.bz2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
This may have known and unaccounted for security vulnerabilities.
Please consider upgrading to ruby-2.4.1 which will have all of the latest security patches.
Ruby was built without documentation, to build it run: rvm docs generate-ri

使用ruby 2.3.3
[root@yunboce redis_bin]# rvm use 2.3.3   或者  rvm use 2.3.3 --default
Using /usr/local/rvm/gems/ruby-2.3.3

[root@yunboce redis_bin]# rvm remove 1.8.7
Check the current version
[root@yunboce redis_bin]# ruby ​​--version
ruby ​​2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
[root@yunboce redis_bin]#Execute
cluster command
[root@yunboce redis_bin]# gem install redis
Fetching: redis-4.0.0.gem (100%)
Successfully installed redis-4.0.0
Parsing documentation for redis-4.0.0
Installing ri documentation for redis-4.0.0
Done installing documentation for redis after 2 seconds
1 gem installed
[root@yunboce redis_bin]# cd ../redis-3.2.8/src
[root@yunboce src]#Create
a cluster
 Under the explanation, --replicas 1 means that each master node is automatically assigned a slave node with 6 nodes on it , the program will generate 3 masters (master) and 3 slaves (slave) according to certain rules

[root@yunboce src]# ./redis-trib.rb  create  --replicas  1  192.168.6.24:7000 192.168.6.24:7001  192.168.6.24:7002 192.168.6.24:7003  192.168.6.24:7004  192.168.6.24:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.6.24:7000
192.168.6.24:7001
192.168.6.24:7002
Adding replica 192.168.6.24:7003 to 192.168.6.24:7000
Adding replica 192.168.6.24:7004 to 192.168.6.24:7001
Adding replica 192.168.6.24:7005 to 192.168.6.24:7002
M: 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb 192.168.6.24:7000
   slots:0-5460 (5461 slots) master
M: 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3 192.168.6.24:7001
   slots:5461-10922 (5462 slots) master
M: 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a 192.168.6.24:7002
   slots:10923-16383 (5461 slots) master
S: 96f4f6da5b172544fd90e18990f64868bd18a14c 192.168.6.24:7003
   replicates 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb
S: dfd4d0e5dc242533af6cb7699e7052e11b10d619 192.168.6.24:7004
   replicates 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3
S: e83888d36f4b8c56e150015be38d7dd7a0ddcc39 192.168.6.24:7005
   replicates 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join...
>>> Performing Cluster Check (using node 192.168.6.24:7000)
M: 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb 192.168.6.24:7000
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3 127.0.0.1:7001
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: e83888d36f4b8c56e150015be38d7dd7a0ddcc39 127.0.0.1:7005
   slots: (0 slots) slave
   replicates 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a
S: 96f4f6da5b172544fd90e18990f64868bd18a14c 127.0.0.1:7003
   slots: (0 slots) slave
   replicates 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb
M: 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a 127.0.0.1:7002
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: dfd4d0e5dc242533af6cb7699e7052e11b10d619 127.0.0.1:7004
   slots: (0 slots) slave
   replicates 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

安装完毕.

测试redis集群

[root@yunboce redis]# ls
7000  7003  appendonly.aof   nodes-7001.conf  nodes-7004.conf  redis-check-aof  redis-sentinel
7001  7004  dump.rdb         nodes-7002.conf  nodes-7005.conf  redis-check-rdb  redis-server
7002  7005  nodes-7000.conf  nodes-7003.conf  redis-benchmark  redis-cli        redis-trib.rb
[root@yunboce redis]#
[root@yunboce redis]#
[root@yunboce redis]#
[root@yunboce redis]#
[root@yunboce redis]# ./redis-cli -c -p 7000
127.0.0.1:7000> set test1 bocehellowolrd
OK
127.0.0.1:7000> get test1
"bocehellowolrd"
127.0.0.1:7000> cluster nodes
e83888d36f4b8c56e150015be38d7dd7a0ddcc39 192.168.6.24:7005 slave 1f9bea3df531b159b294e32ca9d75e9f8ee34d0a 0 1505283170587 6 connected
82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb 192.168.6.24:7000 myself,master - 0 0 1 connected 0-5460
dfd4d0e5dc242533af6cb7699e7052e11b10d619 192.168.6.24:7004 slave 4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3 0 1505283171088 5 connected
1f9bea3df531b159b294e32ca9d75e9f8ee34d0a 192.168.6.24:7002 master - 0 1505283171589 3 connected 10923-16383
96f4f6da5b172544fd90e18990f64868bd18a14c 192.168.6.24:7003 slave 82eeb3e0350bbdc3639f12df48a6fe2ed70dd9fb 0 1505283172592 4 connected
4f8a24da4b6cf5bf5aeff6fea3cee97f1d243cc3 192.168.6.24:7001 master - 0 1505283169584 2 connected 5461-10922
127.0.0.1:7000>
127.0.0.1:7000> quit
[root@yunboce redis]# ./redis-cli -c -p 7001
127.0.0.1:7001> get test1
-> Redirected to slot [4768] located at 192.168.6.24:7000
"bocehellowolrd"
192.168.6.24:7000>




Java test code:


package com.alibaba.dubbo.demo.consumer;

import java.util.HashSet;
import java.util .Set;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

public class JedisClusterTest {


JedisCluster jedisCluster = null;

private String nameKey="test1" ;

    /**
     * Because it is a test, no singleton is written here
     */
   
    public void before(){
        Set<HostAndPort> nodes = new HashSet<HostAndPort>();   
        nodes.add(new HostAndPort("192.168.6.24",7000));
        nodes.add(new HostAndPort("192.168.6.24",7001)); 
        nodes.add(new HostAndPort("192.168.6.24",7002)) ;
        nodes.add(new HostAndPort("192.168.6.24",7003));
       nodes.add(new HostAndPort("192.168.6.24",7004));
       nodes.add(new HostAndPort("192.168.6.24",7005) );
        //Note: the timeout time here should not be too short, it will have a timeout retry mechanism. And other RPC frameworks like httpclient, dubbo should also pay attention to this
        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
        config.setMaxIdle(200);
        config.setMaxTotal(300);
        config.setTestOnReturn(true);
       
       
        jedisCluster = new JedisCluster(nodes, 10000, 1000, 1,


        System.out.println(jedisCluster+"===");
        System.out.println(jedisCluster.set("test1", "Zhang San"));
        System.out.println(jedisCluster.get("test1")) ;
    }

    /**
     * Simple string reading and writing
     */

    public void setStringData(){
   
      // System.out.println(jedisCluster.set("test1", "Zhang San"));
        System.out.println(jedisCluster. get("test1"));
    }

    /**
     * setnx : If the key exists, return 0, if not, the setting is successful.
     * setnx means set if not exist.
     */
  
    public void setnxTest(){
       // System.out.println(jedisCluster.setnx(nameKey, "Zhang San"));//key does not exist, the return value is 1
        System.out.println(jedisCluster.get(nameKey));

      // System.out.println(jedisCluster.setnx(nameKey, "Zhang San"));//Already exists, the return value is 0
        System.out.println( jedisCluster.get(nameKey));
    }

 

   
   
    public static void main(String[] args) {

    JedisClusterTest test = new JedisClusterTest();
    test.before();
    test.setStringData();
   
    test.setnxTest();
}


}



redis cluster After configuration and running for a period of time, we want to add nodes, or delete nodes,
please refer to:
http://blog.51yip.com/nosql/1726.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326250136&siteId=291194637