How to install and configure Redis in CentOS7

How to install and configure Redis in CentOS7

Introduction

There is no need to introduce Redis in detail. Let's start installing and configuring it.

Install

  1. Download the source code wget http://download.redis.io/releases/redis-4.0.12.tar.gz ;
  2. Unzip and enter the directory tar xzf redis-4.0.12.tar.gz , cd redis-4.0.12/ ;
  3. Compile to the specified directory make PREFIX=/usr/local/redis install Create the /usr/local/redis/ect directory and copy redis.conf

The /usr/local/redis directory structure is as follows

Add Redis to the system service and execute vim /usr/lib/systemd/system/redis-server.service . The content is as follows

[Unit]
Description=The redis-server Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/var/run/redis.pid
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID

[Install]
WantedBy=multi-user.target

Start the service systemctl start redis-server

Set systemctl enable redis-server

Test, use redis-cli to test

Modify Redis configuration

  1. Modify the data storage path, create a new /usr/local/redis/data directory, and set dir to this path;
  2. RDB and AOF persistence

The default RDB is save 900 1 save 300 10 save 60 10000 , which means 1 change in 900 seconds, 10 changes in 300 seconds, and 10000 changes in 60 seconds. If any of the above conditions is met, the default value is used;

AOF is disabled by default, change appendonly to yes . There are three options for update conditions: always means manually calling fsync() to write data to disk after each update operation (slow, safe), everysec means syncing once a second (compromise, default value), and no means waiting for the operating system to synchronize data cache to disk (fast). Just use the default value.

The two can be used at the same time, and the other related configurations use the default values.

Modify the data elimination strategy

The maximum memory maxmemory is commented by default and is set to 512M. Note that the unit is bytes, so the value is 536870912;
Redis provides 6 data elimination strategies after exceeding the value, namely

volatile-lru: Select the data that has not been used the longest from the data set with an expiration time set to release;
allkeys-lru: select the data that has not been used for the longest time from the data set (including the data set with expiration time and the data set without expiration time) and release it;
volatile-random: Randomly select a data to release from the data set with an expiration time.
allkeys-random: randomly selects a data from the data set (including those with and without expiration time set) for release;
volatile-ttl: From the data set with an expiration time set, select the data that is about to expire and release it;
noeviction: Do not delete any data (but redis will release it according to the reference counter). If there is not enough memory, an error will be returned directly.

Here, maxmemory-policy is set to volatile-lru .

Keep the default values ​​for other configurations and modify them later as needed. Remember to restart the service after the modification is complete: systemctl restart redis-server

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Installation tutorial of the latest version of Redis 3.2.8 under Centos7
  • Detailed explanation of the process of installing redis 3.0.6 and configuring the cluster under CentOS 7
  • Detailed explanation of the installation and deployment of Redis on Centos7
  • Detailed installation of Redis database in CentOS 7 environment
  • How to install Redis on CentOS 7 (recommended)

<<:  Detailed explanation of the usage and differences between indexes and views in MySQL

>>:  How to implement the prototype pattern in JavaScript

Recommend

How to restore a single database or table in MySQL and possible pitfalls

Preface: The most commonly used MySQL logical bac...

Analysis of the solution to Nginx Session sharing problem

This article mainly introduces the solution to th...

Javascript uses the integrity attribute for security verification

Table of contents 1. Import files using script ta...

Implementation and usage scenarios of JS anti-shake throttling function

Table of contents 1. What is Function Anti-shake?...

Master-slave synchronization configuration of Mysql database

Table of contents Mysql master-slave synchronizat...

Detailed explanation of Vue development website SEO optimization method

Because the data binding mechanism of Vue and oth...

GDB debugging MySQL actual combat source code compilation and installation

Download source code git clone https://github.com...

Steps to set up Windows Server 2016 AD server (picture and text)

Introduction: AD is the abbreviation of Active Di...

Detailed example of using useState in react

useState useState adds some internal state to a c...

How to view Linux ssh service information and running status

There are many articles about ssh server configur...

How to remove spaces or specified characters in a string in Shell

There are many methods on the Internet that, alth...

Detailed explanation of Axios asynchronous communication in Vue

1. First, we create a .json file for interactive ...

How to add Lua module to Nginx

Install lua wget http://luajit.org/download/LuaJI...