redis redis-cluster cluster structures

redis Cluster Setup - micro letter public reference number (poetic programmer): https://mp.weixin.qq.com/s/s5eJE801TInHgb8bzCapJQ

 

This is a description from the official website of redis, probably means:

Redis is an open source (BSD license) is stored in memory data structures, as a database, cache and message broker. It supports data structure, such as a string, a hash ranked set, a list, set with a range query, bitmaps, hyperloglogs, and query the geospatial zone radius index stream and the like. Redis has a built-in replication, Lua script, LRU cleared affairs and different levels of persistent disk, and provides high availability by Redis Sentinel and automatic partitioning with Redis cluster.

and so on ...

But this is not the focus of today, today's focus is to build redis clusters.

Set up a cluster, install a version of the click , actually quite simple to install.

 

redis stand-alone installation:

  • redis c language development. Install redis need c compiler environment language. If you do not need to install gcc online. yum install gcc-c ++

  • The redis installation package uploaded to the Linux and unzip it.

  • Redis into the source directory to compile. Enter the command: make

  • After compilation installed, enter the command: make install PREFIX = / usr / local / redis

       PREFIX specify the installation directory redis, I installed in the / usr / local / redis

 

 

 

Then click on the version already installed, then start it:

Directly start the installation directory of redis:

Enter the command: [root @ localhost bin] # ./redis-server 

 

 

 

This interface represents the emergence of a successful start.

You can view redis process:

Enter the command: ps aux | grep redis

 

 

 

 

But this is the front desk to start, exit redis shut down, following the method of setting the background to start.

  • 把/root/redis-3.0.0/redis.conf复制到/usr/local/redis/bin目录下

  • 进入/usr/local/redis/bin目录下,修改redis.conf配置文件,将daemonize no 改为 yes,保存并退出

 

 

 

  • 这时再次启动redis,但是要指定配置文件以后台启动

    输入命令:[root@localhost bin]# ./redis-server redis.conf

 

 

 

可以看到并没有出现redis的启动图标,那是否启动成功了呢?这时我们查看一下redis进程。

输入命令:ps aux|grep redis

 

 

 

可以看到redis已经成功启动。

下面我们开始搭建集群版,下面是redis官网的一段截取。

 

 

 

更多的介绍请到redis官网查看。

由于redis-cluster采用投票容错的方式来判断该节点是否挂掉,投票容错简单点说就是投票超总数的一半即判定该节点挂掉,因此最少需要三个节点,但是由于redis-cluster要保证高可用,因此每个主节点需要一个备份机,也就是说至少需要六个节点。

这里在redis官网也提到了。

 

 

 六个节点需要六台服务器,这里为了演示就先搭建一个伪分布式,操作步骤和在六台服务器上搭建完全一样。

 

集群环境搭建

步骤一

使用ruby脚本搭建集群,需要ruby的运行环境

安装ruby

yum install ruby

yum install rubygems

 

 

 

步骤二

安装ruby脚本运行所需的依赖包 redis-3.0.0.gem

[root@localhost wl]# gem install redis-3.0.0.gem

搭建redis集群

搭建伪分布式,需要6个redis的实例,分别运行在7001,7002,7003,7004,7005,7006端口

步骤一

创建6个redis实例,把之前的单机版复制6份就可以。

在/usr/local/下创建redis-cluster目录

 

 

 将/usr/local/redis目录下的单机版复制6分到/usr/local/redis-cluster/

 

 

 步骤二

Each instance runs on a different port. Redis.conf need to modify the configuration file.

Configuration file also need to comment before the cluster-enabled yes removed.

Enter redis01 directory, open the configuration file redis.conf

Modify the port number is 7001, and the comment before removing the cluster-enabled yes

 

 

 

 

 

 The other five do the same settings, note that the port is not the same.

Step Three

  • Start each instance redis

  • Use ruby ​​script to build a cluster, you need redis-trib.rb, this source file in the src directory.

  • Into the src directory, copy redis-trib.rb to the / usr / local / redis-cluster directory

    cp redis-trib.rb /usr/local/redis-cluster

  Enter / usr / local / redis-cluster directory execute the command:

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

  • This redis clusters to build complete, then start clicking.

    One by one start too cumbersome, to write a script

    Creating a script .sh under redis-cluster directory,

  • Create a permission to modify the file after completion 

    chmod u+x start_redis.sh

    Run the file sh start_redis.sh, start redis clusters

    View background processes ps aux | grep redis 

  •  

     Redis can see the cluster started successfully.

Guess you like

Origin www.cnblogs.com/wlv1314/p/12324492.html