Redis4.0.10 Cluster Construction

Source: Internet
Author: User
Tags install redis redis server

192.168.254.128
192.168.254.129
192.168.254.127
Precautions
Install the GCC compiler tool or there will be a compilation problem
Yum install-y gcc g++ gcc-c++ make
Upgrade all packages to prevent the release from being too long for incompatibility issues
Yum-y Update

Environment preparation
Install ruby;

You need to open the specified port before shutting down the firewall node, production is not disabled for convenience
CentOS 6.x
Service iptables Stop # Shutdown command:
CentOS 7.x
Systemctl Stop Firewalld.service # Stop Firewall

Cluster construction
First set up Redis and configuration on each server separately
Installing Redis
Download, unzip, compile and install
Cd/opt
wget http://download.redis.io/releases/redis-4.0.10.tar.gz
Tar xzf redis-4.0.10.tar.gz
CD redis-4.0.10
Make
If there is a residual file because the last compilation failed
Make Distclean

Create a Node
Create a cluster directory on each server, respectively
cd/usr/local/
mkdir Redis-cluster

In each Redis-cluster directory
CD redis-cluster/
Create on each server separately
192.168.254.128
mkdir 6000 6001 6002

192.168.254.129
mkdir 6003 6004 6005

192.168.254.127
mkdir 6006 6007 6008
Modify the three configuration files on each server separately, paste the following redis.conf configuration contents into
192.168.254.128
VI 6000/redis.conf
VI 6001/redis.conf
VI 6002/redis.conf

192.168.254.129
VI 6003/redis.conf
VI 6004/redis.conf
VI 6005/redis.conf

192.168.254.127
VI 6006/redis.conf
VI 6007/redis.conf
VI 6008/redis.conf

Configure the appropriate configuration on each server, respectively
redis.conf Configuration Instructions
#端口 6000 6001 6002
Port 6000
#默认ip为127.0.0.1, you need to change to another node machine-accessible IP, otherwise the corresponding port cannot be accessed when the cluster is created and the cluster cannot be created
Bind 192.168.254.128
#redis后台运行
Daemonize Yes
#pidfile文件对应6000, 6001,6002
Pidfile/var/run/redis_6000.pid
#开启集群, remove the note #
cluster-enabled Yes
#集群的配置, the profile is first started automatically generated 6000,6001,6002
Cluster-config-file nodes_6000.conf
#请求超时, default 15 seconds, can be set by itself
Cluster-node-timeout 10100
#aof日志开启, open it if necessary, it logs a log for each write operation
AppendOnly Yes

Then on the other two machines (192.168.254.129;192.168.254.127) Repeat the above three steps, just to change the directory to 6003, 6004, 6005;6006, 6007, 008 the corresponding configuration file will be modified according to this rule

#第一台机器上执行 of 3 nodes
For ((i=0;i<=2;i++)); do/opt/redis-4.0.10/src/redis-server/usr/local/redis-cluster/600$i/redis.conf; Done
Execute 3 nodes on the second machine
For ((i=3;i<=5;i++)); do/opt/redis-4.0.10/src/redis-server/usr/local/redis-cluster/600$i/redis.conf; Done
Perform 3 nodes on the third machine
For ((i=6;i<=8;i++)); do/opt/redis-4.0.10/src/redis-server/usr/local/redis-cluster/600$i/redis.conf; Done

Check Service
Check the boot status of each Redis node
Ps-ef | Whether grep Redis//redis started successfully
NETSTAT-TNLP | grep redis//monitor Redis port

Install Ruby
Installing Ruby on a newly installed Redis server
Because you need to run REDIS-TRIB.RB with Ruby when creating a cluster
Yum-y install ruby Ruby-devel rubygems rpm-build

Gem install Redis This automatic installation is not
You can only download it and install it manually.
wget Http://rubygems.global.ssl.fastly.net/gems/redis-4.0.1.gem
Gem Install-l./redis-4.0.1.gem

/OPT/REDIS-4.0.10/SRC/REDIS-TRIB.RB Create--replicas 1 192.168.254.128:6000 192.168.254.128:6001 192.168.254.128:6002 192.168.254.129:6003 192.168.254.129:6004 192.168.254.129:6005 192.168.254.127:6006 192.168.254.127:6007 192.168.254.127:6008

