Details of the process of installing redis 3.0.6 and configuring the cluster under CentOS 7

  • 2020-05-14 05:22:21
  • OfStack

Install dependencies


[root@centos7-1 ~]# yum -y install gcc openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel gcc-c++ automake autoconf

Install redis


[root@centos7-1 ~]# wget http://download.redis.io/releases/redis-3.0.6.tar.gz
[root@centos7-1 ~]# tar xvf redis-3.0.6.tar.gz
[root@centos7-1 ~]# cd redis-3.0.6/
[root@centos7-1 redis-3.0.6]# make MALLOC=libc
[root@centos7-1 redis-3.0.6]# make install

Start the server

Through the command redis-server To start the redis server . As you can see from the output below, this startup does not specify a configuration file, so you can use the command redis-server /path/to/redis.conf To specify the specific configuration file to launch.


[root@centos7-1 redis-3.0.6]# redis-server 
4435:C 25 Jan 11:40:48.816 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
4435:M 25 Jan 11:40:48.817 * Increased maximum number of open files to 10032 (it was originally set to 1024).
    _._             
   _.-``__ ''-._            
  _.-`` `. `_. ''-._   Redis 3.0.6 (00000000/0) 64 bit
 .-`` .-```. ```\/ _.,_ ''-._         
 ( '  ,  .-` | `, )  Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|  Port: 6379
 | `-._ `._ /  _.-' |  PID: 4435
 `-._ `-._ `-./ _.-' _.-'         
 |`-._`-._ `-.__.-' _.-'_.-'|         
 | `-._`-._  _.-'_.-' |   http://redis.io  
 `-._ `-._`-.__.-'_.-' _.-'         
 |`-._`-._ `-.__.-' _.-'_.-'|         
 | `-._`-._  _.-'_.-' |         
 `-._ `-._`-.__.-'_.-' _.-'         
  `-._ `-.__.-' _.-'          
   `-._  _.-'           
    `-.__.-'            
4435:M 25 Jan 11:40:48.817 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
4435:M 25 Jan 11:40:48.817 # Server started, Redis version 3.0.6
4435:M 25 Jan 11:40:48.817 # 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.
4435:M 25 Jan 11:40:48.817 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
4435:M 25 Jan 11:40:48.817 * DB loaded from disk: 0.000 seconds
4435:M 25 Jan 11:40:48.817 * The server is now ready to accept connections on port 6379

Here we go, single node Redis server Now that the installation is complete, enter the process of configuring and installing the cluster.

Create six nodes in the cluster

Cluster profile

The main changes to the cluster-related configuration files redis.conf Because they are all deployed on one server, each node has a different port.


[root@centos7-1 redis-3.0.6]$ vi redis.conf 
# Modify the following 
port 7000
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 5000
appendonly yes

The configuration file for each node

Create six folders, each representing an redis node, named with the port number of the redis node, and store the configuration files for each node in the file.


[root@centos7-1 redis-3.0.6]# mkdir /usr/local/redis-cluster
[root@centos7-1 redis-3.0.6]# cd /usr/local/redis-cluster
[root@centos7-1 redis-cluster]# mkdir 7000 7001 7002 7003 7004 7005

copy redis.conf Copy to 6 folders


[root@centos7-1 redis-cluster]# cp ~/redis-3.0.6/redis.conf 7000
[root@centos7-1 redis-cluster]# cp ~/redis-3.0.6/redis.conf 7001
[root@centos7-1 redis-cluster]# cp ~/redis-3.0.6/redis.conf 7002
[root@centos7-1 redis-cluster]# cp ~/redis-3.0.6/redis.conf 7003
[root@centos7-1 redis-cluster]# cp ~/redis-3.0.6/redis.conf 7004
[root@centos7-1 redis-cluster]# cp ~/redis-3.0.6/redis.conf 7005

And change the content in each configuration to the port of the respective node, note port and cluster-config-file The value must be 1 only.

Start each node separately


[root@centos7-1 ~]# redis-server /usr/local/redis-cluster/7000/redis.conf
[root@centos7-1 ~]# redis-server /usr/local/redis-cluster/7001/redis.conf
[root@centos7-1 ~]# redis-server /usr/local/redis-cluster/7002/redis.conf
[root@centos7-1 ~]# redis-server /usr/local/redis-cluster/7003/redis.conf
[root@centos7-1 ~]# redis-server /usr/local/redis-cluster/7004/redis.conf
[root@centos7-1 ~]# redis-server /usr/local/redis-cluster/7005/redis.conf

Start and view the process when it is complete


[root@centos7-1 ~]# ps -ef | grep redis
root  4704 2177 0 12:12 pts/0 00:00:07 redis-server *:7000 [cluster]
root  4707 4599 0 12:12 pts/1 00:00:07 redis-server *:7001 [cluster]
root  4710 4638 0 12:12 pts/2 00:00:07 redis-server *:7002 [cluster]
root  4752 4717 0 12:12 pts/3 00:00:07 redis-server *:7003 [cluster]
root  4788 4759 0 12:12 pts/4 00:00:07 redis-server *:7004 [cluster]
root  4824 4795 0 12:13 pts/5 00:00:07 redis-server *:7005 [cluster]
root  9018 8984 0 14:08 pts/6 00:00:00 grep --color=auto redis

Set up the Redis cluster

Each of the six nodes created in the previous step has been started and will be added to one cluster. redis has provided us with scripts for cluster operations redis-trib.rb It's easy to operate. Go ahead.

Install ruby

The ruby script is used for cluster operations redis-trib.rb , so install ruby and rubygems


[root@centos7-1 ~]# yum -y install ruby rubygems
[root@centos7-1 ~]# gem install redis --version 3.0.6
Fetching: redis-3.0.6.gem (100%)
Successfully installed redis-3.0.6
Parsing documentation for redis-3.0.6
Installing ri documentation for redis-3.0.6
1 gem installed

redis-trib.rb Is an ruby scripting tool used to set up and manage redis clusters redis-trib.rb to /usr/local/bin/


[root@centos7-1 redis-3.0.6]$ cp src/redis-trib.rb /usr/local/bin/

Create the cluster


[root@centos7-1 ~]# wget http://download.redis.io/releases/redis-3.0.6.tar.gz
[root@centos7-1 ~]# tar xvf redis-3.0.6.tar.gz
[root@centos7-1 ~]# cd redis-3.0.6/
[root@centos7-1 redis-3.0.6]# make MALLOC=libc
[root@centos7-1 redis-3.0.6]# make install
0

The above create The command creates a cluster, option �replicas 1 Each said Master I need 1 for both Slave . So the result is that three are created in the cluster Master Nodes and 3 Slave Node.

As indicated by M in the above information Master The node, S Slave Node.

So you can see three groups Master and Slave The relationship is as follows:


[root@centos7-1 ~]# wget http://download.redis.io/releases/redis-3.0.6.tar.gz
[root@centos7-1 ~]# tar xvf redis-3.0.6.tar.gz
[root@centos7-1 ~]# cd redis-3.0.6/
[root@centos7-1 redis-3.0.6]# make MALLOC=libc
[root@centos7-1 redis-3.0.6]# make install
1

Detect the status of the cluster


[root@centos7-1 ~]# wget http://download.redis.io/releases/redis-3.0.6.tar.gz
[root@centos7-1 ~]# tar xvf redis-3.0.6.tar.gz
[root@centos7-1 ~]# cd redis-3.0.6/
[root@centos7-1 redis-3.0.6]# make MALLOC=libc
[root@centos7-1 redis-3.0.6]# make install
2

Test cluster

using redis-cli -c -p The port number connects the cluster


[root@centos7-1 ~]# redis-cli -c -p 7000
127.0.0.1:7000> get hello
(nil)
127.0.0.1:7000> set hello "hello world"
OK
127.0.0.1:7000> get hello
"hello world"
127.0.0.1:7000> get name 
-> Redirected to slot [5798] located at 127.0.0.1:7001
(nil)
127.0.0.1:7001> set name "redis server"
OK
127.0.0.1:7001> get name
"redis server"

conclusion

The above is the whole content of installing redis 3.0.6 and configuring the cluster under CentOS 7 system. I hope the content of this paper can bring you a certain help in your study or work. If you have any questions, you can leave a message to communicate.


Related articles: