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)
Redis installation in Linux under the detailed