In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "download and installation configuration of redis". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the download and installation configuration of redis.
1. Download, compile and install redis
Http://www.redis.cn/download.html
When the download is complete, use the rz command to upload to the linux server tar-xvf redis-5.0.5.tar.gz # decompress the source package mv redis-5.0.5 / usr/local/redis # move the source package to the / usr/local/ directory and rename it rediscd / usr/local/redis/ # cd to the source directory
There are two errors in make # compilation, which can be solved.
# if the gcc package is not installed, the yum install gcc-y solution
# add an environment variable to compile together make MALLOC=libc can compile normally with this command
Make install # installs the compiled program, or you don't have to install it. Cd can be executed in the src directory. Cd / usr/local/bin/ # this directory is the script generated after the installation. The tools for opening and closing the client are all in it.
two。 Configure the configuration file, start and close the redisvim / usr/local/redis/redis.conf # configuration redis configuration file, modify the following option bind 0.0.0.0 # listening IP 0.0.0.0 means that all IP on this computer are listening to whether daemonize yes # starts redis in the background, turn on the security mechanism of protected-mode no # redis, and may report an error # requirepass 123456 # setting password, default comment status. Redis-server / usr/local/redis/redis.conf # specify configuration file to launch redis
Netstat-nltp | grep 6379 # check whether 6379 is listening. This port is the default port for redis.
Redis-cli # Log in to the client, enter a few values and view the following
Redis-cli shutdown # shut down the redis service
3.RDB persistence
RDB persistence is done through snapshotting. When certain conditions are met, redis will automatically generate a copy of all the data in memory in binary form and store it on the hard disk. When redis restarts and AOF persistence is not enabled, redis will read the binaries generated by RDB persistence (default name dump.rdb, which can be modified by setting dbfilename) for data recovery. For persistence information, you can use the command "info Persistence" to view.
Snapshot trigger condition
Snapshots generated by RDB can be prompted automatically or triggered manually using the command. The following is redis triggering the execution of snapshot conditions, each of which is described in detail later:
The client executes commands save and bgsave to generate snapshots; automatic snapshots are performed according to the configuration file save m n rules; when master-slave replication, the master database data is replicated in full from the slave database, and the master database executes bgsave commands for snapshots; when the client executes the database cleaning command FLUSHALL, the snapshot is triggered; when the client executes the shutdown shutdown redis, the snapshot is triggered The save command triggers and the shutdown triggers the client to execute the save command, which forces the redis to execute the snapshot. At this time, the redis is in a blocking state and will not respond to any requests from other clients until the RDB snapshot file is executed, so use it with caution. First, use redis-cli info Persistence to view the last persistence time:
# you can see that the data is a set of timestamps, which is not convenient to see. We can use AWK with date command to convert date "+% Y-%m-%d% H:%M:%S"-d @ `redis-cli info Persistence | awk-F ":" 'NR==5 {print$2}' `.
# you can see that after running the redis-cli save command, the last save time has changed
Shutdown trigger
# Note: save will be triggered only if it is closed normally. Direct kill cannot be triggered.
Bgsave command triggers
Immediately after the basave command is executed, it returns OK, and then Redis fork creates a new child process (during which the parent process does not respond to the request), the original Redis process (the parent process) continues to process the client request, while the child process is responsible for saving the data to disk and then exiting.
# usage is similar to that of save, but blocking time is much less than that of save
Save m n rule triggers this configuration. Default save 9001 # in the configuration file means one key has been modified within 900s. Triggering bgsavesave 30010 # means that 10 keys have been modified within 300 seconds. Triggering bgsavesave 60 10000 # means that 10000 keys have been modified within 60 seconds, triggering the relational OR above bgsave#. If one is satisfied, you can trigger bgsaveFLUSHALL trigger and master-slave trigger flushall commands to empty the database. Please use it with caution. When we use it, it indicates that we need to clear the data. Of course, redis also needs to clear the snapshot file, so bgsave will be triggered. In redis master-slave replication, the slave node performs a full copy operation, and the master node executes the bgsave command and sends the rdb file to the slave node. RDB persistence configuration-profile save m n # configure snapshot (rdb) promotion rules, format: save # save 900 at least one key is changed within 1,900 seconds, then take a snapshot # save 300 10300 seconds if at least 300 key is changed, take a snapshot # save 60 10000 take a snapshot if at least 10000 key is changed in 60 seconds # close this rule using svae "" dbfilename dump.rdb#rdb persistent storage database file name The default value of dump.rdbstop-write-on-bgsave-error yes # yes means to stop writing the RDB snapshot file when there is a persistence error using the bgsave command, and no indicates to ignore the error and continue to write the file. Whether rdbchecksum yes# opens the rdb file check when writing and reading files, checks for corruption, and stops startup if it is found to be corrupted during startup. Dir. / # data files are stored in the directory, and rdb snapshot files and aof files are stored in this directory. Make sure you have write permission. The default for compilation and installation is in the current directory. Whether rdbcompression yes# enables RDB file compression. This feature can save disk space and 4.AOF persistence.
AOF persistence is the same as Mysql's two-tier log writing principle, AOF can append every write command executed by Redis to the disk file (appendonly.aof), giving priority to restoring data from the AOF file when redis starts. Due to each write operation, redis will be recorded in the file, which has a certain impact on disk Imax O. Compared with RDB persistence, AOF persistent data (about 1 second of data) is lost less and consumes less memory (RDB execution of bgsve will have a memory copy).
Turn on AOF
# by default, redis disables AOF persistence and enables AOF by configuring appendonly to enable yes. We modify the configuration file or use config set directly on the command line to synchronize to the configuration file using config rewrite. The advantage of client-side modification is that it takes effect directly without restarting redis,AOF persistence.
AOF persistence process
The redisAOF persistence process can be divided into the following phases:
1. Append write
Redis adds each write command to the buffer aof_buf with redis communication protocol. The advantage is that in the case of a large number of write requests, a portion of the command is temporarily stored in the buffer and then written to the disk at one time according to the policy, which can reduce the number of disk ID O and improve performance.
two。 Synchronize commands to hard disk
When the write command is written to the aof_buf buffer, redis writes the command of the buffer to the file. Redis provides three synchronization policies, which are determined by the configuration parameter appendfsync. Here is the meaning of each policy:
▪ no: instead of using the fsync method to synchronize, it is handed over to the operating system write function to perform the synchronization operation, which is buffered about every 30 seconds in the linux operating system. In this case, the buffer data synchronization is uncontrollable, and under a large number of write operations, the accumulation of aof_buf buffers will become more and more serious. Once the redis fails, the data loss will be serious. ▪ always: means that every time a write operation occurs, the fsync method is called to force the kernel to write data to the aof file. In this case, because each write command is written to the file, although the data is relatively safe, but because each write operation will be synchronized to the AOF file, so there will be an impact on performance, and due to frequent IO operations, the service life of the hard disk will be reduced. ▪ everysec: the data is written to a file using the calling operating system write and flushed from the kernel to disk once a second using fsync. This is a compromise that takes into account both performance and data security, so redis recommends this configuration by default.
3. File rewriting (bgrewriteaof)
When AOF is turned on, the AOF file becomes larger and larger over time. Of course, redis also optimizes the AOF file, that is, when the AOF file rewriting condition is triggered (explained later), redis will use bgrewriteaof to rewrite the AOF file. This has the advantage of reducing the AOF file size and facilitating data recovery.
Why rewrite it? For example, when "set foo bar1 set foo bar2 set foo bar3" is executed successively, the AOF file will record three commands, which is obviously unreasonable, because only the last set value of "set foo bar3" should be retained in the file. The previous set commands are superfluous. Here are some rewrite strategies:
▪ duplicate or invalid commands do not write files ▪ expired data is no longer written to files ▪ multiple commands merge writes (when multiple commands can merge a command, they are optimized to be written as one command, for example, "RPUSH list1 a RPUSH list1 b" is merged into "RPUSH list1 a b") rewrite trigger conditions
AOF file trigger conditions can be divided into manual trigger and automatic trigger:
Manual trigger: the client executes the bgrewriteaof command.
Automatic trigger: automatic trigger takes effect through the cooperation of the following two configurations:
▪ auto-aof-rewrite-min-size: the minimum rewrite size of the AOF file, which can be overridden only if the AOF file size is greater than this value. 4. The default configuration is 64mb. ▪ auto-aof-rewrite-percentage: the ratio between the current AOF file size and the last overwritten size is equal to or equal to the specified percentage of growth, for example, 100 means that the current AOF file is twice as large as the last overwritten file.
When redis is enabled, when the AOF function is enabled, the following three variables are maintained
▪ records the variable aof_current_size of the current AOF file size. ▪ records the variable aof_rewrite_base_size of the AOF file size after the last AOF rewrite. ▪ growth percentage variable aof_rewrite_perc.
Each time the serverCron (server periodic operation function) function executes, it checks whether the following conditions are met, and if all of them are met, it triggers an automatic AOF rewrite operation:
▪ has no bgsave command (RDB persistence) / AOF persistence in execution; ▪ has no bgrewriteaofF in progress; ▪ current AOF file size is larger than the value of server.aof_rewrite_min_size The ratio between the current AOF file size of ▪ and the size after the last rewrite is equal to or greater than the specified percentage of growth (auto-aof-rewrite-percentage parameter) AOF configuration parameter-the minimum rewrite size of the configuration file auto-aof-rewrite-min-size 64mb#AOF file, which can be overridden only if the AOF file size is greater than this value. The ratio between the current AOF file size and the last overwritten AOF file size is equal to or equal to the specified percentage of growth, for example, 100 means that the current AOF file is twice as large as the last overwritten file. Appendfsync everysec#no: instead of using the fsync method to synchronize, it is handed over to the operating system write function to perform the synchronization operation, which is buffered about every 30 seconds in the linux operating system. In this case, buffer data synchronization is not controllable, and under a large number of write operations, the accumulation of aof_buf buffers will become more and more serious. Once redis fails, data # always: indicates that every write operation calls the fsync method to force the kernel to write data to the aof file. In this case, because each write command is written to the file, although the data is relatively safe, but because each write operation will be synchronized to the AOF file, so there will be an impact on performance, and due to frequent IO operations, the service life of the hard disk will be reduced. # everysec: the data is written to a file using the calling operating system write and flushed from the kernel to disk once a second using fsync. This is a compromise that takes into account both performance and data security, so redis recommends this configuration by default. Aof-load-truncated yes# when the redis suddenly crashes, the aof file is truncated. Redis can exit and load an error when this happens. The following options control this behavior. # if aof-load-truncated is set to yes, the truncated AOF file is loaded and the Redis server starts to issue a log to notify the user of the event. # if this option is set to no, the service will abort with an error and stop starting. When this option is set to no, the user needs to use the "redis-check-aof" utility to repair the AOF file before restarting. Appendonly no # yes enables AOF,no and closes AOFappendfilename appendonly.aof# to specify the AOF file name. 4 cannot be set through config set, only by modifying the configuration file settings. Dir. / # RDB file and AOF file storage directory
Two save file checks
Redis-check-aof appendonly.aof # AOFredis-check-rdb dump.rdb # RDB Thank you for your reading, the above is the content of "download and installation configuration of redis". After the study of this article, I believe you have a deeper understanding of the download and installation configuration of redis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.