Get the App
SLTechnology News&Howtos  ›  Servers  › 

Cluster deployment of redis caching service in million PV architecture

Shulou Source: shulou.com Published: 2022-06-02 04:58:49 10月05日 Update

Introduction to redis

Redis is a key-value storage system. Similar to Memcached, it supports relatively more value types, including string (string), list (linked list), set (collection), zset (sorted set-ordered collection), and hash (hash type). These data types support push/pop, add/remove, and take intersection union and difference sets, and richer operations, and these operations are atomic. On this basis, redis supports a variety of different sorting methods. Like memcached, data is cached in memory for efficiency. The difference is that redis will periodically write updated data to disk or modify operations to additional record files, and on this basis to achieve master-slave (master-slave) synchronization.

Case environment host IP address role Centos7192.168.71.134redis-masterCentos7192.168.71.129redis-slave building process

1. Master-slave installation of redis

[root@localhost ~] # yum install epel-release-y

[root@localhost ~] # yum install redis-y

2. The master server modifies the configuration file

[root@localhost ~] # vim / etc/redis.confbind 0.0.0.0 # listens on any port

3. Modify the configuration file from the server

[root@localhost ~] # vim / etc/redis.confbind 0.0.0.0 # listen on any port # slaveof slaveof 192.168.71.128 6379 # points to the ip and port of the master server

4. Enable the service from the master / slave server

[root@localhost ~] # systemctl start redis

5. Verify synchronization function (remember to turn off the firewall)

Log in and write content on the main server

[root@localhost] # redis-cli-h 192.168.71.134-p 6379

192.168.71.134 6379 > set abc 111

OK

192.168.71.134purl 6379 > get abc

"111"

Log in from the server to view the content

[root@localhost] # redis-cli-h 192.168.71.129-p 6379

192.168.71.129purl 6379 > get abc

"111"

At this point, the synchronization function is complete, and then the master-slave function is built.

6. Master-slave settings of master server

[root@localhost ~] # vim / etc/redis-sentinel.conf

17-line protected-mode no

69 line sentinel monitor mymaster 192.168.71.134 6379 1 # master address, port, slave server 1

98 line sentinel down-after-milliseconds mymaster 300 # set the switching time

7. Start the service (you don't need to make any configuration from the server, just start the service)

[root@localhost ~] # systemctl start redis-sentinel.service

8. Check the master-slave status on the master server

[root@localhost] # redis-cli-h 192.168.71.134-p 26379 info sentinel

9. Disable a redis and check the master-slave status again.

[root@localhost ~] # systemctl stop redis

10. When the service is enabled again, master will not return to the master service, and the slave server can be disabled again.

Root@localhost ~] # systemctl stop redis # Slave server downtime redis [root@localhost ~] # systemctl start redis # Master server opens redis [root@localhost ~] # redis-cli-h 192.168.71.134-p 26379 info sentinel# Sentinelsentinel_masters:1sentinel_tilt:0sentinel_running_scripts:0sentinel_scripts_queue_length:0sentinel_simulate_failure_flags:0master0:name=mymaster,status=ok,address=192.168.71.134:6379,slaves=1,sentinels=3

Tags: Service server master-slave port again function data file type synchronization support configuration content address base state storage login monitoring cache Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MariaDB Linux Apple vpn