Redis cluster configuration and introduction

1. Introduction to redis cluster

Redis cluster is an assembly that provides data sharing among multiple Redis nodes.

Redis cluster and does not support simultaneous processing of multiple keys Redis commands , because it requires moving data across multiple nodes, this will reduce the performance of redis clusters, in the case of high load may cause unexpected errors.

Redis clusters provide a certain degree of availability through partitioning. Even if some nodes in the cluster fail or cannot communicate, the cluster can continue to process command requests.

Insert picture description here

Advantages of Redis cluster:

  1. The cache never goes down : Start the cluster and always let part of the cluster work. If the master node fails, the child node can quickly change the role to become the master node, and the entire cluster can continue to process commands if some nodes of the entire cluster fail or are unreachable;

  2. Quickly restore data : persistent data can quickly solve the problem of data loss after a downtime;

  3. Redis can use the memory of all machines to expand performance in disguise ;

  4. Redis of the computing capacity by simply adding servers to get increase exponentially , Redis of network bandwidth will also increase computer and network cards exponentially increase ;

  5. Redis cluster does not have a central node , and a certain node will not become the performance bottleneck of the entire cluster;

  6. Asynchronously process data to achieve fast reading and writing.

2. Build a redis cluster

2.1 Download the redis installation package and unzip

# 下载安装包
cd /export/softwares
wget http://download.redis.io/releases/redis-3.2.8.tar.gz

# 解压
cd /export/softwares
tar -zxvf redis-3.2.8.tar.gz -C ../servers/

2.2 Install C program operating environment

yum -y install gcc-c++

2.3 Install tcl

Tcl (tool command language) is a simple scripting language , mainly used to issue commands to some interactive programs such as text editors , debuggers and shells . It has a simple syntax and strong extensibility. Tcl can create new procedures to enhance its built-in command capabilities.

Secondly, Tcl is a library package that can be embedded in applications . The Tcl library contains an analyzer , routines for executing built-in commands, and library functions that allow you to expand (define new procedures) . The application program can generate and execute Tcl commands. The commands can be generated by the user or read from an input in the user interface (button or menu, etc.). But after receiving the command, the Tcl library decomposes it and executes the built-in commands, which often produces recursive calls

yum  -y  install  tcl

2.4 Compile redis

# 编译
make MALLOC=libc 或 make
# 测试编译是否完成
make test 或者 make install

2.5 Create and modify the configuration of different instances of redis

# 创建对应文件夹
cd /export/redis-3.2.8
mkdir -p /export/redis-3.2.8/clusters/7001
mkdir -p /export/redis-3.2.8/clusters/7002
mkdir -p /export/redis-3.2.8/clusters/7003
mkdir -p /export/redis-3.2.8/clusters/7004
mkdir -p /export/redis-3.2.8/clusters/7005
mkdir -p /export/redis-3.2.8/clusters/7006

mkdir -p /export/redis-3.2.8/logs
mkdir -p /export/redis-3.2.8/redisdata/7001
mkdir -p /export/redis-3.2.8/redisdata/7002
mkdir -p /export/redis-3.2.8/redisdata/7003
mkdir -p /export/redis-3.2.8/redisdata/7004
mkdir -p /export/redis-3.2.8/redisdata/7005
mkdir -p /export/redis-3.2.8/redisdata/7006

Copy the configuration file to the corresponding folder, and then modify the configuration

# 对应主机
bind hadoop1
# 端口,7001配置为7001,7002配置为7002,以此类推
port 7001
cluster-enabled yes
# 不同文件夹不同
cluster-config-file nodes-7001.conf
cluster-node-timeout 5000
appendonly yes
daemonize yes
# 同上,7001的地方都要对应不同文件夹进行修改
pidfile /var/run/redis_7001.pid
logfile "/export/redis-3.2.8/logs/7001.log"
dir /export/redis-3.2.8/redisdata/7001

2.6 Start redis

cd  /export/servers/redis-3.2.8
src/redis-server cluster/7001/redis.conf
src/redis-server cluster/7002/redis.conf
src/redis-server cluster/7003/redis.conf
src/redis-server cluster/7004/redis.conf
src/redis-server cluster/7005/redis.conf
src/redis-server cluster/7006/redis.conf

There is no reminder when redis is started, you can use it to ps -ef | grep redischeck whether it is started

Insert picture description here

2.7 Install ruby ​​operating environment

Redis cluster startup requires ruby ​​environment

yum install ruby
yum install rubygems
gem install redis

If there is a ruby ​​version error, Solve according to the following methods:

Insert picture description here

# 安装rvm,rvm是ruby version Manager,ruby版本管理器
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -L https://get.rvm.io | bash -s stable
# 查找 rvm路径
find / -name rvm -print
source /usr/local/rvm/scripts/rvm

# 查看ruby版本
rvm list known

# 安装高版本ruby
rvm install 2.3.3
# 使用高版本ruby
rvm use 2.3.3
# 将ruby设为默认
rvm use 2.3.3 --default
# 卸载旧版本ruby
rvm remove 2.0.0

If it is curl reporting an error, you can refer to the curl table https://www.cnblogs.com/xueyou/p/curl.html

The curl command can refer to http://www.ruanyifeng.com/blog/2019/09/curl-reference.html

but. . . . mineThe virtual machine has not been able to access https://get.rvm.io, The local browser can be accessed, and when the browser is found to visit https://get.rvm.io , jump to https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer . Ran goose. . The virtual machine still couldn't access this website, so I gave up using it completely curl -L https://get.rvm.io | bash -s stableand chose an ancient method. . Create a .sh file on the virtual machine, and then copy the content on the web page. . Re-executecat test.sh | bash -s stable

2.8 Create redis cluster

cd /export/redis-3.2.8
gem install redis
src/redis-trib.rb create --replicas 1 192.168.100.100:7001 192.168.100.100:7002 192.168.100.100:7003 192.168.100.100:7004 192.168.100.100:7005 192.168.100.100:7006

2.9 Connect redis client

src/redis-cli -h hadoop1 -c -p 7001

Guess you like

Origin blog.csdn.net/qq_24852439/article/details/104443659