Linux (Centos7) to build a distributed cluster under redis5

Note: You can view the official website to see Redis Cluster Setup mode, connected as follows

https://redis.io/topics/cluster-tutorial

There should be at least three cluster nodes, each node has a backup node. Need six servers.

If the condition is limited, you can build pseudo-distributed, the following steps are Redis cluster structures have six nodes on a Linux server.

Preparation: install dependencies

[root@localhost ~]#yum install -y gcc g++ make gcc-c++ kernel-devel automake autoconf libtool make wget tcl vim  unzip git

 

1. Create a project catalog in hand into

命令:mkdir /usr/local/redis-cluster

Command: cd / usr / local / redis-cluster

 

 

 

2. Download and unpack compile source packages installed

Command: wget http://download.redis.io/releases/redis-5.0.5.tar.gz # version installed redis5.0.5

Command: tar -zvxf  Redis-5.0.5.tar.gz unpack #

 

 

 

3. Go to the directory where redis, began to compile and install

Command: cd redis-5.0.5 # to enter the directory has the Makefile if you can compile and install the

Command: make # compiler

Command: make install PREFIX = / usr / local / redis # compiler installation and redis placed under / usr / local / redis, this can be directly used redis

Well, now successfully installed redis

 

4. Create six redis configuration file (note: 6 profile can not be placed in the same directory)

命令:[root@localhost redis-5.0.5]# cp redis.conf /usr/local/redis

命令:[root@localhost redis-5.0.5]# cp redis.conf /usr/local/redis/bin

命令:[root@localhost redis-5.0.5]# cd /usr/local/redis

命令:[root@localhost redis]# cp -r bin /usr/local/redis-cluster/redis01

命令:[root@localhost redis]# cd /usr/local/redis-cluster/redis01

Command: [root @ localhost redis01] # vim redis.conf # modify the configuration file

 

 

 Modify the path to the configuration file:

1) port 7001 # port

2) cluster-enabled yes # Enable cluster mode              

3) cluster-config-file nodes.conf # Set the corresponding port is not entered, the port is the default port 

4) cluster-node-timeout 5000 # timeout

5) appendonly yes # open persistent mode

6) daemonize yes # running in the background

7) protected-mode no # non-protected mode

8) pidfile /var/run/redis_7001.pid # prevent multiple processes start copies, only to start 7001

(Knowledge expansion: the process runs .pid file will add a file lock, the lock process gets only have write permission (F_WRLCK),

The pid written to the file itself, the other trying to get the lock process will automatically exit. )

9) bind 172.20.10.7 # 127.0.0.1 to local ip, ip a view available ifconfig or ip

This profile has already done, then save and exit, and then create an additional five nodes

 

5. Create the other five nodes

Command: cd / usr / local / redis-cluster / # enter the directory redis

[root@localhost redis-cluster]# cp -r redis01  redis02
[root@localhost redis-cluster]# cp -r redis01  redis03
[root@localhost redis-cluster]# cp -r redis01  redis04
[root@localhost redis-cluster]# cp -r redis01  redis05
[root@localhost redis-cluster]# cp -r redis01  redis06        #将配置目录复制5份

 

 

 Then modify the configuration file: port and modifications are pidfile under the redis.conf redis02 ~ redis06

Modify the content:

1)port 7001

2)pidfile /var/run/redis_7001.pid

 

 

 

6. Start node

There are two ways to start

1) respectively to redis01, redis02, ... redis06 directory, execute: ./redis-server ./redis.conf

2) Make a script execution start-all.sh

Script reads as follows:

cd redis01
./redis-server redis.conf
cd ..
cd redis02
./redis-server redis.conf
cd ..
cd redis03
./redis-server redis.conf
cd ..
cd redis04
./redis-server redis.conf
cd ..
cd redis05
./redis-server redis.conf
cd ..
cd redis06
./redis-server redis.conf
cd ..

Then add permissions to execute the script on the line

Command: chmod u + x start-all.sh # add permissions to the script

Command: ./ start-all.sh

 

 

 Then look at the way if the node starts successfully

Command: ps aux | grep redis

 

 

 

7. Start Cluster

Because this redis redis-cli file directory 5.0.0 version of the above we use Redis cluster built just need to compile the catalog copy to redis-cluster come on it

As for redis-cli can be found at /usr/local/redis-cluster/redis-5.0.5/src, and then copied to / usr / local / redis-cluster on it

命令:cp -r    /usr/local/redis-cluster/redis-5.0.5/src/redis-cli   /usr/local/redis-cluster

命令:/usr/local/redis-cluster/redis-cli --cluster create 192.168.100.248:7001 192.168.100.248:7002 192.168.100.248:7003 192.168.100.248:7004

192.168.100.248:7005 192.168.100.248:7006 --cluster-replicas 1 # start command (Note: Starting in accordance with their own IP)

 

 

 

 

 

 To this place, finished it redis cluster started successfully

 

8. The operation of the cluster

Shut down the cluster, write a script file in the create-cluster directory: vim shutdown.sh

Script reads as follows:

/ usr / local / Redis-Cluster / Redis -C -H 192.168.100.248 -p-CLI the shutdown 7001
/ usr / local / Redis-Cluster / Redis -C -H 192.168.100.248 -p-CLI the shutdown 7002
/ usr / local / Redis-Cluster / Redis -C -H 192.168.100.248 -p-CLI the shutdown 7003
/ usr / local / Redis-Cluster / Redis -C -H 192.168.100.248 -p-CLI the shutdown 7004
/ usr / local / Redis-Cluster / Redis-cli -c -h 192.168.100.248 7005 the shutdown -p
/ usr / local / Redis-Cluster / Redis-cli -p 7006 -c -h 192.168.100.248 the shutdown
and then to add the script and execute permissions to this file

Command: chmod u + x shutdown.sh

Command: ./ shutdown.sh

 

 

Redis View cluster status

Command: ps aux | grep redis

 

 

 Knowledge expansion:

官方:/usr/local/redis-cluster/redis-cli -a xxx -c -h 192.168.100.248 -p 7001

Tip: -a password to access the server, -c represent cluster model, -h specify the ip address, -p specify the port number

 

9. Restart the cluster

At the end add start-all.sh script / usr / local / redis-cluster / redis-cli --cluster create 192.168.100.248:7001 192.168.100.248:7002 192.168.100.248:7003

192.168.100.248:7004 192.168.100.248:7005 192.168.100.248:7006 --cluster-replicas Note: Use your own IP of the machine 

 Then execute the script on it

Command: ./ start-all.sh

 

 

 

10. Test cluster

Executed in redis-cluster directory

Command: redis01 / redis-cli -h 192.168.100.248 -p 7002 -c (Note: with their own IP)

Command: cluster nodes # query cluster node information

Command: cluster info # cluster status information queries

 

 

 (Extended knowledge: the primary and password)

Redis.conf need to modify these two lines in redis01 ~ redis06 configuration file

masterauth 123456 # master-password

requirepass 123456 # access password

 

 

 

 

 Then restart the service

 

 

 

to sum up:. . . . . . . . . . . . . . . . . (Omitted here a million words)

 

Guess you like

Origin www.cnblogs.com/zgqbky/p/11792141.html