Procedure and configuration parameters for installing Redis on CentOS Linux system

  • 2020-05-09 19:36:47
  • OfStack

Installation process:


wget http://code.google.com/p/redis/downloads/detail?name=redis-2.0.4.tar.gz
tar xvzf redis-2.0.4.tar.gz
cd  redis-2.0.4
make
mkdir /home/redis
cp redis-server  /home/redis
cp redis-benchmark  /home/redis
cp redis-cli  /home/redis
cp redis.conf  /home/redis
cd  /home/redis

The sudo command may be used in the installation process, and the new user of the newly installed redhat virtual machine may not be able to use the sudo command, so the file /etc/sudoers needs to be manually modified. The command is as follows:


cd /etc
su root ## Switch to a root User, enter password at the same time
chmod u+w sudoers ## Let go of sudoers Write permission to the file
## in root ALL = (ALL) ALL The following 1 Line increase " Your username " ALL = (ALL) ALL
:wq ## Save the exit
chmod u-w sudoers ## Cancel modify permission

Start the


./redis-server redis.conf

Enter command interaction mode, two types:


1: ./redis-cli
2: telnet 127.0.0.1 6379 (ip Answer the port )

Configuration file parameter description:

1. Redis does not run as a daemon by default and can be modified with this configuration item to enable the daemon using yes


daemonize no

2. When run Redis daemon way, Redis default would take pid write/var run/redis pid files, can be specified by pidfile


pidfile /var/run/redis.pid

3. Specify Redis listening port, and the default port is 6379. In a blog post, the author explained why 6379 is chosen as the default port, because 6379 is the number corresponding to MERZ on the phone button, while MERZ is named after Alessia Merz, an Italian opera girl


port 6379

4. Binding host address


bind 127.0.0.1

5. Close the connection after the client has been idle for a long time. If 0 is specified, this function is turned off


timeout 300

6. Specify the logging level, Redis supports a total of four levels: debug, verbose, notice, warning, verbose by default


loglevel verbose

7. The logging mode is standard output by default. If Redis is configured to run in daemon mode, and in this case, the logging mode is standard output, the logs will be sent to /dev/null


cd /etc
su root ## Switch to a root User, enter password at the same time
chmod u+w sudoers ## Let go of sudoers Write permission to the file
## in root ALL = (ALL) ALL The following 1 Line increase " Your username " ALL = (ALL) ALL
:wq ## Save the exit
chmod u-w sudoers ## Cancel modify permission
0

8. Set the number of databases, the default database is 0, you can use the SELECT command to specify the database id on the connection


cd /etc
su root ## Switch to a root User, enter password at the same time
chmod u+w sudoers ## Let go of sudoers Write permission to the file
## in root ALL = (ALL) ALL The following 1 Line increase " Your username " ALL = (ALL) ALL
:wq ## Save the exit
chmod u-w sudoers ## Cancel modify permission
1

9. Specify the number of update operations within a certain period of time to synchronize the data to the data file, which can be coordinated by multiple conditions


save

Three conditions are provided in the Redis default profile:


save 900 1
save 300 10
save 60 10000

Represents one change in 900 seconds (15 minutes), 10 changes in 300 seconds (5 minutes), and 10,000 changes in 60 seconds, respectively.

10. The default is yes, and Redis USES 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


cd /etc
su root ## Switch to a root User, enter password at the same time
chmod u+w sudoers ## Let go of sudoers Write permission to the file
## in root ALL = (ALL) ALL The following 1 Line increase " Your username " ALL = (ALL) ALL
:wq ## Save the exit
chmod u-w sudoers ## Cancel modify permission
4

11. Specify the local database file name, with a default value of dump.rdb


cd /etc
su root ## Switch to a root User, enter password at the same time
chmod u+w sudoers ## Let go of sudoers Write permission to the file
## in root ALL = (ALL) ALL The following 1 Line increase " Your username " ALL = (ALL) ALL
:wq ## Save the exit
chmod u-w sudoers ## Cancel modify permission
5

12. Specify local database directory


cd /etc
su root ## Switch to a root User, enter password at the same time
chmod u+w sudoers ## Let go of sudoers Write permission to the file
## in root ALL = (ALL) ALL The following 1 Line increase " Your username " ALL = (ALL) ALL
:wq ## Save the exit
chmod u-w sudoers ## Cancel modify permission
6

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


