Several high-availability clustering solution Redis

Redis high availability cluster usual way and the way to have:

  1. Master-slave mode
  2. Sentinel mode
  3. Cluster Mode

Of course, there are third-party proxy mode, and the like as codis, this discussion is not listed here.

I'm just here to learn, I would simply configure these types of models recorded. Veterans and are not interested in, can this drifting away.

Start the installation and a single instance of the Redis, not repeat them here, it is actually relatively simple.

A master-slave mode

This model is solved on a single machine memory performance problems, and the primary instance can be placed in a different machine from the above examples. Can use for backup from the machine, when the master host fails, a slave station can be promoted to master. Improve the cache performance to some extent, if able to accept a certain delay, may be isolated from a master, are all read from the Slave up, to improve performance.

Configuration is very simple and can be configured in the configuration file or command line directly coupled slaveof host:ip

redis-6380.conf

Slaveof 127.0.0.1:6379

or

127.0.0.1:6380>127.0.0.1:6379

Then each starting from example Redis master on the line.

Master-slave mode, while better than some of the availability of a single instance, but production would use substantially less. Because he did not fail and monitoring. If linked to the master, but also to the need to manually cut to slave above. Address your application to connect have to make the appropriate changes. This is indeed a little trouble, so it feels a little awkward in this mode.

Two sentry mode

The pattern here, and a bit like a master-slave mode, he is based on the master-slave mode. He provides monitoring and failover for the master when the master node fails, can be automatically selected by the election of a slave master to do, until master failover, then cut back, which greatly improves the usability and Sentinel you can do between cluster deployment, monitoring each other. Sentinel prevented individual dead.

在redid-sentinel.conf

sentinel monitor mymaster 127.0.0.1 6379 1

The above configuration with the line, behind that 6379 represents 1 after take several sentinel node consent before they start failover.

Sentinel mode startup mode in two ways:

redis-sentinel sentinel-26379.conf
redis-server sentinel-26379.conf --sentinel

Because the sentinel pattern is a special Redis nodes can be connected using redis-cli

redis-cli -p 26379

127.0.0.1:26379> info sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=odown,address=127.0.0.1:6379,slaves=1,sentinels=1

Under less demanding situations, in fact Sentinel general pattern of the company with sufficient.

Three cluster model

Many examples from different master form large clusters, from multiple multi-master, a master die from the examples, can be transferred to other internal master from the above examples. At least three primary node cluster running to make up.

Configure several machines out of local pseudo-cluster model I use is only one machine, and then to start with a different port.

Create a directory, such as call redis-cluster. And then create a subdirectory in the 6381-6386 directory.

Profiling redis.conf in 6381, the contents are as follows:

daemonize yes

pidfile redis_6381.pid

logfile redis_6381.log

appendonly yes

bind 127.0.0.1

port 6381

cluster-enabled yes

cluster-config-file nodes-6381.conf

cluster-node-timeout 15000

cluster-slave-validity-factor 10

cluster-migration-barrier 1

cluster-require-full-coverage yes

The beginning of the cluster in which these are some of the cluster configuration, the same way, in other directories also add the above configuration, but the 6381 into a corresponding port on the line.

Then start single-instance 6381-6386, respectively

redis-server 6381/redis.conf

redis-server 6382/redis.conf

Verify whether the successful start

ps -ef | grep redis

redis-server 127.0.0.1:6381 [cluster]

Later with [Cluster] This says that line.

The above are just a few examples start to become cluster model, but also the last step, using redis-trib, but I use the local redis5.0, has been recommended by redis-cli This way, if a redis-trib this environment also need to install ruby. I am here to redis-cli an example of

redis-cli --cluster create --cluster-replicas 1  127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385 127.0.0.1:6386

The output appears as follows, represents a cluster is created successful.

I simply said that under the order, by the above command can be just our machines become cluster mode and configure the master and slave. Mainly behind the cluster-replicas 1, the ratio 1 represents an example of a master-slave (master / slave), such as the above is the master from 1: 1, then the main 6381-6383, from 6383 to 6381, followed by other analogy.

Test, I use a simple test of the Go In the cluster and reading, using a go-redis package.

package main

import (
   "fmt"
   "github.com/go-redis/redis"
   "time"
)

func testClient() {
   client := redis.NewClusterClient(&redis.ClusterOptions{
      Addrs:[]string{"127.0.0.1:6381","127.0.0.1:6382","127.0.0.1:6383","127.0.0.1:6384","127.0.0.1:6385","127.0.0.1:6386",},
   })
   statuscmd :=client.Set("name","lc",60 *  time.Second)
   if statuscmd.Err() != nil {
      fmt.Println(statuscmd.Err())
   }
   stringcmd :=client.Get("name")
   fmt.Println(stringcmd.String())
}

func main() {
   testClient()
}

Here, the configuration of several models would be finished, but it is still quite simple, if you want to understand more advanced, you own to refer to the corresponding documentation, and I also recorded my learning process, the more advanced also not been studied.

Guess you like

Origin www.cnblogs.com/smartrui/p/12406178.html