As an application of NoSQL databases, Redis is still more efficient in response speed and hit rate. The project requires a centralized, scale-out caching framework that does a bit of research, even if there is a difference in efficiency between Redis and memcached (specifically compared to reference http://timyang.net/data/mcdb-tt-redis/), But in fact can meet the current project needs, but Redis is still more coquettish, support linked list and set operations, support regular Expression lookup key, the current project cache results are mostly linked list, if the list of new or modified data, Redis is a great advantage (memcached can only reload the linked list, and Redis may add or modify the linked list)
1: Download Redis
Http://code.google.com/p/redis/downloads/list
Recommended download redis-1.2.6.tar.gz, before this version of the colleague has been successful installation run experience, redis-2.0.4.tar.gz This version I can not operate cached data after installation, the specific reasons for further
2: Installing Redis
Download and unzip the tar zxvf redis-1.2.6.tar.gz to any directory, such as/usr/local/redis-1.2.6
After unpacking, enter the Redis directory
cd/usr/local/redis-1.2.6
Make
Copy files
CP redis.conf/etc/This file when Redis-initiated configuration file
The CP Redis-benchmark REDIS-CLI redis-server/usr/bin/is #这个倒是很有用 so that it does not have to be executed when added.
Set the memory allocation policy (optional, set according to the actual situation of the server)
/proc/sys/vm/overcommit_memory
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
It is worth noting that Redis in the dump data, will fork out a sub-process, in theory the child process occupies the same memory and the parent is the same, such as the parent occupies 8G of memory, this time also to allocate 8G of memory to Child, If the memory is not affordable, it will 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)
Turn on the Redis port and modify the firewall configuration file
Vi/etc/sysconfig/iptables
Join Port Configuration
-A rh-firewall-1-input-m state--state new-m tcp-p TCP--dport 6379-j ACCEPT
Reload Rule
Service Iptables Restart
3: Start Redis service
[Email protected] redis-1.2.6]# pwd
/usr/local/redis-1.2.6
[Email protected] redis-1.2.6]# redis-server/etc/redis.conf
Review the process and confirm that Redis is started
[Email protected] redis-1.2.6]# Ps-ef | grep Redis
Root 401 29222 0 18:06 pts/3 00:00:00 grep redis
Root 29258 1 0 16:23? 00:00:00 redis-server/etc/redis.conf
If the Redis service fails to start here, generally because of a problem with the redis.conf file, it is recommended to check or find an available profile to cover, avoid less detours, here is recommended, modify redis.conf, set up the Redis process for the daemon process
# By default, Redis does not run as a daemon. Use the ' yes ' if you need it.
# Note that Redis would write a PID file in/var/run/redis.pid when daemonized.
Daemonize Yes
4: Test Redis
[Email protected] redis-1.2.6]# REDIS-CLI
Redis> Set name Songbin
Ok
Redis> Get Name
"Songbin"
5: Turn off Redis service
REDIS-CLI shutdown
After the Redis service is turned off, the cached data is automatically dump to the hard disk, and the hard disk address is the configuration item in redis.conf dbfilename Dump.rdb is set
To force backup data to disk, use the following command
Redis-cli Save or Redis-cli-p 6380 Save (Specify port)
Linux installation Redis