Introduction to Redis Installation configuration

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 of wget http://redis.googlecode.com/files/redis-2.0.0-rc4.tar.gz

Ii. decompression of tar redis-2.0.0-rc4.tar.gz

C + + compiler components (not required) Apt-get install build-essential

Iv. Compiling 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: The Redis-server:redis server's daemon launcher Redis-cli:redis the command-line operations tool. Of course, you can also use Telnet to operate the Redis-benchmark:redis Performance test tool based on its plain text protocol, and test the read-write Performance Redis-stat:redis State Detection Tool Redis your system and your configuration. Can detect Redis current state parameters and latency 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 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, which indicates that the kernel will check that there is enough available memory to use the process, and that if there is sufficient memory available, the memory request is allowed, otherwise the memory request fails and the error is returned to the application process.
1, which means that the kernel allows all physical memory to be allocated regardless of the current state of memory.
2, which indicates that the kernel allows more memory to be allocated 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 to modify. The following is the meaning of the main configuration parameters of redis.conf: daemonize: Whether to run the Pidfile:pid file location in daemon mode port: Listener port Number timeout: Request Timeout Loglevel:log information level Logfile:log file Location Databases: Open the number of databases save * *: How often the snapshot is saved, the first * represents how long, and the third * indicates how many writes are 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 compressed dbfilename: Data Snapshot file name (just filename, excluding directory) dir: Save directory for Data snapshots (this is directory) appendonly: Open Appendonlylog, When opened, a log will be recorded for each write operation, which will increase the risk-resistant capability of the 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:

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:

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

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

1
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). & nbsp
Escape character is ' ^] '.  
Set foo 3 
bar 
+ok 
get foo 
$3 
Ba R&NBSP
^] 
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.