Building of redis 3.2.8 cluster environment

Keywords: Redis Ruby yum iptables

Environmental preparation

  1. centos6.7
  2. redis3.2.8

Installation steps

  • Step 1: Download the redis 3.2.8 installation package https://redis.io/download

  • Step 2: Decompress the compressed package to the middle/inner_dev_env/redis-3.2.8

[root@allere /inner_dev_env/redis-3.2.8]# pwd
/inner_dev_env/redis-3.2.8
  • Step 3: Create a new directory: redis-3.2.8-cluster (name is arbitrary, location is arbitrary). Then create a new cluster run directory under this directory (with any name)
mkdir redis-3.2.8-cluster
cd redis-3.2.8-cluster
mkdir 7000 7001 7002 7003 7004 7005
[root@allere /inner_dev_env/redis-3.2.8-cluster]# pwd
/inner_dev_env/redis-3.2.8-cluster
[root@allere /inner_dev_env/redis-3.2.8-cluster]# ls
7000  7001  7002  7003  7004  7005 
  • Step 4: Modify redis configuration file redis.conf
[root@allere /inner_dev_env/redis-3.2.8-cluster]# vi /inner_dev_env/redis-3.2.8/redis.conf

To get a cluster to run, you need only the following five parameters
port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes

Because the default redis.conf file has started the following three parameters
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
So you only need to modify the port to the corresponding startup port and start cluser-enable.

  82 # Accept connections on the specified port, default is 6379 (IANA #815344).
  83 # If port 0 is specified Redis will not listen on a TCP socket.
  84 port 7000
  717 # Normal Redis instances can't be part of a Redis Cluster; only nodes that are
  718 # started as cluster nodes can. In order to start a Redis instance as a
  719 # cluster node enable the cluster support uncommenting the following:
  720 #
  721 cluster-enabled yes
  • Step 5: Copy redis.conf file to the corresponding port folder, and modify the port parameter to the corresponding port number
[root@allere /inner_dev_env/redis-3.2.8]# cp ./redis.conf /inner_dev_env/redis-3.2.8-cluster/7000

[root@allere /inner_dev_env/redis-3.2.8]# cp ./redis.conf /inner_dev_env/redis-3.2.8-cluster/7001

[root@allere /inner_dev_env/redis-3.2.8]# cp ./redis.conf /inner_dev_env/redis-3.2.8-cluster/7002

[root@allere /inner_dev_env/redis-3.2.8]# cp ./redis.conf /inner_dev_env/redis-3.2.8-cluster/7003

[root@allere /inner_dev_env/redis-3.2.8]# cp ./redis.conf /inner_dev_env/redis-3.2.8-cluster/7004

[root@allere /inner_dev_env/redis-3.2.8]# cp ./redis.conf /inner_dev_env/redis-3.2.8-cluster/7005
  • Step 6: Copy the executable redis-server to the redis-3.2.8-cluster folder to execute each redis instance.
[root@allere /inner_dev_env/redis-3.2.8]# cp ./src/redis-server /inner_dev_env/redis-3.2.8-cluster/
  • Step 7: Switch to the corresponding file and start each redis instance
[root@allere /inner_dev_env/redis-3.2.8-cluster]# cd 7000
[root@allere /inner_dev_env/redis-3.2.8-cluster/7000]# ../redis-server ./redis.conf 
[root@allere /inner_dev_env/redis-3.2.8-cluster]# cd 7001
[root@allere /inner_dev_env/redis-3.2.8-cluster/7000]# ../redis-server ./redis.con
[root@allere /inner_dev_env/redis-3.2.8-cluster]# cd 7002
[root@allere /inner_dev_env/redis-3.2.8-cluster/7000]# ../redis-server ./redis.con
[root@allere /inner_dev_env/redis-3.2.8-cluster]# cd 7003
[root@allere /inner_dev_env/redis-3.2.8-cluster/7000]# ../redis-server ./redis.con
[root@allere /inner_dev_env/redis-3.2.8-cluster]# cd 7004
[root@allere /inner_dev_env/redis-3.2.8-cluster/7000]# ../redis-server ./redis.con
[root@allere /inner_dev_env/redis-3.2.8-cluster]# cd 7005
[root@allere /inner_dev_env/redis-3.2.8-cluster/7000]# ../redis-server ./redis.con
  • Step 8: Create clusters.
    All redis instances that will run are clustered through the redis-trib.rb tool under the src/package. But redis-trib.rb requires a ruby environment, so first install the ruby environment (installing the ruby environment may cause errors, the appendix of this article gives the solution), and then execute the redis-trib command to create the cluster.