cd /etc
su root ## Switch to a root User, enter password at the same time
chmod u+w sudoers ## Let go of sudoers Write permission to the file
## in root ALL = (ALL) ALL The following 1 Line increase " Your username " ALL = (ALL) ALL
:wq ## Save the exit
chmod u-w sudoers ## Cancel modify permission
7

14. When the master service is password protected, the slav service connects to the master password


cd /etc
su root ## Switch to a root User, enter password at the same time
chmod u+w sudoers ## Let go of sudoers Write permission to the file
## in root ALL = (ALL) ALL The following 1 Line increase " Your username " ALL = (ALL) ALL
:wq ## Save the exit
chmod u-w sudoers ## Cancel modify permission
8

15. Set the Redis connection password. If the connection password is configured, the client needs to provide the password through the AUTH command when connecting to Redis


cd /etc
su root ## Switch to a root User, enter password at the same time
chmod u+w sudoers ## Let go of sudoers Write permission to the file
## in root ALL = (ALL) ALL The following 1 Line increase " Your username " ALL = (ALL) ALL
:wq ## Save the exit
chmod u-w sudoers ## Cancel modify permission
9

16. Set the maximum number of client connections at the same time 1, with no limit by default. The number of client connections that Redis can open at the same time is the maximum number of file descriptors that Redis process can open. 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


./redis-server redis.conf
0

17. Specify the maximum memory limit of Redis. Redis will load data into memory at startup. After reaching the maximum memory, Redis will first try to clear the Key that has expired or is about to expire. Redis's new vm mechanism will store Key in memory and Value in swap


maxmemory

18. Specify whether to log after each update operation. By default, Redis writes data asynchronously to disk. Because redis itself synchronizes data files according to the save condition above, some data will only exist in memory for a period of time. The default is no


appendonly no

19. Specify the file name of the update log, which defaults to appendonly.aof


appendfilename appendonly.aof

20. Specify an update log condition with three optional values:

no: means to wait for the operating system to synchronize the data cache to disk (fast)
always: represents a manual call to fsync() to write data to disk after each update operation (slow, secure)
everysec: sync once per second (compromise, default)


appendfsync everysec

21. Specify whether to enable the virtual memory mechanism, with the default value of no. For a brief introduction, the VM mechanism will store data by paging, and the Redis mechanism will transfer the page with less visits, namely the cold data swap, to the disk, and the pages with more visits will be automatically swapped out from the disk into memory (I will carefully analyze Redis's VM mechanism in the following articles).


vm-enabled no

22. Virtual memory file path, default value is /tmp/ redis.swap, cannot be Shared by multiple instances of Redis


vm-swap-file /tmp/redis.swap

23. Store all data larger than vm-max-memory in virtual memory. No matter how small the vm-max-memory setting is, all index data is stored in memory (keys is the index data of Redis). The default value is 0


./redis-server redis.conf
7

24. The Redis swap file is divided into many page, one object can be saved on multiple page, but one page cannot be Shared by multiple objects. vm-page-size is set according to the stored data size. If you store very large objects, you can use a larger page, or the default if you are not sure


./redis-server redis.conf
8

25. Set the number of page in the swap file. Since the page table (1 bitmap indicating that the page is free or in use) is in memory, every 8 pages on disk will consume 1byte's memory.


vm-pages 134217728

26. Set the number of threads to access the swap file, preferably not exceeding the machine's core. If set to 0, then all operations to the swap file will be serial, which may cause a relatively long delay. The default value is 4


1: ./redis-cli
2: telnet 127.0.0.1 6379 (ip Answer the port )
0

27. Set whether to combine the smaller packets into one packet when sending the reply to the client. It is enabled by default


1: ./redis-cli
2: telnet 127.0.0.1 6379 (ip Answer the port )
1

28. Specify a special hash algorithm to be used when a specified number or maximum element exceeds a certain threshold value of 1


1: ./redis-cli
2: telnet 127.0.0.1 6379 (ip Answer the port )
2

29. Specify whether to activate the reset hash, which is enabled by default (more on Redis's hash algorithm later)


1: ./redis-cli
2: telnet 127.0.0.1 6379 (ip Answer the port )
3

30. Specify the inclusion of additional configuration files, which can be used between multiple instances of Redis on the same host, while each instance has its own specific configuration file


1: ./redis-cli
2: telnet 127.0.0.1 6379 (ip Answer the port )
4


Related articles: