Home> Database> Redis> body text

How to install and configure Redis in CentOS7

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

Installation

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

  2. Compile to the specified directorymake prefix=/usr/local/redis installCreate/usr/local/ redis/ectdirectory, copyredis.confto

How to install and configure Redis in CentOS7

/usr/local/redisThe directory structure is as follows

How to install and configure Redis in CentOS7

Add redis to the system service and executevim /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 servicesystemctl start redis-server

How to install and configure Redis in CentOS7

Set to start at bootsystemctl enable redis-server

Test, useredis-clito 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/datadirectory, and setdirto this path;

  2. rdb and aof persistence

The default rdb issave 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, changeappendonlytoyes. There are three options for update conditions.alwaysmeans manually calling fsync() to write data to disk after each update operation (slow, safe),everysecmeans synchronizing once per second (discounted) Medium, default value),nomeans 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 memorymaxmemoryThe 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.

Setmaxmemory-policyhere tovolatile-lru.

Other configurations remain at default values and may be modified later as needed. Remember to restart the servicesystemctl restart redis-serverafter 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!