[root@allere /inner_dev_env/redis-3.2.8/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

8.1 Error will be reported when executing the above command, because it is a ruby script that needs ruby environment.
Error content: / usr/bin/env: ruby: No such file or directory
So you need to install the ruby environment, and yum install ruby installation is recommended here.
yum install ruby

8.2 and then execute the Create Cluster command in Step 8, which also reports errors, prompts the lack of rubygems components, and installs them using yum

Error content:
./redis-trib.rb:24:in require': no such file to load -- rubygems (LoadError)
from ./redis-trib.rb:24
yum install rubygems
8.3 Executing the command of Step 8 again will also cause an error, indicating that redis cannot be loaded because of the lack of interfaces between redis and ruby, and installing using gem
Error content:
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:ingem_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
Note: If gem install redis fails, you need to modify the source of gem
gem sources –remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/

8.4 When the eighth step is executed, the pop-up prompt for yes can be input and the installation can be completed.

test

  • Step 1: Connect to the cluster. Note that the - c parameter needs to be added
[root@allere /inner_dev_env/redis-3.2.8]# src/redis-cli -p 7000 -c
127.0.0.1:7000> 
  • Step 2: Do some simple operations, check the status of the cluster, etc.
127.0.0.1:7000> set key1 value1
-> Redirected to slot [9189] located at 192.168.0.102:7001
OK
192.168.0.102:7001> get key1
"value1"
192.168.0.102:7001> cluster nodes
99e6b250fd5c3622b6753cd8a3c5ef6ab946a5ec 192.168.0.102:7002 master - 0 1494483809589 3 connected 10923-16383
d13a6d014297d7164347f6ff07ceb50bce0fabdc 192.168.0.102:7004 slave 8ea553e0f9f502c01fc9565128085756ed2988e7 0 1494483811190 5 connected
1e51d8a6704e3c07276ba33c28d379f94b5544b7 192.168.0.102:7005 slave 99e6b250fd5c3622b6753cd8a3c5ef6ab946a5ec 0 1494483810088 6 connected
42b2c7f7afc2850199dee632bc02dc19e3d6c268 192.168.0.102:7003 slave a65d71bce6ea49032410378eb527973bc2249398 0 1494483810588 4 connected
a65d71bce6ea49032410378eb527973bc2249398 192.168.0.102:7000 master - 0 1494483809088 1 connected 0-5460
8ea553e0f9f502c01fc9565128085756ed2988e7 192.168.0.102:7001 myself,master - 0 0 2 connected 5461-10922
192.168.0.102:7001> 
  • Step 3: The cluster of the six nodes is built on a separate host (the host ip in this example is 192.168.0.102). If you access the cluster from another host (the ip of my local computer is 192.168.0.36), additional configuration is required for operation. Log in to each redis instance and do something like this
[root@allere /inner_dev_env/redis-3.2.8]# src/redis-cli -p 7000 -c
127.0.0.1:7000> cluster meet 192.168.0.102 7001
OK
127.0.0.1:7000> cluster meet 192.168.0.102 7002
OK
127.0.0.1:7000> cluster meet 192.168.0.102 7003
OK
127.0.0.1:7000> cluster meet 192.168.0.102 7004
OK
127.0.0.1:7000> cluster meet 192.168.0.102 7005
OK
127.0.0.1:7000> 

summary

Setup of linux open service port

/etc/sysconfig/iptables

vi iptables

Add the following

 -A INPUT -p tcp -m tcp --dport 6001 -j ACCEPT 
Then save the exit and restart the service
/etc/init.d/iptables restarts

2 Error reporting for installing ruby environment: executing gem install redis was unsuccessful

8.1 Error will be reported when executing the above command, because it is a ruby script that needs ruby environment.
Error content: / usr/bin/env: ruby: No such file or directory
 So you need to install the ruby environment, and yum install ruby installation is recommended here.
yum install ruby

8.2 and then execute the Create Cluster command in Step 8, which also reports errors, prompts the lack of rubygems components, and installs them using yum

Error content:
./redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError)
from ./redis-trib.rb:24
yum install rubygems
 8.3 Executing the command of Step 8 again will also cause an error, indicating that redis cannot be loaded because of the lack of interfaces between redis and ruby, and installing using gem
 Error content:
/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 
Note: If gem install redis fails, you need to modify the source of gem
gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/

3 Remotely connected to redis but not available:
The program has been stuck in the following places

E:\software\Redis>redis-cli.exe -c -h 192.168.0.102 -p
192.168.0.102:7000> get name
-> Redirected to slot [5798] located at 127.0.0.1:7001

Solution

[root@allere /inner_dev_env/redis-3.2.8]# src/redis-cli -p 7000 -c
127.0.0.1:7000> cluster meet 192.168.0.102 7001
OK

appendix

Serial number Name Connect
1 linux looks at which ports are open and how to open them http://www.cnblogs.com/paddygege/p/6361042.html
2 Detailed steps for the installation of redis 3.0.0 cluster http://blog.csdn.net/xu470438000/article/details/42971091
3 redis-cli redirected to 127.0.0.1 http://stackoverflow.com/questions/37341646/redis-cli-redirected-to-127-0-0-1

Posted by WesPear on Mon, 01 Jul 2019 11:56:25 -0700