In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
The understanding of redis
Redis is a key-value storage system. Similar to Memcached, it supports relatively more value types to be stored, including string (string), list (linked list), set (collection), and zset (ordered collection). 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.
Redis clustering principle:
Redis cluster benefits: fault tolerance, can solve single-node redis problems; scalability, multi-node deployment; performance improvement.
1) all redis nodes are interconnected with each other (PING-PONG mechanism), and binary protocol is used internally to optimize transmission speed and bandwidth.
2) the fail of a node takes effect only when it is detected by more than half of the nodes in the cluster.
3) the client is directly connected to the redis node and does not need an intermediate proxy layer. The client does not need to connect all the nodes in the cluster, but can connect to any node in the cluster.
4) redis-cluster maps all physical nodes to [0-16383] slot slot, and cluster is responsible for maintaining 16384 hash slots built into the nodeslotvalue Redis cluster. When you need to place a key-value in the redis cluster, redis first uses the crc16 algorithm to calculate a result for the key, and then calculates the remainder of the result to 16384, which ensures that each key corresponds to the hash slot between 0 and 16383. Redis maps hash slots to different nodes roughly equally based on the number of nodes.
Redis master-slave replication + sentinel failover
Environment:
OS:centos
Redis version: above Redis3.0
Node:
Master 192.168.10.78 (redis+sentinel)
Slave01 192.168.10.80 (redis+sentinel)
Slave01 192.168.10.81 (redis+sentinel)
1.redis installation
Yum install-y make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel kernel keyutils patch perl
192.168.10.78 Master
Cd/usr/local/redis-3.0.7/redis-master/makemake installmake test (test can not be operated)
192.168.10.80 and 192.168.10.80 are the same.
2.redis configuration
Take the host 192.168.10.78 as an example.
Echo vm.overcommit_memory=1 > > / etc/sysctl.conf sysctl vm.overcommit_memory=1
Where "0: indicates that the kernel will check whether there is enough memory available for the application process, and 1: indicates that the kernel allows all physical memory to be allocated, regardless of the current memory state."
Vim / usr/local/redis-3.0.7/redis-master/src/redis.conf
Modify the following lines
Daemonize yes / / background run port 6379 logfile "/ var/log/redis.log" tcp-backlog 65535 # to increase the number of tcp backlog maxclients 20000 # this value is not too large, thinking that each socket connection will be opened by the system in the form of "file descriptor", so it is limited by the "file descriptor" of the Linux system. If the system setting is exceeded, server rejects the connection. Maxmemory 6gb # is preferably 3Universe 4 of physical memory, using maxmemory-policy allkeys-lru # Redis memory recovery strategy with maxmemory-policy, and data cleanup policy when memory is insufficient. Lru = last recent updated, allkeys-lru memory recovery strategy is recommended. Maxmemory-samples 3 # memory recovery policies lru and ttl policies are not forbidden policies, but use estimation methods, so sampling methods are selected for inspection. Select 3 key to eliminate those that are not commonly used. Slave-serve-stale-data yes # allows Redis slave to respond to customer requests even if it is not fully synchronized (sync). That is, if the current server is slave, whether to continue to provide services to customers when slave loses communication with master. Slave-read-only yes # forbids the possibility of Slave being accidentally written directly, and salve is read-only. # disable Redis to write to disk to improve performance # save 9001 # save 30010 # save 60 10000 min-slaves-to-write 1 # here guarantee that redis master must have at least one connected slave before it can be written, which is used to reduce the chance of replication losing data min-slaves-max-lag 10 # here guarantee that redis master will stop writing if you do not receive replication confirmation feedback from slave within 10 seconds
192.168.10.80 and 192.168.10.81 are configured as above, you can modify the corresponding ports.
80: slaveof 192.168.10.78 6379
81: slaveof 192.168.10.78 6379
3.sentinel configuration
Redis Sentinel is a distributed system that can be monitored (Monitoring), alerted (Notification), and automatic failover (Automatic failover).
You can run multiple Sentinel processes (progress) in a single architecture that use the rumor protocol (gossip protocols) to receive information about whether the master server is offline, and use the voting protocol (agreement protocols) to decide whether to perform an automatic failover and which slave server to choose as the new master server.
192.168.10.78 main configuration items description:
Vim / etc/sentinel.conf
Port 26379 # specifies the listening port of sentinel (that is, the port to establish a tcp connection with redis server or client) dir / usr/local/redis-3.0.7/redis-master/srcsentinel monitor mymaster 127.0.0.1 6379 2 # specifies the redis instance to be monitor by sentinel, including the alias (alias) of a redis instance and the ip+port of the redis instance. The number 2 at the end of the line means that the status of redis server is judged to be real fail only when at least two setinel instances detect a redis server exception at the same time. Sentinel down-after-milliseconds mymaster 20000 # specifies how long it takes for sentinel to monitor how long an exception persists in a redis instance (20s), and then determines that its status is down. Sentinel failover-timeout mymaster 60000 # if the sentinel fails to complete the failover operation within the configuration value (60s) (that is, master/slave automatically switches over in case of failure), the failover is considered to have failed. Sentinel parallel-syncs mymaster 1 # specifies the maximum number of slave instances that are simultaneously sentinel reconfigure during the failover process. Since the corresponding slave interrupts the response to client requests during the reconfigure process, this value should be appropriately reduced in order to avoid all slave being unavailable at the same time.
192.168.10.80 from the main configuration:
Port 26380dir / usr/local/redis-3.0.7/srcsentinel monitor mymaster 192.168.10.78 6379 2sentinel down-after-milliseconds mymaster 5000sentinel failover-timeout mymaster 60000sentinel parallel-syncs mymaster 1
192.168.10.81 from the main configuration:
Port 26381dir / usr/local/redis-3.0.7/srcsentinel monitor mymaster 192.168.10.78 6379 2sentinel down-after-milliseconds mymaster 5000sentinel failover-timeout mymaster 60000sentinel parallel-syncs mymaster 1
4. Start
Redis
192.168.10.78:
Cd / usr/local/redis-3.0.7/redis-master./src/redis-server. / redis-6379.conf &
192.168.10.80:
Cd / usr/local/redis-3.0.7./src/redis-server. / redis-6380.conf &
192.168.10.81:
Cd / usr/local/redis-3.0.7./src/redis-server. / redis-6381.conf &
Sentinel
192.168.10.78:
Cd / usr/local/redis-3.0.7/redis-master./src/redis-server. / sentinel-26379.conf-- sentinel &
192.168.10.80:
Cd / usr/local/redis-3.0.7/./src/redis-server. / sentinel-26380.conf-- sentinel &
192.168.10.81:
Cd / usr/local/redis-3.0.7./src/redis-server. / sentinel-26381.conf-- sentinel &
5. test
Connect the redis port
. / redis-cli-h 127.0.0.1-p 6379info replication
. / src/redis-cli-h 127.0.0.1-p 6379 info replication./src/redis-cli-h 127.0.0.1-p 26379 info Sentinel
Memory usage View:
Redis-cli-h 127.0.0.1 info | grep memory
Connect to the sentinel monitoring port test:
. / redis-cli-h 127.0.0.1-p 26379
SENTINEL get-master-addr-by-name mymaster
Note:
1. After the master-slave switch, the contents of redis.conf and sentinel.conf will change the reconfiguration, mainly want the original master-slave architecture, and then modify the configuration file.
2. Master is dead. Sentinel has chosen the new master, but has not changed it to master, but has changed old master to slave. Then if you restart old master at this time, you will be in an ownerless state. So on the one hand, you have to wait for sentinel to stabilize before starting old master, or manually modify the configuration file and restart the cluster.
3. Restore the service status of the redis (old master) whose service has been shut down, and the redis sentinel cluster service will rejoin the last master redis into the service, but he will no longer be the master redis and become the slave reids.
4. If you want redis-0 to join the cluster again, you need to first find the current masterip + port through the "INFO" instruction, and specify the slaveof parameter in the startup instruction:. / redis-server-- include / etc/redis.conf-- slaveof 192.168.10.80 6380
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.