Configuring Redis services under Linux installation

Source: Internet
Author: User
Tags install redis

The recent project needs to use the Redis cache and clustering technology, so in the spare time to study a piece of work, in fact, on-line Redis installation configuration of the article there are many, but the total feeling is not very complete, easy to make people dizzy,

So oneself in after the actual combat, also want to write a more complete, the reader according to the article to carry out the article does not make mistakes, the following is just a simple single-instance installation configuration instructions, cluster deployment to the next article.

The installation configuration steps for Redis are as follows:

Part I: Installation start

1, to the Redis official website to download the corresponding Redis installation package, considering the stability, I choose to be 2.8.24 version, Address: http://download.redis.io/releases/redis-2.8.24.tar.gz.

2, download completed, to the source package directory, using the command tar-zxvf redis-2.8.24.tar.gz-c/opt/Decompression installation package, the author extracted to the OPT directory.

3, compile the source code and install Redis: into the extracted Redis directory (the author here is/opt/redis-2.8.24), use the command make Prefix=/usr/local/redis install to complete the compilation and installation work.

4. After installation, the contents of the Bin directory under the installation directory are as follows:

5, start the Redis service: to the installation directory, execute the command bin/redis-server/opt/redis-2.8.24/redis.conf, you can start the Redis service, such as:

Part II: Configure Redis and add to Linux services

6, modify the Redis configuration file, to the Redis directory, modify some of the relevant parameters in the redis.conf (depending on the actual situation can be set), as follows:

=================================== parameter configuration start ===================================

Redis configuration file Parameter description:
1. Redis is not running as a daemon by default and can be modified by this configuration item, enabling the daemon with Yes
Daemonize Yes
2. When Redis is running as a daemon, Redis writes the PID to the/var/run/redis.pid file by default and can be specified by pidfile
Pidfile/var/run/redis.pid
3. Specify the Redis listening port, the default port is 6379, the author in his own article blog post explains why 6379 as the default port, because 6379 Merz the corresponding number on the phone keypad, and Merz from Italy showgirl Alessia Merz name
Port 6379
4. The host address of the binding
Bind 127.0.0.1
5. If the client closes the connection after a long period of inactivity, if it is specified as 0, the function is turned off
Timeout 300
6. Specify logging level, Redis supports four levels in total: Debug, verbose, notice, warning, default is verbose
LogLevel verbose
7. Logging mode, default to standard output, if Redis is configured to run as daemon, and this is configured as logging mode as 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 on the connection
Databases 16
9. Specify how many times the update operation will synchronize the data to the data file and can be combined with multiple conditions
Save <seconds> <changes>
There are three conditions available in the Redis default configuration file:
Save 900 1
Save 300 10
Save 60 10000
Represents 1 changes in 900 seconds (15 minutes), 5 changes in 300 seconds (10 minutes), and 60 changes in 10,000 seconds.
10. Specify whether to compress the data when storing to the local database, the default is Yes,redis with LZF compression, if you want to save CPU time, you can turn off this option, but it will cause the database file to become huge
Rdbcompression Yes
11. Specify the local database file name, the default value is Dump.rdb
Dbfilename Dump.rdb
12. Specify the local database to hold the directory
Dir./
13. Set the IP address and port of the master service when this machine is a Slav service, and it will automatically synchronize data from master when Redis boots
Slaveof <masterip> <masterport>
14. When the master service is password protected, the Slav service connects the password of master
Masterauth <master-password>
15. Set up the Redis connection password, if the connection password is configured, the client will need to provide the password via auth <password> command when connecting to Redis, turn off by default
Requirepass foobared
16. Set the maximum number of client connections at the same time, the default is unlimited, Redis can open the number of client connections for the Redis process can open the maximum number of file descriptors, if set maxclients 0, indicating no restrictions. 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 Redis memory limit, Redis will load data into memory when it is started, Redis will try to clear expired or expiring key first, when this method processing, still reach the maximum memory setting, will no longer write operation, but still can read operation. Redis new VM mechanism will store key memory, value will be stored in swap area
MaxMemory <bytes>
18. Specifies whether logging occurs after each update operation, which, by default, writes data to disk asynchronously and, if not turned on, may result in data loss over a period of time when power is lost. Because the Redis itself synchronizes data files in sync with the save conditions above, some data will only exist in memory for a period of time. Default is No
AppendOnly No
19. Specify the update log file name, default to Appendonly.aof
Appendfilename appendonly.aof
20. Specify the update log condition, a total of 3 optional values:
No: Indicates that the data cache of the operating system is synchronized to disk (fast)
Always: Represents a manual call to Fsync () to write data to disk (slow, secure) after each update operation
Everysec: Indicates synchronization once per second (trade-offs, default values)
Appendfsync everysec
21. Specify whether to enable the virtual memory mechanism, the default value is no, a simple introduction, the VM mechanism to store data paging, by Redis will be less accessible pages, such as cold data swap to disk, Access to multiple pages is automatically swapped out into memory by the disk (in a later article I will carefully analyze the Redis VM mechanism)
Vm-enabled No
22. Virtual memory file path, default value is/tmp/redis.swap, cannot be shared by multiple Redis instances
Vm-swap-file/tmp/redis.swap
23. Store all data greater than vm-max-memory in virtual memory, regardless of the vm-max-memory settings, all index data is memory stored (REDIS index data is keys), that is, when the vm-max-memory is set to 0, In fact, all value is present on disk. The default value is 0
Vm-max-memory 0
The Redis swap file is divided into a number of page, an object can be saved on more than one page, but a page can not be shared by multiple objects, Vm-page-size is based on the size of the stored data to set, the author suggests that if you store many small objects, The page size is best set to 32 or 64bytes, and if you store large objects, you can use a larger page, and if you are unsure, use the default values
Vm-page-size 32
25. Set the number of pages in the swap file, since the page table (a bitmap that indicates that the page is idle or used) is in memory and consumes 1byte of memory per 8 pages on disk.
Vm-pages 134217728
26. Set the number of threads to access swap files, preferably do not exceed the machine's core number, if set to 0, then all the swap file operation is serial, may cause a relatively long delay. The default value is 4
Vm-max-threads 4
27. Set when replying to the client, whether to merge the smaller package into one package send, the default is to turn on
Glueoutputbuf Yes
28. Specifies that a special hashing algorithm is used when more than a certain number or maximum element exceeds a critical value
Hash-max-zipmap-entries 64
Hash-max-zipmap-value 512
29. Specify whether to activate the reset hash, which is on by default (described later in the introduction of the Redis hashing algorithm)
activerehashing Yes
30. Specify other profiles that can use the same configuration file across multiple Redis instances on the same host, while each instance has its own specific configuration file
Include/path/to/local.conf

