Installation
Unzip and enter the directorytar xzf redis-4.0.12.tar.gz
、cd redis -4.0.12/
;
Compile to the specified directorymake prefix=/usr/local/redis install
Create/usr/local/ redis/ect
directory, copyredis.conf
to
/usr/local/redis
The directory structure is as follows
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
Start the servicesystemctl start redis-server
Set to start at bootsystemctl enable redis-server
Test, useredis-cli
to test and see
Modify redis configuration
Modify the data saving path, create a new/usr/local/redis/data
directory, and setdir
to this path;
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, changeappendonly
toyes
. 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 memorymaxmemory
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.
Setmaxmemory-policy
here tovolatile-lru
.
Other configurations remain at default values and may be modified later as needed. Remember to restart the servicesystemctl 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!