1.redis master-slave configuration
If redis need to achieve high availability on the condition that achieve data synchronization
(1) Copy the folder configuration shards renamed sentinel
(2) from the main building strategy
6379 host.
6380 Slave
6381 Slave
(3) Check the status information
info replication
(4) from the main mount
(5) Check the mounted state from the master
2. Sentinel mechanism
2.1 Role of Sentinel
By Sentinel mechanism, can achieve redis highly available , if the primary node goes down, the Sentinel through the election mechanism, select a slave, while other machines to modify configuration files, configure a new host.
2. Edit the configuration file Sentinel
(1) Preparations
The Sentinel configuration file into the folder sentinel
(2) off protected mode
(3) modify the sentry monitor
sentinel monitor mymaster 192.168.126.166 6379 2
2: 2 votes expressed consent to the election take effect.
(4) modify the timing of the elections
When the host goes down how long to start election
(5) amending electoral defeat timeout
(6) Start Sentinel
Start command: redis-sentinel sentinel.conf
Test Procedure:
- Close redis host, 10 seconds after checking redis Sentinel is normal election.
- The host is rebooted, check if downgraded to a slave.
(7) Sentinel entry case
@Test public void test01 () { / * * * masterName: variable name of the host * sentinels: Sentinel represents the link * new new HostAndPort ( "192.168.126.166", 26379) .toString () * * results after the conversion * 192.168. 126.166: 26379 * / the Set <String> = Sentinels new new HashSet <> (); sentinels.add ( " 192.168.126.166:26379 " ); JedisSentinelPool sentinelPool = new new JedisSentinelPool ( " mymaster " , Sentinels); Jedis jedis= sentinelPool.getResource(); jedis.set("bb","哨兵操作"); System.out.println(jedis.get("bb")); }
.