Redis master-slave configuration and Sentinel Construction

Source: Internet
Author: User
Tags redis cluster
As one of the mainstream nosql database products, redis is widely used. This article introduces the master-slave configuration method and

As one of the mainstream nosql database products, redis is widely used. This article introduces the master-slave configuration method and

As one of the mainstream nosql database products, redis is widely used. This article describes the master-slave configuration method of redis and how to ensure high availability and automatic failover of redis.

As follows:
Environment Description:
Server: CentOS 6.5X64
Redis Software Description: 2.8.19
I. Configure Master/Slave redis
1. Architecture:
Master Database: 172.16.52.130
Slave database 1: 172.16.52.131
Slave database 2: 172.16.52.132
2. Master-slave operations:
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

---
# Add the following command directly at the end
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 # configure the master and slave nodes for the following sentinel preparations

Slaveof 172.16.52.130 6379 # Add the configuration from the slave database. This configuration is not added to the master database.
Masterauth system # configure the master and slave nodes for the following sentinel preparations
# The above passwords must be the same. If they are both set, they are not set.
---
3. Start and Stop a database
Start: redis-server/usr/local/redis. conf
Close: redis-cli-a system shutdown
Notes:
1) the master does not need to set the login password, so the slave does not need to set masterauth
2) When the master does not set the logon password, the command to shut down is redis-cli shutdown.
4. Test
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
---
At the same time, you can perform a data test: Create and insert data on the master database to check whether the slave database is synchronized.
Ii. 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 MySQL master 3000
Sentinel failover-timeout MySQL master 10000
Sentinel auth-pass mymaster system # This verification password is consistent with the master-slave password above. If the master-slave password is not set, this section is not required.
---
Start and Stop sentinel
Redis-sentinel/etc/sentinel. conf
Redis-cli-p 26379 shutdown
View logs:
Tail-f/var/log/sentinel. log
[24259] 27 Apr 16:42:58. 280 # Sentinel runid is f6688a7526b2b5f3298dc0c5348ae78207f1c1be
[24259] 27 Apr 16:42:58. 280 # + monitor master mymaster 172.16.52.130 6379 quorum 1
[24259] 27 Apr 16:42:58. 280 * + slave 172.16.52.132: 6379 172.16.52.132 6379 @ mymaster 172.16
.. 52.130 6379
[24259] 27 Apr 16:42:58. 280 * + slave 172.16.52.131: 6379 172.16.52.131 6379 @ mymaster 172.16
.. 52.130 6379
To ensure high availability of redis and make sentinel meaningful, select at least two or more sentinel servers. Generally, we recommend that you use three servers to ensure the voting mechanism.

Install and test Redis in Ubuntu 14.04

Redis cluster details

Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis

Redis series-installation, deployment, and maintenance

Install Redis in CentOS 6.3

Learning notes on Redis installation and deployment

Redis. conf

Redis details: click here
Redis: click here

This article permanently updates the link address:

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.