How to install Redis in Linux

Source: Internet
Author: User
Tags password protection redis cluster install redis

How to install Redis in Linux

Redis overview and Comparison

Memcached is a high-performance distributed memory object Cache System for dynamic Web applications to reduce database load. It caches data and objects in the memory to reduce the number of reads to the database, thus improving the speed of dynamic and database-driven websites.

Redis is a key-value storage system. Similar to Memcached, Memcached supports more storage value types. The default connection port of the Redis server is 6379.

1. Redis and Memcache both store data in the memory and are memory databases. However, memcache can also be used to cache other

Things, examples, videos, etc.

2. Data Type-Memcache specifies the length of data bytes when adding data, for example:

Set key3 0 0 8

Lxsymcto

STORED

Redis does not need it, for example, redis 127.0.0.1: 6379> set key2 "lxsymblog"

OK

Redis 127.0.0.1: 6379> get key2

"Lxsymblog"

3. Virtual Memory-Redis can swap some unused values to the disk when the physical memory is used up

4. Expiration Policy-memcache is specified at set time. For example, set key1 0 0 8 never expires.

Redis can be set through expire, for example, expire name 10

5. Distributed-set the memcache cluster and use magent for one master and multiple slaves. redis can perform one master and multiple slaves. Both can be master-slave

6. Storage Data Security-after memcache is suspended, data is lost. redis can be regularly stored on disks (persistent)

7. Disaster Recovery-data cannot be recovered after memcache is suspended; after redis data is lost, data can be restored through aof.

8. Redis supports data backup, that is, data backup in master-slave mode.

Install

1 .:

Wget http://redis.googlecode.com/files/redis-2.6.13.tar.gz

2. Extract

Tar xzf redis-2.6.13.tar.gz

3. Compile

Cd redis-2.6.13

Make

Make install

Cp redis. conf/etc/

After the make install command is executed, an executable file is generated in the/usr/local/bin directory, they are redis-server, redis-cli, redis-benchmark, redis-check-aof, and redis-check-dump. Their functions are as follows:

Redis-server: daemon Startup Program of the Redis server

Redis-cli: Redis command line operation tool. You can also use telnet to operate based on its plain text protocol.

Redis-benchmark: Redis performance testing tool to test Redis's read/write performance in the current system

Redis-check-aof: data repair

Redis-check-dump: check the export tool

4. modify the system configuration file and execute the command

A) echo vm. overcommit_memory = 1>/etc/sysctl. conf

B) sysctl vm. overcommit_memory = 1 or execute echo vm. overcommit_memory = 1>/proc/sys/vm/overcommit_memory

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.

5. Modify the redis configuration file

A) cd/etc

B) vi redis. conf

C) Modify daemonize yes --- to make the process run in the background

6. Start redis

A) cd/usr/local/bin

B)./redis-server/etc/redis. conf

7. Check whether startup is successful

A) ps-ef | grep redis

Configuration File Parameters

1. Redis does not run as a daemon by default. You can modify this configuration item and use yes to enable the daemon.

Daemonize no

2. When Redis runs as a daemon, Redis writes the pid to the/var/run/redis. pid file by default, which can be specified through pidfile

Pidfile/var/run/redis. pid

3. specify the Redis listening port. The default port is 6379. The author explains in his blog why 6379 is used as the default port, because 6379 corresponds to the MERZ number on the mobile phone key, MERZ is taken from the name of Alessia Merz, an Italian singer.

Port 6379

4. Bound host address

Bind 127.0.0.1

5. When the client is idle for a long time, the connection is closed. If it is set to 0, the function is disabled.

Timeout 300

6. Specify the log record level. Redis supports four levels in total: debug, verbose, notice, and warning. The default value is verbose.

Loglevel verbose

7. log Record mode. The default value is standard output. If Redis is configured to run in daemon mode and the log record mode is set to standard output, the log will be sent to/dev/null.

Logfile stdout

8. Set the number of databases. The default database is 0. You can use the SELECT <dbid> command to specify the database id for the connection.

Databases 16

9. specify how many update operations are performed within the specified time period to synchronize data to the data file. Multiple conditions can be used together.

Save <seconds> <changes>

The default configuration file of Redis provides three conditions:

Save 900 1

Save 300 10

Save 60 10000

1 change in 900 seconds (15 minutes), 10 Changes in 300 seconds (5 minutes), and 10000 changes in 60 seconds.

10. Specify whether to compress data when stored in the local database. The default value is yes. Redis uses LZF to compress data. To save CPU time, disable this option, but this will cause huge changes in database files.

