Redis Installation and Configuration Tutorial

  

Redis is an advanced key-value database. It is similar to memcached, but the data can be persisted and the supported data types are very rich. There are strings, linked lists, collections, and ordered collections. Supports the calculation of sets, intersections, and digests on the server side. It also supports multiple sorting functions. So Redis can also be seen as a data structure server.

Redis all data is stored in memory, and then saved to disk asynchronously (this is called "semi-persistent mode"); you can also change every data change Write to an append only file(aof) (this is called “full persistence mode”).

First, download the latest version

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

Two solutions Compressed

tar redis-2.0.0-rc4.tar.gz

Three, install C /C + + compiler components (not required)

apt-get install build- Essential

Four, compile

cd redis-2.0.0-rc4make

After the execution of the make command is completed, the executable file will be generated in the current directory, respectively Redis-server, redis-cli, redis-benchmark, redis-stat, their role is as follows:

redis-server: Redis server daemon startup program redis-cli: Redis command line operation tool. Of course, you can also use telnet to operate redis-benchmark according to its plain text protocol: Redis performance test tool, test Redis read and write performance of your system and your configuration redis-stat: Redis state detection tool, can detect Redis Current status parameters and delay status

V. Modify configuration file

/etc/sysctl.confvm.overcommit_memory=1sysctl vm.overcommit_memory=1

**If memory comparison If you are nervous, you need to set the kernel parameters: echo 1 > /proc/sys/vm/overcommit_memory

The kernel parameters are as follows:

The overcommit_memory file specifies the kernel's strategy for memory allocation. The value can be 0, 1, 2. 0, indicating that the kernel will check if there is enough available memory available for the process; if there is enough available memory, the memory request allows; otherwise, the memory request fails and the error is returned to the application process . 1, indicating that the kernel allows all physical memory to be allocated, regardless of the current memory state. 2, indicates that the kernel allows allocation of memory that exceeds the sum of all physical memory and swap space.

**Edit the redis.conf configuration file (/etc/redis.conf) and make appropriate adjustments as needed, for example: daemonize yes #转为为 daemon, otherwise it will output a line of monitoring information every 5 seconds at startup. save 60 1000 #Reduce the number of changes, in fact, this can be specified according to the situation maxmemory 256000000 # allocate 256M memory

After we successfully installed After Redis, we can run Redis directly on redis-server, and it runs according to the 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. The Redis configuration file is the redis.conf file of our second cp operation. It is currently copied to the /usr/local/redis/etc/directory. under. Modify it to configure our server. How to amend? The following is the meaning of the main configuration parameters of redis.conf:

daemonize: whether to run pidfile in the background daemon mode: pid file location port: listening port number timeout: request timeout time loglevel: log information level logfile: log File location databases: The number of open databases save * *: The frequency of saving snapshots, the first * indicates how long, and the third * indicates how many writes are performed. The snapshot is automatically saved when a certain number of write operations are performed within a certain period of time. Multiple conditions can be set. Rdbcompression: whether to use compressed dbfilename: data snapshot file name (just file name, excluding directory) dir: data snapshot storage directory (this is the directory) appendonly: whether to open appendonlylog, open, then write a log every time you write Will improve the ability of data to resist risks, but affect efficiency. Appendfsync: how appendonlylog is synchronized to disk (three options are to force fsync to be called for each write, fsync every second, or fsync to wait for the system to synchronize itself)

Copyright © Windows knowledge All Rights Reserved