Redis cluster installation

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

A Redis cluster is an assembly that provides the sharing of data among multiple Redis nodes. redis3.0 Previously, only support master-slave synchronization, if the main is hung, write a problem. 3.0 will be good to help us solve this problem.
Currently Redis 3.0 is not stable, if you want to use in the production environment, be cautious.

One, Redis server description

192.168.120.45 7000
192.168.120.45 7001
192.168.120.45 7002

192.168.120.46 7003
192.168.120.46 7004

192.168.120.46 7005


To allow the cluster to operate at least three primary nodes, it is strongly recommended to use six nodes when starting the cluster function: Three are primary, while the remaining three are the slave nodes of each master node. So use two machines, open 6 redis processes, simulate 6 machines.

Second, install Redis 1. Copy the compressed package to the/usr/local/directory 2. Unzip and install Redis [/usr/local/] #tar-xvzf redis-3.0.5.tar.gz [/usr/local/] #cd Redis -3.0.5 [/usr/local/redis-3.0.5] #make [/usr/local/redis-3.0.5] #make install [/usr/local/redis-3.0.5] #cd src [/usr/l ocal/redis-3.0.5] #cp redis-trib.rb/usr/local/bin 3. Create a Redis cluster profile #mkdir/etc/redis #mkdi/var/log/redis (2,3 requires two services Execution) 4. Configure Redis[/usr/local/redis-3.0.5] #vim redis.confWhat's changed: Port7000
pidfile/var/run/redis-7000. pid 
    dbfilename dump-7000 . Rdb  
    Appendfilename "Appendonly-7000 . AoF "  
    Cluster-config-file nodes-< Span style= "color: #ff0000;" >7000 . Conf &NBSP;
     cluster-enabled yes  &NBSP;
     cluster-node-timeout   &NBSP;
    appendonly yes  5.copy config file, and modify Port # CP redis.conf/etc/redis/redis-7000.conf
# CP Redis.conf/etc/redis/redis-7001.conf
# CP Redis.conf/etc/redis/redis-7002.conf

# SCP redis.conf 192.168.120.46:/etc/redis/redis-7003.conf&NBSP;
    # SCP redis.conf 192.168.120.46:/etc/redis/ Redis-7004.conf &NBSP;
    # SCP redis.conf 192.168.120.46:/ Etc/redis/redis-7005.conf &NBSP;
   // Replace all 7000 in the redis-7001.conf file with 7001
    # sed-i "s/7000/7001/g"/etc/redis/redis-7001.conf &NBSP;
    # sed-i "s/7000/7002/g"/etc/redis/redis-7002.conf &NBSP;
 &NBSP;
    # Sed-i "S/7000/7003/g"/etc/redis/redis-7003.conf &NBSP;
    # sed- I "s/7000/7004/g"/etc/redis/redis-7004.conf &NBSP;
    # SED -I "s/7000/7005/g"/ETC/REDIS/REDIS-7005.CONF&NBSP; Third, start Redis and view Redis #./redis-server/etc/redis/redis-7000.conf >/var/log/redis/redis-7000.log 2>&1 &
#./redis-server/etc/redis/redis-7001.conf >/var/log/redis/redis-7001.log 2>&1 &&NBSP;
    #/redis-server/etc/redis/redis-7002.conf >/var/ Log/redis/redis-7002.log 2>&1 & &NBSP;
 &NBSP;
    #./redis-server/etc/redis/redis-7003.conf >/var/log/redis/ Redis-7003.log 2>&1 & &NBSP;
    #./redis-server/ etc/redis/redis-7004.conf >/var/log/redis/redis-7004.log 2>&1 &  &NBSP;
    #/redis-server/etc/redis/redis-7005.conf >/var/ Log/redis/redis-7005.log 2>&1 & &NBSP;
 &NBSP;
    # NETSTAT-TPNL |grep redis  /span> tcp        0      0  192.168.120.45:17000        0.0.0.0:*                    LISTEN       15658/./redis-serve tcp        0       0 192.168.120.45:17001        0.0.0.0:*                     LISTEN      15652/./redis-serve tcp         0      0 192.168.120.45:17002         0.0.0.0:*                    listen      15644/./redis-serve tcp         0      0 192.168.120.45:7000          0.0.0.0:*                    LISTEN      15658/./redis-serve tcp         0      0 192.168.120.45:7001          0.0.0.0:*                    LISTEN       15652/./redis-serve tcp        0       0 192.168.120.45:7002         0.0.0.0:*                    LISTEN       15644/./redis-serve  all nodes are started successfully, it does not mean that they are clustered. Four, create a cluster and view     

1. Create a Redis cluster

#./REDIS-TRIB.RB Create--replicas 1 192.168.120.45:7000 192.168.120.45:7001 192.168.120.45:7002 192.168.120.46:7003 192.168.120.46:7004 192.168.120.46:7005

The meaning of the command is as follows:
The command for a given REDIS-TRIB.RB program is create, which means we want to create a new cluster.
Option--replicas 1 means that we want to create a slave node for each master node in the cluster.
The other parameters followed are the address lists of the instances, and we want the program to use the instance indicated by these addresses to create a new cluster.
Simply put, the above command means that the REDIS-TRIB program creates a cluster that contains three primary nodes and three slave nodes.

2. View Redis cluster status

#redis-trib.rb Check 192.168.120.45:7000