==================================== parameter Configuration End =======================================

7. Copy the Redis boot script to directory/etc/init.d/redis, and name it Redis, where the Redis script file (redis_init_script) is located under the Redis directory utils directory.

8, add the registered Redis Service, command chkconfig--add Redis.

If the following error is reported: Service Redis does not support Chkconfig, the Redis script needs to be modified.

Vi/etc/init.d/redis, add the following two sentences in the script #!/bin/sh:

# chkconfig:2345 90 10

# Description:redis is a persistent key-value database

The above note means that the Redis service must be started or shut down at run level 2,3,4,5, the priority of the boot is 90, and the priority of the shutdown is 10.

Once the modifications are complete, you can execute the command again chkconfig--add Redis to complete the Add service.

9, modify the service start level: Chkconfig--level 2345 Redis on.

10. Copy script file: Execute command cp/usr/local/redis/bin/*/usr/local/bin

11. Start Redis Services: Service Redis start

If error: Fatal error,can ' t open config file '/etc/redis/6379.conf ', the Redis profile needs to be copied to the/etc/redis directory: cp/opt/redis-2.8.24/ redis.conf/etc/redis/6379.conf, this step first to the/etc directory to establish the Redis directory, the reason for the command 6379.conf, which is determined by the startup script, but also corresponding to the modification, but not recommended.

12. Stop Redis Services: Service Redis stop

If error:/var/run/redis_6379.pid does not exist,process are not running, the Redis configuration file needs to be modified, vi/etc/redis/6379.conf, Pidfile/var /run/redis.pid to: Pidfile/var/run/redis_6379.pid, this PID is also determined by the startup script, you can modify the corresponding.

Here, the Redis installation configuration is complete! If you have questions, you can leave a message or contact the author ^_^.

Configuring Redis services under Linux installation

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.