Redis Master-Slave +sentinel

Source: Internet
Author: User

As one of the mainstream products of NoSQL database, Redis is now widely used, how to guarantee the high availability and automatic failover of Redis, this paper introduces the master-slave configuration method of Redis and Sentinel building of failover. As follows:

Environment Description:

Server System: CentOS 6.5 X64

Redis Software Description: 2.8.19 version

One: Configure Master-Slave Redis

1. Architecture:

Main Library: 172.16.52.130

From library 1:172.16.52.131

From library 2:172.16.52.132

2, Master-slave operation:

Tar xvf redis-2.8.19.tar.gz-c/usr/local

cd/usr/local/redis-2.8.19/

Make && make install

mkdir data

Vim redis.conf

---

#在最后可以直接加如下命令

Aof-rewrite-incremental-fsync Yes

Daemonize Yes

Logfile/var/log/redis.log

Syslog-enabled No

Dir/usr/local/redis-2.8.19/data

Requirepass system#为下面sentinel做准备主从均需配置

slaveof 172.16.52.130 6379#从库加上该配置, the main library does not add this configuration

Masterauth system#为下面sentinel做准备主从均需配置

#以上设计到的密码必须相同, if the settings are set, otherwise they are not set

---

3. Database Start-Stop operation

Start: redis-server/usr/local/redis/redis.conf

Close: redis-cli-a system shutdown

Notes

1) Master can not set the login password, then slave does not have to set Masterauth

2) master does not set the login password, the close command is: REDIS-CLI shutdown

4. Testing

REDIS-CLI-A system

Info

---

Slave0:ip=172.16.52.131,port=6379,state=online,offset=211171,lag=0

Slave1:ip=172.16.52.130,port=6379,state=online,offset=211171,lag=1

---

Data can also be tested: Insert data is created on the main library to see if the library is synchronized.

Second, configure Sentinel

Vim/etc/sentinel.conf

---

Port 26379

Daemonize Yes

LogFile "/var/log/sentinel.log"

Sentinel Monitor MyMaster 172.16.52.132 6379 1

Sentinel Down-after-milliseconds MyMaster 3000

Sentinel Failover-timeout MyMaster 10000

Sentinel Auth-pass MyMaster System#本验证密码和上面主从密码保持一致, you do not need to configure this section if the master/slave does not set the authentication password

---

Start-Stop Sentinel

Redis-sentinel/etc/sentinel.conf

Redis-cli-p 26379 shutdown

Log view:

Tail-f/var/log/sentinel.log

[24259] APR 16:42:58.280 # Sentinel Runid is f6688a7526b2b5f3298dc0c5348ae78207f1c1be

[24259] APR 16:42:58.280 # +monitor Master MyMaster 172.16.52.130 6379 Quorum 1

[24259] Apr 16:42:58.280 * +slave slave 172.16.52.132:6379 172.16.52.132 6379 @ mymaster 172.16

.52.130 6379

[24259] Apr 16:42:58.280 * +slave slave 172.16.52.131:6379 172.16.52.131 6379 @ mymaster 172.16

.52.130 6379

To ensure that Redis is highly available, it makes sense for Sentinel to select at least two or more sentinel, preferably three, to ensure that the voting mechanism

This article is from the "Floating Phoenix Year" blog, please be sure to keep this source http://liuzhanbin.blog.51cto.com/10060150/1639845

Redis Master-Slave +sentinel

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.