Home > Database > Redis > body text

How to install and configure Redis in CentOS7

WBOY
Release: 2023-05-29 08:53:16
forward
1547 people have browsed it

Installation

  1. Unzip and enter the directory tar xzf redis-4.0.12.tar.gzcd redis -4.0.12/

  2. Compile to the specified directory make prefix=/usr/local/redis installCreate /usr/local/ redis/ect directory, copy redis.conf to

How to install and configure Redis in CentOS7

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

How to install and configure Redis in CentOS7

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
Copy after login

Start the service systemctl start redis-server

How to install and configure Redis in CentOS7

Set to start at boot systemctl enable redis-server

Test, use redis-cli to test and see

How to install and configure Redis in CentOS7

Modify redis configuration

  1. Modify the data saving 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, that is, 1 change in 900 seconds, 300 10 changes per second, 10,000 changes in 60 seconds, if any of the above conditions are met, use the default value;

aof is turned off 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 synchronizing once per second (discounted) Medium, default value), no means waiting for the operating system to synchronize the data cache to the disk (fast), just use the default value;

Both can be used at the same time , other related configurations use default values.

Modify data elimination strategy

Maximum occupied memory maxmemory The default is commented and set to 512m. Note that the unit is bytes, so the value is 536870912 ;
redis provides a total of 6 data elimination strategies after overvaluation, which are

volatile-lru: From the data set with expiration time set, select the most recent and longest unused data to release;
allkeys-lru: From the data set (including data sets with expiration time set and data sets without expiration time set), select the most recently unused data for release;
volatile-random: Randomly select from the data set with expiration time set A piece of data is released;
allkeys-random: Randomly select a piece of data from the data set (including set expiration time and unset expiration time) for release;
volatile-ttl: From the data set with expiration time set , select the data that is about to expire for release operation;
noeviction: Do not delete any data (but redis will also release it based on the reference counter). At this time, if the memory is not enough, an error will be returned directly.

Set maxmemory-policy here to volatile-lru.

Other configurations remain at default values ​​and may be modified later as needed. Remember to restart the service systemctl restart redis-server after the modification is completed.

The above is the detailed content of How to install and configure Redis in CentOS7. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template