Redis Redis and pseudo-cluster environment set up

First, the preparatory work

  1. GCC compiler environment
  2. ruby operating environment
  3. Install ruby ​​script package

Second, the installation environment

1.GCC environment

First, because redis is written in C, so you need to install GCC environment, you can use

gcc -v

GCC command to check whether the installation environment, if already installed you can skip this step, to no avail

yum install gcc-c++

Online GCC environment to install.

2.ruby operating environment

Note: If you just want to use the stand-alone Redis, that is not to build a cluster environment can skip installing 3, but if you want to build a cluster, then redis environment and must have a ruby ​​script package

Use the following two commands to install ruby ​​operating environment:

yum install ruby
yum install rubygems

3.ruby script package

The Internet to download the ruby ​​script package, download address https://rubygems.org/gems/redis/versions/3.0.0 uploaded to the Linux installation, I use a redis-3.0.0.gem package, so use the command

gem install redis-3.0.0.gem 

To install, where to install according to their version,

Three, redis installation

1. Download the redis own source package uploaded to Linux, unzip

2. Go to redis extracted directory, there is a Makefile is used to install redis, enter the command

make install PREFIX=/usr/local/redis

After PREFIX specifies redis installation directory, you can modify their own, I am here to install it into / usr / local / redis directory

Four, redis start

There are two kinds of start redis front and rear ends of two ways, it is recommended to use the back end to start, after you use the front start, quit client, redis service shut down, is not conducive to the development

Front-end start

Relatively simple way to start the front end, enter the directory redis

cd /usr/local/redis/bin
./redis-server

See the following screen illustrates a successful start redis

Back-end start

Backend start redis need to modify the configuration file, extract the first copy to the next /redis-3.0.0/redis.conf directory / usr / local / redis / bin directory,

cp /redis-3.0.0/redis.conf /usr/local/redis/bin

After modifying the configuration file, open redis.conf with vim, then no modification will find daemonize no to yes, save and exit, and then command

./redis-server redis.conf

Start redis, you can use the command ps aux | grep redis redis whether to start to see success, if there is redis process, on behalf of the successful launch

Connection and close redis

Connecting redis: ./ redis-cli -h 192.168.61.129-p 6379

-h: address of the server connection

-p: Port number services

Close redis: ./redis-cli shutdown

Fifth, build redis pseudo-cluster (focus)

Because the vote of fault tolerance mechanisms redis, redis redis clusters require at least three servers, each server needs redis timing to send their status to other servers, so that other redis servers to vote to confirm this server is not hung up, in order to ensure cluster high availability, each host node must have at least one spare node, so this time we set up three primary and three backup node.

1. Create redis-cluster directory under / usr / local directory

2. Modify redis.conf file in the bin directory using the vim command to open redis.conf keyword search to find the cluster-enabled yes this one, remove the comments, save and exit

3. Copy the bin directory to the directory redis-cluster, six copies, each folder and rename redis01, redis02 ...... and so on

cp -r /usr/local/redis/bin/ /usr/local/redis-cluster/redis01

cp -r /usr/local/redis/bin/ /usr/local/redis-cluster/redis02

...........................

4. redis01,02 respectively modify the configuration file of each port in the port are so 7001,7002,7003 ....

5. In order to facilitate a key to start the cluster without a redis a boot server, we create startup and shutdown services redis batch script, create two named start-all.sh and shutdown-all are in redis-cluster directory. sh file, the file contents are as follows:

start-all.sh

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 ../

shutdown-all.sh

redis01/redis-cli -p 7001 shutdown
redis02/redis-cli -p 7002 shutdown
redis03/redis-cli -p 7003 shutdown
redis04/redis-cli -p 7004 shutdown
redis05/redis-cli -p 7005 shutdown
redis06/redis-cli -p 7006 shutdown

And to modify the two file permissions to make it executable

chmod u+x start-all.sh  
 chmod u+x shutdown-all.sh  

6. Use a batch script to start redis each node, and then use the ruby ​​script to build redis clusters

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

Here there is a special point to note, when using the above command to build a cluster, when performing the Can I set the above configuration? ( Type 'yes' to accept) the time, will let you enter yes to continue to pay attention! ! ! Here is the input yes! Here is the input yes! Here is the input yes! Rather than other Linux command input y on the implementation of, if not enter yes, first set up the cluster unsuccessful but no error will result in a number of connected nodes behind the operation can not be performed in the pit blogger who spent a to find the cause of the afternoon, make sure to remember! ! !

This redis clusters to build complete, because constraints, this time we set up a pseudo-cluster.

Six: connection to the cluster

Use command to connect the cluster, wherein the parameter indicates that the connection is -c cluster redis

redis01/redis-cli -p 7002 -c

Guess you like

Origin www.cnblogs.com/blackmlik/p/12075047.html