Redis installation, master-slave configuration and Sentinel configuration automatic failover

Source: Internet
Author: User
Tags benchmark failover keep alive redis cluster

1. Installing Redis

Home Address: http://redis.io/

: http://download.redis.io/Download the latest source package

TAR-ZXVF redis-stable.tar.gz-c/apps/product/cd  /apps/product/redis-stable/make MALLOC=libcmake Install

2. Operation

Load configuration files and run in the background

Redis-server/apps/product/redis-stable/redis.conf &

#redis-cli (command line tools)

3. Testing

# Redis-benchmark--help Get help information including stress test command sample

Practical Test Examples

[[Email protected]~]# redis-benchmark-t set-c 20-n 1000000-r 100000000====== set ====== 1000000 requests completed in 8.92 seconds Parallel clients 3 bytes payload Keep alive:1100.00% <= 0 milliseconds112095.06 requests per second

4. Master-slave configuration and measurement Try:

Main Gc-redis1 10.10.10.15 6379
From Gc-redis2 10.10.10.16 6379
From Gc-redis3 10.10.10.17 6379

#主服务器 (10.15) The following configuration, the other default can be:

[Email protected] redis-stable]# Vim/apps/product/redis-stable/redis.confmasterauth "Jrgcredispass" Requirepass " Jrgcredispass "

#从服务器上 (10.16,10.17) Do the following configuration, other default:

[Email protected] redis-stable]# vim/apps/product/redis-stable/redis.confslaveof 10.10.10.15 6379masterauth " Jrgcredispass "Requirepass" Jrgcredispass "[[email protected] redis-stable]# vim/apps/product/redis-stable/ redis.confslaveof 10.10.10.15 6379masterauth "Jrgcredispass" Requirepass "Jrgcredispass"

#启动主, from Redis services:

Redis-server/apps/product/redis-stable/redis.conf &

#主服务器显示信息:

[13997] 09:57:21.045 * Slave ask for synchronization[13997] Geneva 09:57:21.045 * Starting BGSAVE for sync[13997] 0 3 Nov 09:57:21.046 * Background saving started by PID 14002[14002] Geneva 09:57:21.058 * DB saved on disk[14002] Geneva 09 : 57:21.059 * rdb:0 MB of memory used by copy-on-write[13997] Geneva 09:57:21.070 * Background saving terminated with SUCC ess[13997] 09:57:21.070 * Synchronization with Slave succeeded

#从服务器显示信息:

  [3496] 09:56:41.953 * connecting to master...  [3496] Geneva 09:56:41.953 * MASTER <-> SLAVE Sync STARTED&NBSP;&NBSP;[3496] 09:56:41.954 * Non blocking Connect for SYNC fired the event.  [3496] Geneva 0  9:56:41.954 * Master replied to PING, replication can continue...  [3496] Geneva 09:56:42.055 * Master <-> SLAVE sync:receiving bytes from master  [3496] Geneva 09:56:42.055 * Master <-> SLAVE sync:loading D B in memory  [3496] Geneva 09:56:42.055 * MASTER <-> SLAVE sync:finished with success  [3499] 0 3 Nov 09:56:42.056 * SYNC append only file rewrite performed  [3499] Geneva 09:56:42.057 * AOF rewrite:0 MB of Memory used by copy-on-write  [3496] Geneva 09:56:42.057 * Background append only file rewriting started by PID 3499&NBSP;&NBSP;[3496] 09:56:42.154 * Background AOF rewrite terminated with success  [3496] Geneva 09:56 : 42.154 * Parent diff suCcessfully flushed to the rewritten AOF (0 bytes)   [3496] Geneva 09:56:42.154 * Background AOF rewrite finished Successfully

#主服务器查看主从信息

[Email protected] ~]# redis-cli-h 127.0.0.1-a redispass info replication# replicationrole:masterconnected_slaves : 2slave0:ip=10.10.10.16,port=6379,state=online,offset=168812144,lag=1slave1:ip=10.10.10.17,port=6379,state= Online,offset=168812144,lag=0master_repl_offset:168812281repl_backlog_active:1repl_backlog_size:1048576repl_ backlog_first_byte_offset:167763706repl_backlog_histlen:1048576

#从服务器查看主从信息

