Installation and deployment of Redis under Linux CentOS + Construction of Redis pseudo cluster

redis Download: http://download.redis.io/releases/redis-4.0.10.tar.gz

  • Decompress, compile and install
//Extract to local directory
# tar -xvf redis-4.0.10.tar.gz -C /usr/local/

//Navigate to the unzip directory
# cd /usr/local/redis-4.0.10/

//Perform compilation and installation, PREFIX must be uppercase
# make install PREFIX=/usr/local/redis
  • /The following files will be generated in the usr/local/redis/bin directory. Then you can start redis server
# cd /usr/local/redis/bin
//Execute command in bin directory
# ./redis-server
23154:C 24 Aug 05:23:47.865 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
23154:C 24 Aug 05:23:47.865 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=23154, just started
23154:C 24 Aug 05:23:47.865 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
23154:M 24 Aug 05:23:47.867 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.10 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 23154
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

23154:M 24 Aug 05:23:47.871 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
23154:M 24 Aug 05:23:47.871 # Server initialized
23154:M 24 Aug 05:23:47.872 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
23154:M 24 Aug 05:23:47.874 * Ready to accept connections

  • At this time, the default configuration is used for startup
  • bind 127.0.0.1
  • port 6379
  • daemonize no

  • Open another remote client for client connection

# cd /usr/local/redis-4.0.10/bin/
# cd ./redis-cli
127.0.0.1:6379> shutdown

//Execute shutdown to shut down the redis service
not connected>
  • The server can exit through CTRL+C or execute shutdown on the client
  • Set service background start mode
//Copy a configuration file to the redis directory
# cp /usr/local/redis-4.0.10/redis.conf /usr/local/reids

//vi command to modify daemonize to yes
daemonized yes
//After entering the vi command, you can quickly locate through / daemonize

//Start redis service with configuration file in bin directory
# ./redis-server ../redsi.conf
23345:C 24 Aug 05:52:05.153 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
23345:C 24 Aug 05:52:05.153 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=23345, just started
23345:C 24 Aug 05:52:05.153 # Configuration loaded
#
  • Remote connection to redis service through Redis Desktop Manager 0.9.5

  • First, make sure your Linux system is open to port 6379

  • Modify the configuration file, open the comment of requirepass or add a line directly
requirepass The verification code you want
//Add bind server address
 bind 120.0.0.1
 bind 192.168.25.120(Here's your server's ip address)

//Start service, test remote connection
# ./redis-server ../redsi.conf

//Because validation is added to the configuration file, it is also required to shut down the service
# . / redis cli - a verification code shutdown

Redis pseudo cluster construction

1. deploy Ruby with Ruby Version Manager (RVM)

//On line installation of RVM
# \curl -sSL https://get.rvm.io | bash -s stable
//Deploy Ruby online, list all versions
# rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.7]
[ruby-]2.4[.4]
[ruby-]2.5[.1]
[ruby-]2.6[.0-preview2]
ruby-head

# for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2

# JRuby
jruby-1.6[.8]
jruby-1.7[.27]
jruby-9.1[.17.0]
jruby[-9.2.0.0]
jruby-head

# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx-2[.5.8]
rbx-3[.100]
rbx-head

# TruffleRuby
truffleruby[-1.0.0-rc2]

# Opal
opal

# Minimalistic ruby implementation - ISO 30170:2012
mruby-1.0.0
mruby-1.1.0
mruby-1.2.0
mruby-1.3.0
mruby-1[.4.0]
mruby[-head]

# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]

# Topaz
topaz

# MagLev
maglev-1.0.0
maglev-1.1[RC1]
maglev[-1.2Alpha4]
maglev-head

# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head

# IronRuby
ironruby[-1.1.3]
ironruby-head
//Install the selected version
# rvm install ruby-2.5
//Validation version
# ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

2. Install RubyGems
Installation package download: https://rubygems.org/rubygems/rubygems-2.7.7.tgz

//After decompressing rubygems.tgz, execute in the decompressed directory
# ruby setup.rb

//Validation version
# gem -v
2.7.7

3. Install redis.gem Online

//The latest version of redis.gem will be installed
# gem install redis

4. Configure multiple redis servers

//New redis cluster folder
# mkdir /usr/local/redis-cluster

//Delete the RDB snapshot file and AOF file generated in bin directory
# rm -rf /usr/local/redis/bin/dump.rdb appendonly.aof

/*
  Modify the redis.conf configuration file
1.Comment out bind 127.0.0.1
2.Comment out the requirepass verification code
3.Comments on opening cluster enabled yes
4.Change the protected mode to no
*/

# bind 127.0.0.1
# requirepass verification code
cluster-enabled yes
protected-mode no

//Copy 6 copies of the redis directory to the redis cluster * cluster. At least 3 redis services are needed, and one backup is needed for each reids. Therefore, 6 copies are needed*
# cp /usr/local/redis /usr/local/redis-cluster/redis01 -r
# cp /usr/local/redis /usr/local/redis-cluster/redis02 -r
# cp /usr/local/redis /usr/local/redis-cluster/redis03 -r
# cp /usr/local/redis /usr/local/redis-cluster/redis04 -r
# cp /usr/local/redis /usr/local/redis-cluster/redis05 -r
# cp /usr/local/redis /usr/local/redis-cluster/redis06 -

//Modify the configuration file redis.conf in the redis01-06 directory, and change the port number port
redis01/reids.conf  port 7001
redis02/reids.conf  port 7002
redis03/reids.conf  port 7003
redis04/reids.conf  port 7004
redis05/reids.conf  port 7005
redis01/reids.conf  port 7006

//Copy the redis-trib.rb under the redis decompression directory src to the redis cluster directory
# cp /usr/local/redis-4.0.10/src/redis-trib.rb /usr/local/redis-cluster

//New batch execution file
# mkdir /usr/local/redis-cluster/redis_start_all.sh

//Modify batch execution
# vi /usr/local/redis-cluster/redis_start_all.sh
d /usr/local/redis-cluster/redis01/bin
./redis-server ../redis.conf

cd /usr/local/redis-cluster/redis02/bin
./redis-server ../redis.conf

cd /usr/local/redis-cluster/redis03/bin
./redis-server ../redis.conf

cd /usr/local/redis-cluster/redis04/bin
./redis-server ../redis.conf

cd /usr/local/redis-cluster/redis05/bin
./redis-server ../redis.conf

cd /usr/local/redis-cluster/redis06/bin
./redis-server ../redis.conf

//Modify the executable permission of redis start all.sh
# chmod u+x /usr/local/redis-cluster/redis_start_all.sh

//Start multiple redis services and execute them in the redis cluster directory
# ./redis_start_all.sh
23928:C 24 Aug 07:09:37.156 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
23928:C 24 Aug 07:09:37.156 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=23928, just started
23928:C 24 Aug 07:09:37.156 # Configuration loaded
23930:C 24 Aug 07:09:37.173 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
23930:C 24 Aug 07:09:37.174 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=23930, just started
23930:C 24 Aug 07:09:37.174 # Configuration loaded
23932:C 24 Aug 07:09:37.188 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
23932:C 24 Aug 07:09:37.188 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=23932, just started
23932:C 24 Aug 07:09:37.188 # Configuration loaded
23934:C 24 Aug 07:09:37.203 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
23934:C 24 Aug 07:09:37.203 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=23934, just started
23934:C 24 Aug 07:09:37.203 # Configuration loaded
23936:C 24 Aug 07:09:37.217 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
23936:C 24 Aug 07:09:37.217 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=23936, just started
23936:C 24 Aug 07:09:37.217 # Configuration loaded
23938:C 24 Aug 07:09:37.230 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
23938:C 24 Aug 07:09:37.231 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=23938, just started
23938:C 24 Aug 07:09:37.231 # Configuration loaded

5. Use ruby script to build cluster

//Execute in the redis cluster directory

# ./redis-trib.rb create --replicas 1 192.168.25.120:7001 192.168.25.120:7002 192.168.25.120:7003 192.168.25.120:7004 192.168.25.120:7005 192.168.25.120:7006

>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.25.120:7001
192.168.25.120:7002
192.168.25.120:7003
Adding replica 192.168.25.120:7005 to 192.168.25.120:7001
Adding replica 192.168.25.120:7006 to 192.168.25.120:7002
Adding replica 192.168.25.120:7004 to 192.168.25.120:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 46a3cc0665de4b8cedd32559bb5b0846972f5ab6 192.168.25.120:7001
   slots:0-5460 (5461 slots) master
M: d10e7c79b3083f5726167e164f73469b84574609 192.168.25.120:7002
   slots:5461-10922 (5462 slots) master
M: 700db85f5944275988477093c84099ddccc6ffb3 192.168.25.120:7003
   slots:10923-16383 (5461 slots) master
S: fc11396097f8337ad17bde9496a1869932e8cbda 192.168.25.120:7004
   replicates 700db85f5944275988477093c84099ddccc6ffb3
S: 57c5e3cf86738ed017668389e659edf7ba5f4fe4 192.168.25.120:7005
   replicates 46a3cc0665de4b8cedd32559bb5b0846972f5ab6
S: c56a9bb7135073740229af070ab96ad500817c7d 192.168.25.120:7006
   replicates d10e7c79b3083f5726167e164f73469b84574609
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.25.120:7001)
M: 46a3cc0665de4b8cedd32559bb5b0846972f5ab6 192.168.25.120:7001
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: c56a9bb7135073740229af070ab96ad500817c7d 192.168.25.120:7006
   slots: (0 slots) slave
   replicates d10e7c79b3083f5726167e164f73469b84574609
M: 700db85f5944275988477093c84099ddccc6ffb3 192.168.25.120:7003
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
M: d10e7c79b3083f5726167e164f73469b84574609 192.168.25.120:7002
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 57c5e3cf86738ed017668389e659edf7ba5f4fe4 192.168.25.120:7005
   slots: (0 slots) slave
   replicates 46a3cc0665de4b8cedd32559bb5b0846972f5ab6
S: fc11396097f8337ad17bde9496a1869932e8cbda 192.168.25.120:7004
   slots: (0 slots) slave
   replicates 700db85f5944275988477093c84099ddccc6ffb3
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

Be accomplished

Possible errors
[ERR] Sorry, can't connect to node 192.168.X.X
Check the redis.conf configuration file
Whether bind is your server address
Whether the protected mode is no
Is requirepass commented out

Keywords: Redis Ruby Linux github

Added by Smackie on Fri, 03 Jan 2020 16:06:31 +0200