In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
A preface
Redis-Sentinel is a high availability (HA) solution officially recommended by Redis. When Redis is used as a high-availability solution for Master-slave, if master goes down, Redis itself (including many of its clients) does not automatically switch between master and slave, and Redis-sentinel itself is also an independent process, which can monitor multiple master-slave clusters and switch itself when master is down. Its main functions are:
From time to time, monitor whether redis is running well as expected.
2 if a redis node is found to be in a condition, you can notify another process (such as its client).
(3) it can switch automatically. When a master node is unavailable, one of the multiple slave of the master (if there is more than one slave) can be elected as the new master, and the other slave nodes will change the address of the master it follows to the new address of the slave promoted to the master. Second practice
This paper introduces the high availability system of building master-slave replication and three-node sentinel to build redis. Among them, redis has a set of master and slave, sentinel has three nodes due to machine resource constraints, and two sentinel nodes and redis are reused.
2.1 Environmental preparation
Redis version: Redis-3.2.8
OS version CentOS 6
Redis 、 sentinel
10.9.34.172 reids master
10.9.43.207 reids slave
Sentinel
10.9.34.252 sentinel2.2 Software installation
Wget http://download.redis.io/releases/redis-3.2.8.tar.gz
Tar zxvf redis-3.2.8.tar.gz
Mv redis-3.2.8 / usr/local/redis
Cd / usr/local/redis
Make PREFIX=/usr/local/redis install
Cd src & & make test
Create a soft connection
Ln-s / usr/local/redis/bin/redis-cli / usr/local/bin/redis-cli
Ln-s / usr/local/redis/bin/redis-sentinel / usr/local/bin/redis-sentinel
Ln-s / usr/local/redis/bin/redis-server / usr/local/bin/redis-server; 2.3 configuration file
Copy the sentinel.conf and redis.conf files in the source package to the / etc/redis directory, we need to rewrite the configuration file to configure the master and slave.
Mkdir-p / etc/redis
Cp / usr/local/redis/redis.conf / etc/redis/redis_7021.conf
Cp / usr/local/redis/sentinel.conf / etc/redis/sentinel_17021.conf
Cp / usr/local/redis/utils/redis_init_script / etc/init.d/redis of course, if it is like MySQL stand-alone multi-instance, the redis configuration file can also be put in the instance of redis, such as / data/redis7021/redis.conf, and follow the redis instance.
The content of redis_7021.conf
It should be noted that in order to facilitate the removal of permissions and bind and set protected-mode to no, the installation and testing process because of these two parameters caused several additional problems. It is recommended to enable these two parameters in production. Also remember that this example is the main library, and the slave library needs to be added.
Slaveof master_ip port
# redis.conf
# Redis configuration file example.
#. / redis-server / path/to/redis.conf
# # INCLUDES # #
# this is useful when you have a standard configuration template but each redis server needs personality settings.
# include / path/to/local.conf
# include / path/to/other.conf
# # GENERAL # #
# whether to run in the background, yes: run in the background; no: not run in the background (default in the old version)
Daemonize yes
For the parameters in # 3.2, whether to enable the protection mode is enabled by default. If the bind and password are not specified in the configuration. When this parameter is enabled, redis will only access it locally and deny external access. If the password and bind are enabled, you can open it. Otherwise, it is best to turn it off and set it to no.
Protected-mode no
# process file of redis
Pidfile "/ data/redis_7021/run/redis.pid"
# Port number of redis snooping.
Port 7021
# this parameter determines the length of the completed queue in the TCP connection (after the completion of the three-way handshake), of course, this value must not be greater than the / proc/sys/net/core/ somaxconnvalue defined by the Linux system, which defaults to 511, while the default parameter value for Linux is 128. When the concurrency of the system is large and the speed of the client is slow, these two parameters can be set together. The default value of this kernel parameter is generally 128, which is not enough for heavily loaded service programs. It is usually modified to 2048 or greater. Add: net.core.somaxconn = 2048 to / etc/sysctl.conf, and then execute sysctl-p in the terminal.
Tcp-backlog 511
# specify that redis will only receive requests from this IP address. If not set, all requests will be processed.
# bind 10.9.34.172
# configure unix socket to enable redis to listen for local connections.
Unixsocket "/ data/redis_7021/run/redis.sock"
# configure permissions for unix socket to use files
# unixsocketperm 700
# this parameter sets the client to be idle beyond timeout, and the server will disconnect. If 0, the server will not actively disconnect, and cannot be less than 0.
Timeout 0
# tcp keepalive parameter. If the setting is not 0, the SO_ KEEPALIVE value of the configured tcp is used. Using keepalive has two benefits: it detects the dead peer. Reduce the problem that there is something wrong with the intermediate device, which leads to the problem that the network appears to be connected but is already connected to the peer port. In the Linux kernel, keepalive,redis is set to send ack to the peer on a regular basis. Twice the setting value is required to detect a peer shutdown.
Tcp-keepalive 0
# specifies the level of the server log. Levels include: debug (a lot of information to facilitate development and testing), verbose (a lot of useful information, but not as much as debug-level information), notice (appropriate log level, suitable for production environment), warn (only very important information)
Loglevel notice
# specifies the file to log. If the string is empty, the log will be printed to the standard output device. The standard output of redis running in the background is / dev/null.
Logfile "/ data/redis_7021/log/alert.log"
# whether to enable the record syslog function
# syslog-enabled no
Identifier of # syslog.
# syslog-ident redis
# Source and device of log
# syslog-facility local0
# the number of databases. The default database is DB 0. You can select a db through the "SELECT" command
Databases 16
# # SNAPSHOTTING # #
# Snapshot configuration
# comment out the line configuration item "save" to invalidate the ability to save the database
# set the frequency of database mirroring by sedis.
At least 1 key value change within # 900 seconds (15 minutes) (then save the database-persist)
# change at least 10 key values within # 300 seconds (5 minutes) (then save the database-persist)
# change at least 10000 key values within 60 seconds (1 minute) (then save the database-persist)
# save 900 1
# save 300 10
# save 60 10000
# whether to continue to work after an error occurs in RDB persistence. Yes: cannot work. No: you can continue to work. You can check whether there are any errors in RDB persistence through rdb_last_bgsave_status in info.
Stop-writes-on-bgsave-error yes
# use compressed rdb files, rdb files are compressed using LZF compression algorithm, yes: compression, but require some cpu consumption. No: no compression, more disk space is needed
Rdbcompression yes
# whether to verify the rdb file. Starting with the fifth version of the rdb format, the CRC64 checksum is included at the end of the rdb file. This is good for file fault tolerance, but there will be about 10% performance loss when saving rdb files, so if you are looking for high performance, you can turn off the configuration.
Rdbchecksum no
# name of the rdb file
Dbfilename "dump.rdb"
# data directory, where the database will be written. Rdb and aof files will also be written in this directory
Dir "/ data/redis_7021/data"
# # REPLICATION # #
# replication option, slave copy the corresponding master.
# slaveof
# if requirepass is set for master, then slave needs to have the password of master to connect to master. Masterauth is the password used to configure master so that you can authenticate after you connect to master.
# masterauth "youzan"
# when the slave library loses connection with the host or the replication is in progress, the slave library can be run in two ways: 1) if slave-serve-stale-data is set to yes (the default), the slave library will continue to respond to client requests. 2) if slave-serve-stale-data is set to no, any request except the INFO and SLAVOF commands will return an error "SYNC with master in progress".
Slave-serve-stale-data yes
# as a slave server, it is yes by default and can be modified to NO for writing (not recommended).
Slave-read-only yes
# whether to use socket to copy data. Currently, there are two ways of redis replication, disk and socket. If the new slave is connected or the reconnected slave cannot be partially synchronized, a full synchronization is performed and the master generates a rdb file. There are two ways: the disk way is for master to create a new process to save the rdb file to disk, and then pass the rdb file on the disk to slave. Socket is a master process that creates a new process and sends the rdb file directly to slave as socket. In disk mode, when a rdb is saved, multiple slave can share the rdb file. The way of socket is to copy one slave sequentially. Socket is recommended when the disk speed is slow and the network speed is fast.
Repl-diskless-sync no
# delay time for diskless replication, to prevent it from being set to 0. Once replication begins, the node will no longer receive replication requests from the new slave until the next rdb transmission. So it's best to wait for a while and wait for more slave to connect.
Repl-diskless-sync-delay 5
# slave sends ping requests to the server at specified intervals. The interval can be set through repl_ping_slave_period, with a default of 10 seconds.
Repl-ping-slave-period 5
# replication connection timeout. Both master and slave have timeout settings. When master detects that the last time slave sent exceeds repl-timeout, slave is considered offline and the slave message is cleared. If slave detects that the last interaction with master is longer than repl-timeout, master is considered offline. It is important to note that repl-timeout needs to set a higher value than repl-ping-slave-period, otherwise timeouts will be detected frequently.
Repl-timeout 60
# whether to prohibit copying the tcp nodelay parameter of the tcp link. You can pass yes or no. The default is no, even with tcp nodelay. If master sets yes to disable the tcp nodelay setting, the number of packets and network bandwidth will be reduced when copying data to slave. But it can also lead to data delays. By default, we recommend a smaller latency, but in scenarios where the amount of data transfer is large, yes is recommended.
Repl-disable-tcp-nodelay no
# copy buffer size, which is a circular copy buffer that holds the latest copied commands. In this way, when slave is offline, there is no need to completely copy the data of master. If partial synchronization can be performed, only part of the data in the buffer needs to be copied to slave, and the normal replication state can be restored. The larger the buffer size, the longer the slave can be offline, and the copy buffer allocates memory only when there is a slave connection. Memory will be freed for a period of time without slave, with a default of 1m.
Repl-backlog-size 32mb
# master without slave for a period of time frees up the memory of the replication buffer, and repl-backlog-ttl is used to set the length of time. In seconds.
Repl-backlog-ttl 3600
# when master is not available, Sentinel elects a master based on the priority of the slave. The lowest priority slave, selected as master. If configured to 0, it will never be elected.
Slave-priority 100
# redis provides a way for master to stop writing. If min-slaves-to-write is configured, writing is prohibited if the number of healthy slave is less than Nredis. At a minimum, how many healthy slave must be alive for master to execute write commands. Although this configuration does not guarantee that all N slave will receive write operations from master, it can avoid that when there is not enough healthy slave, master can not write to avoid data loss. Set to 0 to turn off the feature.
# min-slaves-to-write 3
# A slave with a latency less than min-slaves-max-lag seconds is considered a healthy slave.
# min-slaves-max-lag 10
# set 1 or another setting to 0 to disable this feature.
# Setting one or the other to 0 disables the feature.
# By default min-slaves-to-write is set to 0 (feature disabled) and
# min-slaves-max-lag is set to 10.
# # SECURITY # #
The # requirepass configuration allows users to use AUTH commands to authenticate passwords before using other commands. This allows redis to be used in untrusted networks. To maintain backward compatibility, you can comment on the command because most users do not need authentication either. Be careful when using requirepass, because Redis is so fast that you can authenticate 15w passwords per second, and simple passwords are easy to break, so it's best to use a more complex password.
# requirepass "youzan"
# change the dangerous command to another name. For example, the CONFIG command can be renamed to a command that is hard to guess, so that users cannot use it, and internal tools can continue to be used.
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
Rename-command SHUTDOWN REDIS_SHUTDOWN
Rename-command FLUSHDB REDIS_FLUSHDB
Rename-command FLUSHALL REDIS_FLUSHALL
Rename-command KEYS REDIS_KEYS
# rename-command CONFIG REDIS_CONFIG
# rename-command SLAVEOF REDIS_SLAVEOF
# set to an empty value, you can disable a command
# rename-command CONFIG ""
# # LIMITS # #
# set the maximum number of client connections that can be connected to redis. The default is 10000 client connections. Because redis does not distinguish whether the connection is a client connection or an internal open file or a slave connection, the minimum recommended setting for maxclients is 32. If the maxclients,redis is exceeded, a 'max number of clients reached', is sent to the new connection and the connection is closed.
# maxclients 10000
# the maximum memory capacity configured by redis. When the memory is full, it needs to be handled in conjunction with the maxmemory-policy strategy. Note that the output buffer of slave is not counted in maxmemory. Therefore, in order to prevent the host from running out of memory, it is recommended that you set a smaller maxmemory.
Maxmemory 512mb
# processing strategy when the memory capacity exceeds the maxmemory.
# volatile-lru: use the LRU algorithm to remove the key that sets the expiration time.
# volatile-random: randomly remove the key that sets the expiration time.
# volatile-ttl: remove the key that is about to expire and delete it according to the most recent expiration time (supplemented by TTL)
# allkeys-lru: use the LRU algorithm to remove any key.
# allkeys-random: randomly remove any key.
# noeviction: no key is removed, only a write error is returned.
# the above expulsion strategies, if redis does not have a suitable key expulsion, will still return an error for writing commands. Redis will no longer receive write requests, only get requests. Write commands include: set setnx setex append incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby getset mset msetnx exec sort.
Maxmemory-policy allkeys-lru
# the number of samples detected by lru. Using the lru or ttl elimination algorithm, randomly select sample key from the list to be eliminated, and select the key that has been idle for the longest time to be removed.
# maxmemory-samples 5
# # APPEND ONLY MODE # #
# the default redis uses rdb persistence, which is sufficient in many applications. However, if the redis goes down midway, it may result in a few minutes of data loss. Persistence is based on save strategy. Append Only File is another persistence method, which can provide better persistence characteristics. Redis will write the data written each time into the appendonly.aof file after receiving. Every time Redis starts, it will read the data of this file into memory and ignore the RDB file first.
Appendonly no
# aof file name
Appendfilename "appendonly.aof"
# configuration of aof persistence policy
# no means that the fsync is not executed, and the operating system ensures that the data is synchronized to disk, which is the fastest.
# always means that fsync is executed for each write to ensure that the data is synchronized to disk.
# everysec means that fsync is executed every second, which may result in the loss of 1s of data.
Appendfsync everysec
# A large number of IO will be executed when aof is rewritten or written to the rdb file. For the aof mode of everysec and always, the execution of fsync will block for too long, and the no-appendfsync-on-rewrite field is set to no by default. For applications with high latency requirements, this field can be set to yes, otherwise it can be set to no, which is a more secure option for persistence features. Set to yes means that the new write operation is not fsync during rewrite and is temporarily stored in memory until the rewrite is completed. Default is no. Yes is recommended. The default fsync policy for Linux is 30 seconds. Data may be lost for 30 seconds.
No-appendfsync-on-rewrite yes
# aof automatically rewrites the configuration. Rewrite when the current aof file size exceeds the last rewritten aof file size, that is, when the aof file grows to a certain size, Redis can call bgrewriteaof to rewrite the log file. When the current AOF file size is twice the size of the AOF file obtained from the last log rewrite (set to 100), a new log rewrite process is automatically started.
Auto-aof-rewrite-percentage 100
# set the minimum aof file size allowed to be rewritten to avoid reaching the agreed percentage but the size is still very small.
Auto-aof-rewrite-min-size 64mb
The # aof file may be incomplete at the end. When redis starts, the data of the aof file is loaded into memory. Restart may occur after the operating system of the host where the redis is located is down, especially if the ext4 file system does not add the data=ordered option (redis downtime or abnormal termination will not cause tail incompleteness. If this happens, you can choose to let redis exit or import as much data as possible If yes is selected, when the truncated aof file is imported, a log is automatically published to the client and then load. In the case of no, the user must manually redis-check-aof to repair the AOF file.
Aof-load-truncated yes
# # LUA SCRIPTING # #
# if the maximum time limit (milliseconds) is reached, redis will record a log and return error. When a script exceeds the maximum time limit. Only SCRIPT KILL and SHUTDOWN NOSAVE are available. The first thing that can be killed without calling the write command. If you have already called write, you can only use the second command to kill.
Lua-time-limit 5000
# # REDIS CLUSTER # #
# Cluster switch. Cluster mode is not enabled by default.
# cluster-enabled yes
# the name of the cluster configuration file. Each node has a cluster-related configuration file, which persists the cluster information. This file does not need to be manually configured. This configuration file is generated and updated by Redis. Each Redis cluster node needs a separate configuration file. Make sure it does not conflict with the name of the configuration file in the system on which the instance is running.
# cluster-config-file nodes-7021.conf
The threshold for the # node interconnection timeout. Number of milliseconds of cluster node timeout
# cluster-node-timeout 30000
# during failover, all slave will request to apply for master, but some slave may be disconnected from master for a period of time, resulting in obsolete data, such slave should not be promoted to master. This parameter is used to determine whether the disconnection between the slave node and the master is too long. The method of judgment is:
# compare the disconnection time of slave and (node-timeout * slave-validity-factor) + repl-ping-slave-period
# if the node timeout is 30 seconds and the slave-validity-factor is 10, it is assumed that the default repl-ping-slave-period is 10 seconds, that is, slave will not attempt to fail over if it exceeds 310 seconds
# it may occur that the cluster cannot work properly because a master node is lost but no slave node can be topped. In this case, the cluster will not resume operation until the original master node returns to the cluster.
# if set to 0, no matter how long the slave node loses contact with the master node, the slave node will try to upgrade to the master node
# cluster-slave-validity-factor 10
If the number of slave of # master is greater than this value, slave can be migrated to other isolated master. For example, if this parameter is set to 2, only if a master node has two working slave nodes, one of its slave nodes will try to migrate.
# the minimum number of slave nodes required by the master node, which will be migrated only when the master node fails.
# cluster-migration-barrier 1
# by default, all slot of the cluster is assigned by nodes, and the cluster status is ok before the service can be provided. Set to no to provide services when the slot is not fully allocated. It is not recommended to open this configuration, as this will cause the master of a small partition to accept write requests all the time, resulting in data inconsistency for a long time.
# if this parameter is set to "yes" (the default) when some of the nodes where the key resides are not available, the whole cluster stops accepting operations; if this parameter is set to "no", the cluster still provides read operations for key on reachable nodes
# cluster-require-full-coverage yes
# # LOG # #
# slog log is used to record the time spent on commands that are slow to execute while redis is running. When the execution of the command exceeds the specified time, it is recorded in slow log, and the slog log is saved in memory, so there is no IO operation.
# requests with execution time longer than slowlog-log-slower-than are recorded in slowlog in microseconds, so 1000000 is 1 second. Note that a negative time disables the slow query log, while 0 forces all commands to be logged.
Slowlog-log-slower-than 10000
# slow query log length. When a new command is written to the log, the oldest record is deleted. There is no limit to this length. As long as there is enough memory. You can free memory through SLOWLOG RESET.
Slowlog-max-len 128
# # LATENCY MONITOR # #
# delay monitoring feature is used to monitor some slow operations in redis, and use LATENCY to print the time-consuming chart of redis instances when running commands. Only operations that are greater than or equal to the values set below are recorded. If 0, turn off the surveillance. The default delay monitoring function is off, and if you need to turn it on, you can also set it dynamically through the CONFIG SET command.
Latency-monitor-threshold 0
# # EVENT NOTIFICATION # #
# Keyspace notifications allow clients to subscribe to channels or patterns to receive events that have changed the Redis dataset in some way. Because it takes some CPU to turn on the keyspace notification feature, it is turned off by default.
The argument to # notify-keyspace-events can be any combination of the following characters, which specifies what types of notifications the server should send:
# # K key space notifications, all notifications are prefixed with _ _ keyspace@__
# # E key event notifications, all notifications are prefixed with _ _ keyevent@__
# # Notification of general commands unrelated to g DEL, EXPIRE, RENAME, etc.
# # Notification of $string command
# # Notification of l list command
# # Notification of s Collection Command
# # Notification of hash command
# # z Notification of ordered collection commands
# # x Expiration event: sent whenever an expired key is deleted
# # e eviction (evict) event: sent whenever a key is deleted because of maxmemory policy
# # alias of parameter A g$lshzxe
# there must be at least one K or E in the input parameters, otherwise, no notification will be distributed regardless of the rest of the parameters. For more information, please refer to http://redis.io/topics/notifications.
Notify-keyspace-events "e"
# # ADVANCED CONFIG # #
# use ziplist if the amount of data is less than or equal to hash-max-ziplist-entries, and hash if it is greater than hash-max-ziplist-entries
Hash-max-ziplist-entries 512
# ziplist is used if the value size is less than or equal to hash-max-ziplist-value, and hash is used when the size is greater than hash-max-ziplist-value.
Hash-max-ziplist-value 64
# the amount of data is less than or equal to list-max-ziplist-entries using ziplist, and greater than list-max-ziplist-entries using list.
List-max-ziplist-entries 512
# ziplist is used if the value size is less than or equal to list-max-ziplist-value, and list is used when the size is greater than list-max-ziplist-value.
List-max-ziplist-value 64
# the amount of data is less than or equal to set-max-intset-entries using iniset, and greater than set-max-intset-entries using set.
Set-max-intset-entries 512
# the amount of data is less than or equal to zset-max-ziplist-entries using ziplist, and greater than zset-max-ziplist-entries using zset.
Zset-max-ziplist-entries 128
# value size is less than or equal to zset-max-ziplist-value using ziplist, and greater than zset-max-ziplist-value using zset.
Zset-max-ziplist-value 64
# value size less than or equal to hll-sparse-max-bytes uses sparse data structures (sparse), and larger than hll-sparse-max-bytes uses dense data structures (dense). A value larger than 16000 is almost useless, and the recommended value is about 3000. If the requirement of CPU is not high, and the requirement of space is high, it is recommended to set it to about 10000.
Hll-sparse-max-bytes 3000
# Redis will use 1 millisecond of CPU time every 100ms to re-hash the hash table of redis, which reduces memory usage. When you have a very strict real-time requirement in your usage scenario and cannot accept that Redis has a delay of 2 milliseconds to the request from time to time, configure this as no. If you don't have such strict real-time requirements, you can set it to yes so that memory can be freed as quickly as possible.
Activerehashing yes
# # restrictions on client output buffering can force clients that do not read data from the server to disconnect and force clients with slow transmission to shut down.
# for normal client, the first 0 means to cancel the hard limit, and the second 0 and the third 0 means to cancel the default restriction of the soft limit,normal client, because they will not receive data if they are not asked.
Client-output-buffer-limit normal 0 0 0
# for slave client and MONITER client, once client-output-buffer exceeds 256mb, or lasts 60 seconds beyond 64mb, the server will disconnect the client immediately.
Client-output-buffer-limit slave 256mb 64mb 60
# for pubsub client, once client-output-buffer exceeds 32mb, or lasts for 60 seconds beyond 8mb, the server will disconnect the client immediately.
The content of client-output-buffer-limit pubsub 32mb 8mb 60sentinel_17021.conf
The name of master is youzan
Port 17021
Dir "/ data/sentinel_17021"
Logfile "/ data/sentinel_17021/log/alert.log"
Daemonize yes
Protected-mode no
Sentinel monitor youzan 10.9.34.172 7021 2
Sentinel down-after-milliseconds youzan 5000
Sentinel failover-timeout youzan 120000
# sentinel client-reconfig-script youzan / opt/bin/notify.py
Rename-command SHUTDOWN REDIS_SHUTDOWN
# content of sentinel auth-pass youzan xxx/etc/init.d/redis
#! / bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the / proc filesystem.
REDISPORT=7021
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/data/redis_$ {REDISPORT} / run/redis.pid
CONF= "/ etc/redis/redis_$ {REDISPORT} .conf"
HOST= `hostname-i`
Case "$1" in
Start)
If [- f $PIDFILE]
Then
Echo "$PIDFILE exists, process is already running or crashed"
Else
Echo "Starting Redis server..."
Su redis-c "$EXEC $CONF"
Fi
Stop)
If [!-f $PIDFILE]
Then
Echo "$PIDFILE does not exist, process is not running"
Else
PID=$ (cat $PIDFILE)
Echo "Stopping..."
$CLIEXEC-h $HOST-p $REDISPORT redis_shutdown
While [- x / proc/$ {PID}]
Do
Echo "Waiting for Redis to shutdown..."
Sleep 1
Done
Echo "Redis stopped"
Fi
*)
Echo "Please use start or stop as first argument"
Esac2.4 adds redis and sentinel accounts.
Avoid using root account to start redis directly (there are related security risks, take advantage of the vulnerability of improper configuration of Redis to increase the rights of linux server root)
Useradd redis
Mkdir-p / data/redis_7021/ {data,log,run}
Mkdir-p / data/sentinel_17021/ {log,run}
Chown-R redis.redis / data/redis_7021/
Chown-R redis.redis / etc/redis/
Useradd sentinel
Chown-R sentinel.sentinel / data/sentinel_17021/
Chown-R sentinel.sentinel / etc/redis/sentinel_17021.conf
Chmod 664 / etc/redis/sentinel_17021.conf2.5 deploy other nodes
The above procedure is to configure the redis main library and one of the sentinel, and copy the above process to install redis and sentinel again at 10.9.43.207, but it should be noted that we set 10.9.43.207 as the slave node of redis, so add slaveof 10.9.34.172 7021 to the configuration file redis_7021.conf. For installing the third sentinel node 10.9.34.252, simply select the sentinel-related steps in the above steps.
2.6 start redis and sentinel
Start redis
/ etc/init.d/redis start
Close redis
/ etc/init.d/redis stop
Su sentinel-c "redis-sentinel / etc/redis/sentinel_17021.conf"
The log after starting sentinel is as follows
32126:X 31 Jul 23:28:41.570 # Sentinel ID is b28ca1bb3d722e09d0de905caa380397455e8e3c
32126 quorum X 31 Jul 23 28 quorum 41.570 # + monitor master youzan 10.9.34.172 7021 quorum 2
32126 Jul X 31 Jul 23 28 youzan 41.571 * + slave slave 10.9.43.207 7021 10.9.43.207 7021 @ youzan 10.9.34.172 7021
32126youzan X 31 Jul 23V 28V 54.484 * + sentinel sentinel 5c44560584c3245590e86fa78880eacccdfe8318 10.9.34.252 17021 @ youzan 10.9.34.172 70212.7 to conduct fault drills
On the main library
10.9.34.172Viru 7021 > debug sleep 30
OK
(30.01s) observe the log output of sentinel
32126 X 01 Aug 09 24 12.752 # + sdown master youzan 10.9.34.172 7021
32126 quorum X 01 Aug 09 24 12.828 # + odown master youzan 10.9.34.172 7021 # quorum 2
32126 X 01 Aug 092412.828 # + new-epoch 1
32126 X 01 Aug 09 24 12.828 # + try-failover master youzan 10.9.34.172 7021
32126 X 01 Aug 092412.838 # + vote-for-leader b28ca1bb3d722e09d0de905caa380397455e8e3c 1
32126:X 01 Aug 09:24:12.842 # 5c44560584c3245590e86fa78880eacccdfe8318 voted for b28ca1bb3d722e09d0de905caa380397455e8e3c 1
32126 X 01 Aug 09 24 12.928 # + elected-leader master youzan 10.9.34.172 7021
32126 X 01 Aug 09 24 12.928 # + failover-state-select-slave master youzan 10.9.34.172 7021
32126 Aug X 01 youzan 09 24 youzan 12.995 # + selected-slave slave 10.9.43.207 7021 10.9.43.207 7021 @ youzan 10.9.34.172
32126 Aug X 01 youzan 09 24 Vol 12.995 * + failover-state-send-slaveof-noone slave 10.9.43.207 7021 10.9.43.207 7021 @ youzan 10.9.34.172 7021
32126 Aug X 01 youzan 09 24 Vol 13.047 * + failover-state-wait-promotion slave 10.9.43.207 7021 10.9.43.207 7021 @ youzan 10.9.34.172 7021
32126 Aug X 01 youzan 09 24 youzan 13.893 # + promoted-slave slave 10.9.43.207 7021 10.9.43.207 7021 @ youzan 10.9.34.172
32126 X 01 Aug 09 24 13.893 # + failover-state-reconf-slaves master youzan 10.9.34.172 7021
32126 X 01 Aug 09 24 13.942 # + failover-end master youzan 10.9.34.172 7021
32126 Aug X 01 09 24 13.942 # + switch-master youzan 10.9.34.172 7021 10.9.43.207 7021
32126 Aug X 01 youzan 09 24 youzan 13.943 * + 10.9.34.172 youzan 10.9.34.172 7021 @ youzan 10.9.34.172
32126 Aug X 01 youzan 09 24 youzan 18.986 # + 10.9.34.172 youzan 10.9.34.172 7021 @ youzan 10.9.34.172
32126 youzan X 01 Aug 09 24 youzan 37.041 #-sdown slave 10.9.34.172 7021 10.9.34.172 7021 @ youzan 10.9.43.207 7021
32126 youzan X 01 Aug 09 24 youzan 47.041 * + convert-to-slave slave 10.9.34.172 7021 10.9.34.172 7021 @ youzan
Observe the configuration file of sentinel and be modified and rewritten.
Three summaries
This article is an entry-level how to document, which introduces how to install and deploy redis sentinel high-availability architecture, and the content is relatively simple. It should be noted that a set of database storage system for operation and maintenance is certainly not so simple, but also involves related processes, logs, performance monitoring, and so on. The case in this article still has a long way to go from production practice, continue to learn.
Four reference articles
[1] Sentinel high availability installation and deployment for Redis
[2] Mechanism and usage of Redis Sentinel (1)
[3] Mechanism and usage of Redis Sentinel (2)
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.