connecting to node 192.168.120.45:7000: okconnecting to node  192.168.120.46:7005: okconnecting to node 192.168.120.46:7004: okconnecting to  node 192.168.120.46:7003: OKConnecting to node 192.168.120.45:7001:  Okconnecting to node 192.168.120.45:7002: ok>>> performing cluster  Check  (using node 192.168.120.45:7000) m: f84ca7b52e70e179e82b56120db72b828a5a60a4  192.168.120.45:7000   slots:5461-6917,6919-10922  (5461 slots)  master    1 additional replica (s) s: 87eb060b519c5ca21cad4229b6bab4fa685c134c  192.168.120.46:7005   slots:  (0 slots)  slave   replicates  f84ca7b52e70e179e82b56120db72b828a5a60a4m: c9f204b2f1b82de04a0cac045164ee1d64ab8b54  192.168.120.46:7004   slots:10923-16383  (5461&nbsP;slots)  master   0 additional replica (s) m:  c18ab6cf7fd53ccbb7a4c38a385df4db8e22531d 192.168.120.46:7003   slots:0-5460  (5461  slots)  master   1 additional replica (s) s:  5e502340bea055417e76985c4cc6355a66263a5b 192.168.120.45:7001   slots:  (0 slots)  slave   replicates c18ab6cf7fd53ccbb7a4c38a385df4db8e22531dM:  13bbd4a90fef751a57247f92d44e3dc4db6b99ab 192.168.120.45:7002   slots:6918  (1  Slots)  master   0 additional replica (s) [ok] all nodes agree  about slots configuration.>>> check for open slots...>>>  Check slots coverage ... [ok] all 16384 slots covered.  here, the Redis cluster has been configured successfully by five, testing the Redis cluster #./REDIS-CLI-C-P7001-h 192.168.120.45//login at 45
192.168.120.45:7001> Set Tank TANK1//Set test value
-Redirected to Slots [4407] located at192.168.120.45:7000
OK//Direct turn to 45 7000 port, data stored to 45 7000, but a little strange
192.168.120.45:7001> get tank//can fetch a value&NBSP;
"Tank1"  &NBSP;
 &NBSP;
[[email protected] redis]# redis-cli-c-P 7005-h 192.168.120.46 &NBSP;//46 Machine, 7005-Port  &NBSP;
192.168.120.46:7005> Get Tank &NBSP;
, redirected to Slots [4407] located at 192.168.120.46:7004//Direct Steering 46 7004 ports  &NBSP;
"Tank1"  &NBSP;
 &NBSP;
[[email protected] Redis]# ps aux |grep Redis// View process  &NBSP;
root      2838  0.0  0.0 105048  3344  Pts/2    t    14:18   0:00 vim redis.confroot       2870  0.0  0.0 105048  3312 pts/2     t    14:25   0:00 vim /etc/redis/ redis-7004.confroot      2977  0.0  0.0  95388   2644 ?        Ssl  14:58    0:01 ./redis-server 192.168.120.46:7003 [cluster]root      2983   0.0  0.0  95388  2572 ?         ssl  14:58   0:01 ./redis-server 192.168.120.46:7004 [ cluster]root      2987  0.0  0.0  95388  2628 ?         Ssl  14:58   0:01 ./redis-server  192.168.120.46:7005 [cluster]root      3289  0.0  0.0   63412   780 pts/2    R+   16:48    0:00 grep redis  &NBSP
[[email protected] redis]# kill-9 2983//Close 46 7004 ports to see if the data will be lost   &NBSP;
 &NBSP;
[email  protected] redis]# redis-trib.rb check 192.168.120.45:7000 //view cluster condition, any interface will be  
connecting to node 192.168.120.45:7000: okconnecting to node  192.168.120.46:7005: okconnecting to node 192.168.120.46:7003: okconnecting to  node 192.168.120.45:7001: OKConnecting to node 192.168.120.45:7002: OK> >> Performing Cluster Check  (using node 192.168.120.45:7000) m:  f84ca7b52e70e179e82b56120db72b828a5a60a4 192.168.120.45:7000   slots:5461-6917,6919-10922   (5461 slots)  master   1 additional replica (s) S:  87eb060b519c5ca21cad4229b6bab4fa685c134c 192.168.120.46:7005   slots:  (0 slots)  slave   replicates f84ca7b52e70e179e82b56120db72b828a5a60a4M:  c18ab6cf7fd53ccbb7a4c38a385df4db8e22531d 192.168.120.46:7003   slots:0-5460  (5461  slots)  master   1 additional replicA (s) s: 5e502340bea055417e76985c4cc6355a66263a5b 192.168.120.45:7001   slots:  (0  slots)  slave   replicates c18ab6cf7fd53ccbb7a4c38a385df4db8e22531dM:  13bbd4a90fef751a57247f92d44e3dc4db6b99ab 192.168.120.45:7002   slots:6918  (1  Slots)  master   0 additional replica (s) [ok] all nodes agree  about slots configuration.>>> check for open slots...>>>  Check slots coverage ...[OK] All 16384 slots covered.//became, three master two from the

[[email protected]src]#./redis-cli-c-P 7002-h 192.168.120.45//45 login 192.168.120.45:7002> get tank-> redirected to slot [4407] Loc Ated at 192.168.120.46:7003//data was transferred to the 7003 node."Tank1"
After testing, the cluster is available.

Redis cluster installation

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.