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

A brief summary of basic web page performance optimization rules

Some optimization rules for browser web pages Pag...

Vue implements div wheel zooming in and out

Implement div wheel zooming in and out in Vue pro...

Detailed explanation of props and context parameters of SetUp function in Vue3

1. The first parameter props of the setUp functio...

MySQL uses init-connect to increase the implementation of access audit function

The mysql connection must first be initialized th...

React uses routing to redirect to the login interface

In the previous article, after configuring the we...

Tips on MySQL query cache

Table of contents Preface Introduction to QueryCa...

Solution to the problem that Docker cannot stop or delete container services

Preface Today, a developer gave me feedback that ...

js implements custom drop-down box

This article example shares the specific code of ...

Detailed explanation of JavaScript's built-in objects Math and strings

Table of contents Math Objects Common properties ...

MySQL Query Cache and Buffer Pool

1. Caches - Query Cache The following figure is p...

Best Practices for Deploying ELK7.3.0 Log Collection Service with Docker

Write at the beginning This article only covers E...