Writing in the front

In this tutorial you will learn how to install Redis nanny level from 0 to 1Copy the code

Install the GCC compiler

 yum install -y gcc    
Copy the code

Download the Redis installation package and unzip it

Wget http://download.redis.io/releases/redis-5.0.3.tar.gz tar - ZXVF redis - 5.0.3. Tar. GzCopy the code

Compiling Redis

1 // Go to the decompressed directory redis-5.0.3cd redis-5.0.32 Run the make command to compile makeCopy the code

Install Redis and specify the installation directory

make install PREFIX=/usr/local/redis
Copy the code

Go to the /usr/local/redis/bin directory and copy the configuration file redis. conf to this directory

CD /usr/local/redis/bin/cp /usr/local/redis-5.0.3/redis.conf /usr/local/redis/bin/Copy the code

Run the start command to start Redis

./redis-server redis.conf 
Copy the code

Configuration file details

What is the Redis configuration file redis.conf used for? Here is the explanation in the form of question and answer: 1. How to start the background of Redis? vi redis.conf daemonize yesCopy the code

2. How to enable Redis to support remote connection, that is, the Redis tool can connect to the host address of the service vi Redis. 127.0.0.1 indicates that only native access to bind 0.0.0.0 is allowedCopy the code

3. How to configure the Redis startup port vi RedisCopy the code

Vi Redis. Conf // Note that there is no password by default. Requirepass testDemo is annotatedCopy the code

5 configuration file modification restart Redis to see the effect // background boot // boot port changed to 6479 // connection tools, password verificationCopy the code

Appendix -Redis common configuration

Daemonize yes // Set background startup, Pid // When edis runs in daemon mode,redis writes pid to /var/run/redis. Pid by default. Port 6379 // The default port is 6379 bind 127.0.0.1 // Host address. If 0.0.0.0 is not set, all hosts can be accessed. 127.0.0.1 indicates that only local access is allowed. Timeout 900 // How long is the client idle before the connection is closed? If the value is 0, the function is disabled. Logfile "./redis7001.log" # databases 1, 2, 3, 1 The default Redis profile provides three conditions for synchronizing data to a data file: Save 900 1 //900 seconds (15 minutes) 1 change save 300 10 //300 seconds (5 minutes) 10 changes Save 60 10000 // 60 seconds 10000 changes rDBCompression yes // Dbfilename dump. RDB // specify the local database filename dir./ // specify the local database directory slaveof // set the primary database IP address and port. 60 # By default, if RDB snapshot is enabled (at least one save command) and the latest background save fails, Redis will stop accepting writes # this will let the user know that data has not been persisted to disk correctly, Stop-write-on-bgsave-error yes # Default Redis will stop accepting writes if RDB snapshot is enabled (at least one save command) and the latest background save fails. Stop-writes-on-bgsave-error yes # Whether to use LZF to compress string objects when exporting to the.rdb database RDBCompression Yes # Version 5 of RDB has a checksum for the CRC64 algorithm placed at the end of the file. This will make the file format more reliable. RDB # working directory dir /usr/local/redis-4.0.8/redis_master/ # Masterauth TestMaster123 # When a slave loses its connection to the master, or synchronization is in progress, the slave can act in one of two ways: #1) If slave-serve-stale-data is set to "yes" (the default), slave will continue to respond to client requests for normal data, stale data, or empty data that has not yet received a value. # 2) If slave-serve-stale-data is set to "no", the slave will reply "synchronizing with master in progress" to handle various requests. Except for INFO and SLAVEOF commands. Slave-serve-stale-data yes # Configure whether to read slave-only yes # If you select yes Redis will use less TCP packets and bandwidth to send data to Slaves. But this will delay the transmission of data to the slave, The default configuration of the Linux kernel is 40 milliseconds # If you select "no" the delay of data transfer to salve will be reduced but more bandwidth will be used repl-disable-tcp-nodelay no # slave priority, 100 # Password verification requirepass TestMaster123 # Redis Maximum memory usage. Once the memory usage reaches the upper limit, Redis will delete the key based on the selected reclamation policy (see: # maxMemory -policy) maxMemory 3GB # Maximum memory policy: How Redis chooses to delete the key if the memory limit is reached. # volatile- lRU -> Delete key with expiration time based on LRU algorithm. # allkeys-lRU -> Delete any keys according to the LRU algorithm. # volatile-random -> Delete keys randomly based on expiration Settings. # allkeys->random ->random delete any key. # volatile- TTL -> Delete based on last expiry time (supported by TTL), key # noeviction -> will be designed for write operations when errors are returned. Appendonly no # appendFilename "appendonly. AOF "# fsync() The system call tells the operating system to write data to disk instead of waiting for more data to enter the output buffer. Some operating systems actually flush data to disk immediately; Others will try to do so as soon as possible. # Redis supports three different modes: # No: Don't swipe right away, only swipe when the operating system needs to swipe. Faster. Always: Every write operation is written immediately to the AOF file. Slow, but safest. # everysec: Write once per second. A compromise. Appendfsync everysec # If the AOF synchronization policy is set to "always" or "everysec" and the background storage process (the background stores or writes to the AOF # log) will incur a lot of disk I/O overhead. Some Linux configurations cause Redis to block for a long time due to fsync() system calls. # Note that there is no perfect fix for this, and even fsync() from different threads will block our synchronized write(2) calls. # To alleviate this problem, use the following option. It can prevent the main process from fsync() during BGSAVE or BGREWRITEAOF processing. # This means that Redis is "out of sync" if a child is saving. In the worst case, 30 seconds of log data may be lost. (Default Linux setting) # Set this to "yes" if you have latency issues, otherwise leave "no", this is the safest way to save persistent data. No -appendfsync-on-rewrite yes # auto- AOF -rewrite-percentage 100 auto- AOF -rewrite-min-size 64mb # AOF files may be incomplete at the end (this has problems with system shutdown, especially when mounting ext4 filesystems without the data=ordered option). Will only happen when OS dies, redis will not die incomplete). There is a problem with load loading when redis restarts. When an error occurs, you can choose to start redis and notify the user and log, or load as much normal data as possible. # If aof-load-truncated is yes, a log is automatically published to the client and then loaded (default). If it is no, the user must manually repair the aOF file by redis-check-aof. This option is only used when the server tries to read more data and cannot find it. Aof-load-truncated yes # Maximum execution time of Lua script, Slowlog-log-slower than 10000 # There is no limit for this length. It's just that it mostly consumes memory. You can recycle memory by SLOWLOG RESET. Slowlog-max-len 128 # limit of client output buffer, Client -output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 60 # When a child process overwrites an AOF file, it synchronizes AOF -rewrite-incremental-fsync yes for every 32M of data generated by the fileCopy the code