>> Creating Cluster
>> performing hash slots allocation on 9 nodes ...
Using 4 Masters:
192.168.254.128:6000
192.168.254.129:6003
192.168.254.127:6006
192.168.254.128:6001
Adding replica 192.168.254.127:6007 to 192.168.254.128:6000
Adding replica 192.168.254.128:6002 to 192.168.254.129:6003
Adding replica 192.168.254.129:6005 to 192.168.254.127:6006
Adding replica 192.168.254.127:6008 to 192.168.254.128:6001
Adding replica 192.168.254.129:6004 to 192.168.254.128:6000
M:A4652CA08FD832DEF811F585AC14A3367364B6BC 192.168.254.128:6000
slots:0-4095 (4096 slots) Master
M:6275ac1e805e1d54281b66a7d49d64d2b0e802da 192.168.254.128:6001
slots:12288-16383 (4096 slots) Master
s:84a752afcb6fda24df7a2fa220d38170daac5976 192.168.254.128:6002
Replicates d9228859beb0180ab6ff198a1819088d401f936a
m:d9228859beb0180ab6ff198a1819088d401f936a 192.168.254.129:6003
slots:4096-8191 (4096 slots) Master
S:4fc65bf3c4747d767fa56b357891d4062b310f52 192.168.254.129:6004
Replicates A4652CA08FD832DEF811F585AC14A3367364B6BC
S:EA51FA38217674F51A968B341732D77EABE7561D 192.168.254.129:6005
Replicates B14eddc61b984089360713932cd16bd114f3aff4
M:b14eddc61b984089360713932cd16bd114f3aff4 192.168.254.127:6006
slots:8192-12287 (4096 slots) Master
S:84645AC8B50A4F199B413A290835F363C2C17CD8 192.168.254.127:6007
Replicates A4652CA08FD832DEF811F585AC14A3367364B6BC
S:172be3915c71f16302fa3ce8219af024f950f0e5 192.168.254.127:6008
Replicates 6275ac1e805e1d54281b66a7d49d64d2b0e802da
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.254.128:6000)
M:A4652CA08FD832DEF811F585AC14A3367364B6BC 192.168.254.128:6000
slots:0-4095 (4096 slots) Master
2 additional replica (s)
S:EA51FA38217674F51A968B341732D77EABE7561D 192.168.254.129:6005
Slots: (0 slots) Slave
Replicates B14eddc61b984089360713932cd16bd114f3aff4
S:172be3915c71f16302fa3ce8219af024f950f0e5 192.168.254.127:6008
Slots: (0 slots) Slave
Replicates 6275ac1e805e1d54281b66a7d49d64d2b0e802da
S:84645AC8B50A4F199B413A290835F363C2C17CD8 192.168.254.127:6007
Slots: (0 slots) Slave
Replicates A4652CA08FD832DEF811F585AC14A3367364B6BC
S:4fc65bf3c4747d767fa56b357891d4062b310f52 192.168.254.129:6004
Slots: (0 slots) Slave
Replicates A4652CA08FD832DEF811F585AC14A3367364B6BC
m:d9228859beb0180ab6ff198a1819088d401f936a 192.168.254.129:6003
slots:4096-8191 (4096 slots) Master
1 additional replica (s)
M:6275ac1e805e1d54281b66a7d49d64d2b0e802da 192.168.254.128:6001
slots:12288-16383 (4096 slots) Master
1 additional replica (s)
s:84a752afcb6fda24df7a2fa220d38170daac5976 192.168.254.128:6002
Slots: (0 slots) Slave
Replicates d9228859beb0180ab6ff198a1819088d401f936a
M:b14eddc61b984089360713932cd16bd114f3aff4 192.168.254.127:6006
slots:8192-12287 (4096 slots) Master
1 additional replica (s)
[OK] All nodes agree about slots configuration.
>> Check for open Slots ...
>> Check Slots Coverage ...
[OK] All 16384 slots covered.
[Email protected] ~]# Ps-ef|grep Redis
Root 17107 1 0 15:49? 00:00:24/opt/redis-4.0.10/src/redis-server 192.168.254.128:6000 [cluster]
Root 17112 1 0 15:49? 00:00:24/opt/redis-4.0.10/src/redis-server 192.168.254.128:6001 [cluster]
Root 17114 1 0 15:49? 00:00:24/opt/redis-4.0.10/src/redis-server 192.168.254.128:6002 [cluster]
Root 36435 16949 0 20:21 pts/0 00:00:00 grep--color=auto Redis

Shutting down the cluster
This is also possible, recommended
$ pkill Redis
Loop node closes one by one
For ((i=0;i<=2;i++)); Do/opt/redis-4.0.10/src/redis-cli-c-H 192.168.254.128-p 600$i shutdown; Done
For ((i=3;i<=5;i++)); Do/opt/redis-4.0.10/src/redis-cli-c-H 192.168.254.129-p 600$i shutdown; Done
For ((i=6;i<=8;i++)); Do/opt/redis-4.0.10/src/redis-cli-c-H 192.168.254.127-p 600$i shutdown; Done

Cluster validation
Connecting cluster tests
Parameter-C can be connected to the cluster because the redis.conf changes bind to an IP address, so the-H parameter cannot be omitted, and the-p parameter is the port number

View cluster status
Cluster nodes

Redis4.0.10 Cluster Construction

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.