NoSQL Redis Simple installation and use

Source: Internet
Author: User
Tags redis redis server

Redis Basic Application Scenario:

Session sharing between Web, that is, multiple war projects share a session

Distributed cache, because Redis is a key-value pair storage, provides a rich adapter can support C,. NET, Java client, so the platform for data exchange played a role

So it can be used as a distributed cache for large-scale systems, and its setnx locks are often used for seconds to kill and to steal red envelopes in an e-commerce activity scenario

Download: redis:http://download.redis.io/releases/

Redis compiled installation

Tar XF redis-3.0.7.tar.gz

CD redis-3.0.7

Make

Make Prefix=/usr/local/redis Install

Mkdir-p/usr/local/redis/{data,etc,var}

To modify a configuration file:

Daemonize Yes: Daemon mode operation after station

Logfile/usr/local/redis/var/redis.log: Put the log in the Var directory you just created

Dir "/usr/local/redis/data": Where the data directory is stored

Save 900 1

#save 300 10

#save 60 10000

#redis以每900秒写一次, write 10 times in 300 seconds, write 10,000 times in 60 seconds This strategy puts the cache into a disk file called. Rdb

#如果按照默认的话, these three strategies take turns, and in a large concurrency environment,

#这样的写策略将会对我们的性能造成巨大的影响, so we only keep 900 seconds to write 1 times this strategy

AppendOnly No: The aof feature of Redis is turned off.


vim/etc/profile.d/redis.sh

Export path= $PATH:/usr/locl/redis/bin

. /etc/profile.d/redis.sh


redis.conf CP to the/USR/LOCAL/REDIS/ETC directory

Start Redis Service

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


Login client:

REDIS-CLI command

Redis-cli-p port-h IP

Redis-cli-p 6379-h 127.0.0.1


To close the Redis service command:

REDIS-CLI shutdown (-p can also specify ports)


The observation log found an error as follows:

Warning:the TCP Backlog setting of 511 cannot be enforced because/proc/sys/net/core/somaxconn are set to the lower value of 128.

WARNING Overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ' vm.overcommit_memory = 1 '

To/etc/sysctl.conf and then reboot or run the command ' Sysctl Vm.overcommit_memory=1 ' for the "take effect.

1. Echo 511 >/proc/sys/net/core/somaxconn

or Sysctl-w/proc/sys/net/core/somaxconn=511.

2, echo 1 >/proc/sys/vm.overcommit_memory

Sysctl-p


Overcommit_memory parameter Description: http://skly-java.iteye.com/blog/2167400

Optional values: 0, 1, 2.

0, indicates that the kernel will check for sufficient available memory to be used by the process, and if sufficient memory is 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 memory state.

2, which indicates that the kernel allows allocating more memory than the sum of all physical memory and swap space


Note: In the case of the dump data, Redis will fork out a sub-process, in theory the child process consumes the same memory as the parent, for example, the parent occupies 8G of memory,

This time also to allocate 8G of memory to child, if the memory can not afford, often cause the Redis server down or IO load is too high, inefficient.

So the more optimized memory allocation policy here should be set to 1 (indicating that the kernel allows all physical memory to be allocated regardless of the current memory state).


NoSQL Redis Simple installation and use

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.