[Email protected] ~]# redis-cli-h 127.0.0.1-a redispass info replication# replicationrole:slavemaster_host : 10.10.10.15master_port:6379master_link_status:upmaster_last_io_seconds_ago:0master_sync_in_progress:0slave_ Repl_offset:168809239slave_priority:100slave_read_only:1connected_slaves:0master_repl_offset:0repl_backlog_ active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0

#写同步测试

#主服务器
[[email protected] ~]# redis-cli-h 127.0.0.1-a jrgcredispass redis 127.0.0.1:6379> set a 123OKredis 127.0.0.1:6379> ; Get a "123"

#从服务器

[Email protected]~]# redis-cli-h 127.0.0.1-a Jrgcredispassredis 127.0.0.1:6379> get a "123" [[Email protected]~]# Red Is-cli-h 127.0.0.1-a Jrgcredispassredis 127.0.0.1:6379> get a "123" Redis 127.0.0.1:6379> set B 234 (Error) READO NLY you can ' t write against a read only slave. (Read-only mode, so the data will not be written to ensure that the data is only synchronized from the primary server to the slave server)
#故障测试 # Downtime from the server will automatically be removed from the master-slave relationship of the primary server # master server down, displayed from the server, and cannot automatically switch
[15932] 09:46:25.465 * Connecting to MASTER ... [15932] 09:46:25.465 * MASTER <-> SLAVE sync started[15932] Nov 09:46:25.466 # Error condition on socket F or Sync:connection refused

5. Redis Sentinel Configuration

Home Address: Http://redis.io/topics/sentinel

Sentinel's primary function is to provide the Redis m-s (master,slaves) cluster with

1) Master Survival detection

2) M-s service monitoring in the cluster

3) automatic failover, m-s role conversion and other capabilities, from one aspect is to improve the availability of Redis cluster.

#添加并编辑配置文件/etc/sentinel.conf, add the following, or you can take care of the Sentinel configuration file in the installation file and make the appropriate modifications:

[[email protected] ~]# vim/apps/product/redis-stable/sentinel.confport 26379sentinel Monitor MyMaster 10.10.10.15 6379 2sentinel failover-timeout mymaster 900000sentinel auth-pass mymaster jrgcredispasssentinel Config-epoch mymaster 2#sentinel can-failover mymaster yessentinel leader-epoch mymaster 2---------------------------- -------------------------------------------------------------------[[email protected] ~]# vim/apps/product/ Redis-stable/sentinel.confport 26380sentinel Monitor MyMaster 10.10.10.15 6379 2sentinel failover-timeout MyMaster 900000sentinel auth-pass mymaster jrgcredispasssentinel config-epoch mymaster 2#sentinel can-failover MyMaster Yessentinel Leader-epoch MyMaster 2------------------------------------------------------------------------------ ----------------[[email protected] ~]# vim/apps/product/redis-stable/sentinel.confport 26381sentinel Monitor MyMaster 10.10.10.15 6379 2sentinel failover-timeout mymaster 900000sentinel Auth-pass MyMaster JrGcredispasssentinel Config-epoch mymaster 2#sentinel can-failover mymaster yessentinel Leader-epoch MyMaster 2 

#在三个服务器中以sentinel模式启动redis-server

Launch Sentinel [[email protected] ~] #redis-server/apps/product/redis-stable/sentinel.conf--sentinel &[[email Protected] ~] #redis-server/apps/product/redis-stable/sentinel.conf--sentinel &[[email protected] ~]# Redis-server/apps/product/redis-stable/sentinel.conf--sentinel &

#三台服务器sentinel输出: (Note that each machine output corresponds to the IP of the other two machines)

#关掉主gc-redis1 redis-server Service # will re-elect the master server and reconfigure the connection to the new primary server:

#查看主从关系: (Gc-redis2-based, gc-redis3 as from, if GC-REDIS1 restarts, will also be added to the new cluster from the server)

Start redisredis-server/usr/local/redis-stable/redis.conf & Stop redisredis-cli-a jrgcredispass shutdown Start sentinelredis-server/usr/local/redis-stable/sentinel.conf--sentinel & View Main preparation information: Redis-cli-h 127.0.0.1-p 6379-a Redispass Info Replication

.

Reference Document: http://mrcto.blog.51cto.com/1923168/1319542

  

Redis installation, master-slave configuration and Sentinel configuration automatic failover

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.