Redis database Installation and configuration method _redis

Source: Internet
Author: User
Tags benchmark memcached redis install redis redis server

Redis is a high-performance key-value database. The emergence of Redis, to a large extent, compensates for the shortage of such keyvalue storage in memcached, and in some cases can complement the relational database well. It provides a python,ruby,erlang,php client and is easy to use. The problem is that the project is still new, may not be stable enough, and there are no examples of actual applications in some large systems. In addition, the lack of MC in bulk get is also a big problem, always bulk acquisition and multiple access to the network overhead is not the same.

Performance Test Results:

Set operation 110,000 times per second, get operation 81,000 times per second, server configuration is as follows:

Linux 2.6, Xeon X3320 2.5Ghz.

The StackOverflow Web site uses Redis as a caching server.

Installation process:

Redis is an advanced Key-value database. It's similar to memcached, but data can be persisted and supported with rich data types. There are strings, lists, sets, and ordered collections. Support for computing collections on the server side, difference, and so on, also supports a variety of sorting functions. So Redis can also be viewed as a data structure server.

All the data in Redis is stored in memory, it is then periodically saved to disk asynchronously (this is called a "semi-persistent mode"), or it can be written to a append only file (AOF) (this is called "Total persistence mode") for each data change.

First, download the latest version

wget http://redis.googlecode.com/files/redis-2.0.0-rc4.tar.gz

Second, decompression

Tar redis-2.0.0-rc4.tar.gz

C + + Compile components installed (not required)

Apt-get Install Build-essential

Four, compile

CD REDIS-2.0.0-RC4
Make

When the make command completes, the executable file is generated in the current directory, Redis-server, REDIS-CLI, Redis-benchmark, redis-stat, and they function as follows:

Daemon startup program for Redis-server:redis server
Redis-cli:redis Command line Operation tool. Of course, you can also use Telnet to operate on its plain text protocol.
Redis-benchmark:redis Performance Testing tool to test Redis performance in your system and your configuration
Redis-stat:redis State Detection Tool, can detect Redis current state parameters and delay status
In the following will be a description of these commands, of course, copied from the internet ...

V. Modify the configuration file

/etc/sysctl.conf
Add to

Vm.overcommit_memory=1
Refreshing the configuration to take effect

Sysctl Vm.overcommit_memory=1

Supplementary Introduction:

* * If the memory situation is more stressful, you need to set kernel parameters:
Echo 1 >/proc/sys/vm/overcommit_memory

The kernel parameters are described below:

The Overcommit_memory file specifies the kernel's policy for memory allocation, which can be 0, 1, and 2.
0 indicates that the kernel will check if there is enough available memory to use the process, and if there is enough memory available, the memory request is allowed, otherwise the memory request fails and the error is returned to the application process.
1 indicates that the kernel allows all physical memory to be allocated regardless of the current state of memory.
2, which indicates that the kernel allows to allocate more memory than the sum of all physical memory and swap space

* * Edit the redis.conf configuration file (/etc/redis.conf) and make appropriate adjustments as required, such as:
Daemonize Yes #转为守护进程, otherwise one line of monitoring information is output every 5 seconds at startup
Save 1000 #减小改变次数, in fact, this can be specified according to the situation
MaxMemory 256000000 #分配256M内存


After we successfully install Redis, we can run the Redis directly by executing Redis-server, which is run by default configuration (the default configuration is not even running in the background). We want Redis to run according to our requirements, then we need to modify the configuration file, Redis configuration file is our second CP operation of the redis.conf file, currently it is we copy to the/usr/local/redis/etc/directory. Modify it to configure our server. How do I modify it? The following are the meaning of the main configuration parameters of redis.conf:
Daemonize: Whether to run after the daemon mode
Pidfile:pid File Location
Port: The port number listening
Timeout: Request Timeout time
Loglevel:log Information level
Logfile:log File Location
Databases: number of databases Open
Save * *: How often the snapshot is saved, how long the first * represents, and the third * indicates how many writes have been performed. Automatically saves snapshots when a certain number of writes are performed within a certain amount of time. Multiple conditions can be set.
Rdbcompression: Whether to use compression
Dbfilename: Data Snapshot file name (just filename, excluding directory)
Dir: Save directory for Data snapshots (this is a directory)
AppendOnly: Whether to turn on the Appendonlylog, open the word every write will remember a log, which will improve the risk-resistant ability of data, but affect efficiency.
Appendfsync:appendonlylog How to sync to disk (three options, each write is forced to call Fsync, enable once per second Fsync, do not call Fsync wait for the system to sync itself)

The following is a slightly modified configuration file content:

Copy Code code as follows:

Daemonize Yes
Pidfile/usr/local/redis/var/redis.pid
Port 6379
Timeout 300
LogLevel Debug
Logfile/usr/local/redis/var/redis.log
Databases 16
Save 900 1
Save 300 10
Save 60 10000
Rdbcompression Yes
Dbfilename Dump.rdb
dir/usr/local/redis/var/
AppendOnly No
Appendfsync always
Glueoutputbuf Yes
Shareobjects No
Shareobjectspoolsize 1024

Write the above content as redis.conf and save it to the/usr/local/redis/etc/directory

Then execute at the command line:

/usr/local/redis/bin/redis-server/usr/local/redis/etc/redis.conf

You can start the Redis service in the background when you pass

Telnet 127.0.0.1 6379

You can connect to your Redis service.

Six, start the service and verify

Start the server

./redis-server
Or
$redis-server/etc/redis.conf
To see if it started successfully
$ PS-EF | grep Redis
Or
./redis-cli Ping
PONG

Vii. Start command line client assignment value

REDIS-CLI Set MyKey somevalue
./REDIS-CLI Get MyKey

Viii. Closing Services

$ redis-cli Shutdown
#关闭指定端口的redis-server
$redis-cli-p 6380 shutdown

The client can also use Telnet form to connect.

[Root@dbcache conf]# telnet 127.0.0.1 6379
Trying 127.0.0.1 ...
Connected to Dbcache (127.0.0.1).
Escape character is ' ^] '.
Set Foo 3
Bar
+ok
Get foo
$
Bar
^]
Telnet> quit
Connection closed.

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.