Install and configure Redis in CentOS

Source: Internet
Author: User
Redis is short for REmoteDIctionaryServer. Is an open-source key-value non-relational database written in C. Similar to memcached, but data can be persistent. All Redis data is stored in the memory and occasionally stored to the disk asynchronously (called & ldquo; semi-persistent mode & rdquo ;); you can also write every data change to an appendonlyfile (

Redis is short for REmote DIctionary Server. Is an open-source key-value non-relational database written in C. Similar to memcached, but data can be persistent.

All Redis data is stored in the memory and then asynchronously stored to the disk (called "semi-persistent mode "); you can also write every data change to an append only file (aof) (called "full persistence mode ").

To successfully use a product, we need to have a deep understanding of its features.

Directory
  • 1 installation
  • 2 configuration
  • 3. run
  • 4 Close
  • 5 Yi search reference
Install

Download source code: http://dl.vmall.com/c0a0ysmx5f

$ tar xzf redis-2.8.8.tar.gz$ cd redis-2.8.8$ make

After the make command is executed, five executable files are generated in the src directory, they are redis-server, redis-cli, redis-benchmark, redis-check-aof, and redis-check-dump. Their functions are as follows:

  • Redis-server: daemon startup program of the Redis server
  • Redis-cli: Redis command line operation tool. Of course, you can also use telnet to operate based on its plain text protocol.
  • Redis-benchmark: Redis performance testing tool to test the read/write performance of Redis in your system and your configuration
  • Redis-check-aof: update log check
  • Redis-check-dump: used for local database check

Install

make PREFIX=/usr/local install
Configuration

The redis configuration file is in your installation directory. Name: redis. conf

mkdir /etc/rediscp redis.conf /etc/redis/redis.conf
  • Redis does not use daemonize by default. if you need to change daemonize no to daemonize yes.
  • If you are not comfortable with redis's default port 6379, you can change port 6379.
  • If you want to put the data file in a specified folder, change dir/var/lib/redis/(you need to create it first) (the default value is dir./, that is, put it in the installation directory by default .)
  • How many seconds after the client is idle, disconnect
timeout 300
  • Either of the following configurations

1. snapshow.memory snapshot method (Save the DB on disk) save **: the snapshot retention frequency. the first * indicates the time duration, and the third * indicates the number of write operations performed. Snapshots are automatically saved when a certain number of write operations are performed within a certain period of time. You can set multiple conditions.

# When A Keys data item is changed, refresh it to disk in 900 seconds. save 900 1 # When 10 Keys data items are changed, refresh to disk in 300 seconds save 300 10 # when 1 million pieces of keys data are changed, refresh to disk in 60 seconds save 60 10000

II. append only mode (aof mode) appendfsync everysec synchronization per second. You can comment it out and open the option appendfsync no below it.

Whether or not to record logs after each update operation. if not enabled, data may be lost for a period of time during power failure. Because redis synchronizes data files according to the save conditions above, some data will only exist in the memory for a period of time. The default value is no.

appendonly no

Redis can be stored in two ways. the default mode is snapshot. the implementation method is to regularly save the snapshot of the memory to the hard disk, the disadvantage of this method is that if a crash occurs after persistence, a piece of data will be lost. Therefore, driven by the perfectionist, the author adds the aof method. Aof is append only mode. when writing memory data, the operation command is saved to the log file.

In fact, aof mainly aims at data reliability and high availability. there is another way in Redis to achieve this goal: Replication. Because of Redis's high performance, there is basically no replication latency. This prevents SPOF and achieves high availability.

Run
redis-server /etc/redis/redis.conf

You can start the redis service. after you confirm that it is running, you can use the redis-benchmark command to test it. you can also use the redis-cli command to perform actual operations, for example:

redis-cli set foo barOKredis-cli get foo“bar”
Close
redis-cli shutdown

Because redis writes data to the disk asynchronously, if you want to write data in the memory to the hard disk immediately, run the following command:

redis-cli save
Yi search reference

Http://www.cnblogs.com/hb_cattle/archive/2011/10/22/2220907.html

Http://www.cnblogs.com/zhuhongbao/archive/2013/06/04/3117997.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.