Install redis in Linux

Source: Internet
Author: User
Tags download redis install redis

As an application of nosql databases, redis is highly efficient in terms of response speed and hit rate. The project needs to use a centralized horizontally Scalable Cache framework, do a little research, even redis, memcached there are efficiency differences (for more information, refer to the http://timyang.net/data/mcdb-tt-redis ), but in fact, it can meet the needs of the current project. However, redis is still cool. It supports linked list and set operations and regular expressions to search for keys. Currently, most of the results cached by the project are linked lists, if the linked list adds or modifies data, redis will have a great advantage (memcached can only reload the linked list, and redis can add or modify the Linked List)

1: Download redis
Http://code.google.com/p/redis/downloads/list
We recommend that you download redis-1.2.6.tar.gz. the previous example has already experienced successful installation and operation. redis-2.0.4.tar.gz cannot be used to cache data after installation.

2: Install redis
Unzip the tar zxvf redis-1.2.6.tar.gz to any directory, such as/usr/local/redis-1.2.6

Decompress the package and go to the redis directory.
CD/usr/local/redis-1.2.6
Make

Copy an object
Configuration File started by redis when CP redis. CONF/etc/is used
CP redis-benchmark redis-cli redis-server/usr/bin/# is very useful, so you do not need to add./during execution, and you can execute it anywhere.

Set the Memory Allocation Policy (optional, based on the actual situation of the server)
/Proc/sys/Vm/overcommit_memory
Optional values: 0, 1, and 2.
0 indicates that the kernel will check whether there is enough available memory for use by the process. If there is enough available memory, the memory application will be allowed; otherwise, the memory application will fail, and return the error to the application process.
1 indicates that the kernel allows all physical memory allocation regardless of the current memory status.
2. indicates that the kernel is allowed to allocate more memory than the total physical memory and swap space.

It is worth noting that redis will fork a sub-process when dumping data. In theory, the memory occupied by the child process is the same as that of the parent process, for example, if the memory occupied by parent is 8 GB, 8 GB of memory should be allocated to the child at the same time. If the memory is not sufficient, it will usually cause the redis server to go down or the IO load is too high, reduced efficiency. Therefore, the optimized memory allocation policy should be set
1 (indicates that the kernel allows allocation of all physical memory, regardless of the current memory status)

Enable the redis port and modify the firewall configuration file
VI/etc/sysconfig/iptables

Add port configuration
-A RH-Firewall-1-INPUT-M state -- state new-m tcp-p tcp -- dport 6379-J accept

Reload rules
Service iptables restart

3: Start the redis Service
[Root @ effecect redis-1.2.6] # pwd
/Usr/local/redis-1.2.6
[Root @ effecect redis-1.2.6] # redis-server/etc/redis. conf

Check the process and confirm that redis has been started.

[Root @ revoke ect redis-1.2.6] # ps-Ef | grep redis
Root 401 29222 0 00:00:00 pts/3 grep redis
Root 29258 1 0? 00:00:00 redis-server/etc/redis. conf

If the redis service fails to be started here, it is generally because of redis. if there is a problem with the conf file, we recommend that you check or find an available configuration file to overwrite it to avoid detours. Here we recommend that you modify redis. conf, set the redis process as the background daemon

# By default redis does not run as a daemon. Use 'yes' if you need it.
# Note that redis will write a PID file in/var/run/redis. PID when daemonized.
Daemonize Yes

4: Test redis
[Root @ ect redis-1.2.6] # redis-cli
Redis> Set Name songbin
OK
Redis> get name
"Songbin"

5. Disable the redis service.
Redis-cli Shutdown

When the redis service is disabled, the cached data is automatically dumped to the hard disk. The hard disk address is set by dbfilename dump. RDB, the configuration item in redis. conf.
Use the following command to forcibly back up data to a disk:

Redis-cli save or redis-cli-P 6380 save (specified port)

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.