redis: redis sentinel (sentry) master-slave high availability scheme


http://wosyingjun.iteye.com/blog/2289593




    Monitoring: Sentinel constantly checks that your master and slave servers are functioning properly.
    Notification (Notification): Sentinel can send notifications to administrators or other applications through the API when there is a problem with one of the monitored Redis servers.
    Automatic failover: When a master server fails to work properly, Sentinel will start an automatic failover operation, which will upgrade one of the slave servers of the failed master server to the new master server, and let the failed master server The other slave servers are changed to replicate the new master server; when the client tries to connect to the failed master server, the cluster will also return the address of the new master server to the client, so that the cluster can use the new master server instead of the failed server.


Sentinel supports
clustering Obviously, it is unreliable to use only a single sentinel process to monitor the redis cluster. When the sentinel process is down (sentinel itself also has a single point of problems, single-point-of-failure) the entire cluster system will not be able to perform as expected way to operate. So it is necessary to cluster the sentinel, which has several advantages:

  • Even if some sentinel processes are down, the master-slave switch of the redis cluster can still be performed;
  • If there is only one sentinel process, if the process runs incorrectly or the network is blocked, the master-slave switchover of the redis cluster will not be possible (single point problem);
  • If there are multiple sentinels, the redis client can connect to any sentinel at will to obtain information about the redis cluster.


Sentinel Version
Sentinel's current latest stable version is called Sentinel 2 (to distinguish it from the previous Sentinel 1 ). Released with the installation package of redis2.8. After installing Redis2.8, you can find the startup program of Redis-sentinel in redis2.8/src/ .



sentinel_63791.conf configuration:
port
63791 daemonize yes
logfile "/var/log/sentinel_63791.log"
#master-1
sentinel monitor master-1 192.168.78.99 6379 2
sentinel down-after-milliseconds master-1 5000
sentinel failover-timeout master -1 18000
sentinel auth-pass master-1 yingjun
sentinel parallel-syncs master-1 1

sentinel_63792.conf Configuration:
port 63792
daemonize yes
logfile "/var/log/sentinel_63792.log"
#master-1
sentinel monitor master-1 192.168.78.99 6379 2
sentinel down-after-milliseconds master-1 5000
sentinel failover-timeout master-1 18000
sentinel auth-pass master-1 yingjun
sentinel parallel-syncs master-1 1

redis_master_6379. conf configuration:
make the following modifications in the original configuration file:
port 6379
daemonize yes
requirepass yingjun
masterauth yingjun

redis_slave_6380.conf configuration:
make the following modifications in the original configuration file:
port 6380
daemonize yes
requirepass yingjun
slaveof 192.168.78.99 6379
masterauth yingjun

redis_slave_6381.conf configuration:
Make the following modifications in the original configuration file:
port 6381
daemonize yes
requirepass yingjun
slaveof 192.168.78.99 6379
masterauth yingjun

starts the services in the following order:
./redis-server ../conf/redis_master_6379.conf
./redis-server ../conf/redis_slave_6380.conf   
./redis-server ../ conf/redis_slave_6381.conf   
./redis-sentinel ../conf/sentinel_63791.conf
./redis-sentinel ../conf/sentinel_63792.conf


Third, Jedis Sentinel tutorial
Maven dependency:
    redis.clientsjedis2.8.0org.springframework.dataspring- data-redis1.6.4.RELEASE Redis configuration file:
#redis config
redis.pass=yingjun
redis.pool.maxTotal=105
redis.pool.maxIdle=10
redis.pool.maxWaitMillis=60000
redis.pool.testOnBorrow=true

sentinel1.ip=192.168.78.99
sentinel1.port=63791

sentinel2.ip=192.168.78.99
sentinel2.port=63792

Spring的配置文件:

代码中直接用redisTemplate调用:
    @Override
    public boolean add(final KeyToken tkey) {
        boolean result = redisTemplate.execute(new RedisCallback() {

            @Override
            public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
                RedisSerializer serializer = getRedisSerializer();
                byte[] key = serializer.serialize(tkey.getIndex());
                byte[] name = serializer.serialize(tkey.getExpire_time());
                return connection.setNX(key, name);
            }

        });
        return result;
    }



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326486050&siteId=291194637