Rdbcompression yes

11. Specify the local database file name. The default value is dump. rdb.

Dbfilename dump. rdb

12. Specify the local database storage directory

Dir ./

13. Set the IP address and port of the master service when the local machine is slav service. When Redis is started, it will automatically synchronize data from the master.

Slaveof <masterip> <masterport>

14. When password protection is set for the master service, the slav service connects to the master password

Masterauth <master-password>

15. Set the Redis connection password. If the connection password is configured, the client must use the AUTH <password> command to provide the password when connecting to Redis. The password is disabled by default.

Requirepass foobared

16. Set the maximum number of client connections at the same time. By default, there is no limit. The number of client connections that Redis can open at the same time is the maximum number of file descriptors that Redis processes can open. If you set maxclients 0, no limit is imposed. When the number of client connections reaches the limit, Redis closes the new connection and returns the max number of clients reached error message to the client.

Maxclients 128

17. specify the maximum memory limit of apsaradb for Redis. Redis loads data into the memory at startup. After the maximum memory is reached, Redis first tries to clear the expired or expiring Key, after this method is processed, it still reaches the maximum memory setting, and no write operation can be performed, but the read operation can still be performed. Redis's new vm mechanism stores keys in memory, and values in the swap Area

Maxmemory <bytes>

18. specify whether to record logs after each update operation. Redis asynchronously writes data to the disk by default. If this parameter is not enabled, data may be lost for a period of time during power failure. Because redis synchronizes data files according to the save conditions above, some data will only exist in the memory for a period of time. The default value is no.

Appendonly no

19. Specify the Update log file name. The default value is appendonly. aof.

Appendfilename appendonly. aof

20. Specify the log update conditions. There are three optional values:

No: indicates that the data cache is synchronized to the disk by the operating system (FAST)

Always: indicates that data is written to a disk by manually calling fsync () after each update operation (slow and secure)

Everysec: Indicates synchronization once per second (compromise, default)

Appendfsync everysec

21. specifies whether to enable the virtual memory mechanism. The default value is no. For a brief introduction, the VM mechanism stores data on pages, and Redis stores cold data on the disk, that is, pages with less traffic, multiple accessed pages are automatically swapped out from the disk to the memory (I will carefully analyze the VM mechanism of Redis in the following article)

Vm-enabled no

22. virtual memory file path. The default value is/tmp/redis. swap. It cannot be shared by multiple Redis instances.

Vm-swap-file/tmp/redis. swap

23. store all data greater than vm-max-memory into the virtual memory. No matter how small the vm-max-memory settings are, all index data is stored in the memory (Redis's index data is keys ), that is to say, when vm-max-memory is set to 0, all values exist on the disk. The default value is 0.

Vm-max-memory 0

24. redis swap files are divided into many pages. One object can be stored on multiple pages, but one page cannot be shared by multiple objects, vm-page-size is set based on the size of stored data. The author suggests that if many small objects are stored, the page size should be set to 32 or 64 bytes. If a large object is stored, you can use a larger page. If you are not sure, use the default value.

Vm-page-size 32

25. set the number of pages in the swap file. Because the page table (a bitmap indicating that the page is idle or used) is in the memory, every 8 pages on the disk consumes 1 byte of memory.

Vm-pages 134217728

26. set the number of threads used to access the swap file. It is best not to exceed the number of server cores. If it is set to 0, all operations on the swap file are serial, which may cause a long delay. The default value is 4.

Vm-max-threads 4

27. Set whether to combine a small package into a package for sending when responding to the client. The function is enabled by default.

Glueoutputbuf yes

28. When a specified number or maximum element exceeds a critical value, a special hash algorithm is used.

Hash-max-zipmap-entries 64

Hash-max-zipmap-value 512

29. Specify whether to enable or disable hash resetting. The default setting is enable (this will be detailed later when we introduce the hash algorithm of Redis)

Activerehashing yes

30. Specify other configuration files. You can use the same configuration file between multiple Redis instances on the same host, and each instance has its own specific configuration file.

Include/path/to/local. conf

You may also like the following articles about Redis. For details, refer:

Install and test Redis in Ubuntu 14.04

Basic configuration of Redis master-slave Replication

Redis cluster details

Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis

Redis series-installation, deployment, and maintenance

Install Redis in CentOS 6.3

Learning notes on Redis installation and deployment

Redis. conf

Redis details: click here
Redis: click here

This article permanently updates the link address:

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.