1. redis. conf configuration parameters:
# Running as a daemon
Daemonize Yes
# If a later process runs, you must specify a PID. The default value is/var/run/redis. PID.
Pidfile redis. PID
# Bind the Host IP address. The default value is 127.0.0.1.
# Bind 127.0.0.1
# Redis default listening port
Port 6379
# How many seconds after the client is idle, disconnect. The default value is 300 (seconds)
Timeout 300
# Log record level, with four optional values: Debug, verbose (default), notice, and warning
Loglevel verbose
# Specify the log output file name. The default value is stdout. You can also set it to/dev/null to shield logs.
Logfile stdout
# Number of available databases; default value: 16; default value: 0
Databases 16
# Policy for saving data to disk
# If one of the keys data is changed, it will be refreshed to disk once every 900 seconds.
Save 900 1
# When 10 keys data items are changed, refresh them to disk once every 300 seconds
Save 300 10
# When pieces of keys data are changed, refresh to disk once every 60 seconds
Save 60 10000
# Whether to compress data objects when dump. RDB Databases
Rdbcompression Yes
# Local database file name, default value: dump. RDB
Dbfilename dump. RDB
# Local database storage path. The default value is ./
DIR/var/lib/redis/
########### Replication #####################
# Redis replication Configuration
# Slaveof <masterip> <masterport> when the local machine is a slave service, set the master service IP address and port
# Masterauth <master-Password> when the local machine is a slave service, set the master service connection password
# Connection password
# Requirepass foobared
# Maximum number of client connections, unlimited by default
# Maxclients 128
# Maximum memory usage settings. When the maximum memory is reached, redis will first try to clear expired or expiring keys. After this method is processed, any key that has reached the maximum memory settings will be cleared, no more write operations can be performed.
# Maxmemory <bytes>
# Whether to record logs after each update operation. If 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
# Update the log file name. The default value is appendonly. Aof.
# Appendfilename
# Update log conditions. There are three optional values. "No" indicates that data is cached and synchronized to the disk by the operating system. "Always" indicates that data is manually written to the disk by calling fsync () after each update operation. "everysec" indicates that data is synchronized once per second (default ).
# Appendfsync always
Appendfsync everysec
# Appendfsync No
############### Virtual memory ###########
# Whether to enable the VM function. The default value is no.
VM-enabled No
# VM-enabled Yes
# 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
# Store all data greater than VM-max-memory into the virtual memory. No matter how small the VM-max-memory settings are, all the 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
VM-page-size 32
VM-pages 134217728
VM-max-threads 4
############ Advanced config ###############
Glueoutputbuf Yes
Hash-max-zipmap-entries 64
Hash-max-zipmap-value 512
# Whether to reset the hash table
Activerehashing Yes
Note: The official redis documentation provides some suggestions on VM usage:
When your key is very small and the value is very large, it will be better to use the VM, because the memory saved is relatively large.
When your key is not hour, you can consider using some very method to convert a large key into a large value. For example, you can consider combining the key and value into a new value.
It is best to use Linux ext3 and other file systems that support sparse files to save your swap files.
The VM-max-threads parameter can be used to set the number of threads accessing the swap file. It is best to set the number of threads not to exceed the number of machine cores. if it is set to 0, all operations on swap files are serial. it may cause a long delay, but it guarantees data integrity.
2. Adjust System Kernel Parameters
If the memory is insufficient, you need to set the kernel parameters:
Echo 1>/proc/sys/Vm/overcommit_memory
Here we will talk about the meaning of this configuration:/proc/sys/Vm/overcommit_memory
This file specifies the kernel memory allocation policy. The value can be 0, 1, or 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.
Redis generates a sub-process when dumping data. In theory, the memory occupied by the child process is the same as that of the parent. For example, the parent occupies 8 GB of memory, at this time, 8 GB of memory should also be allocated to the child. If the memory is not enough, it will often cause the redis server to go down or the IO load is too high, and the efficiency is reduced. Therefore, the optimized memory allocation policy should be set to 1 (indicating that the kernel allows allocation of all physical memory, regardless of the current memory status)
I. Running services
# Enable redis-server/etc/redis. conf
# Disable redis-cli Shutdown
Ii. Test
1) You can use the redis-benchmark command to test the redis service after it is started in the background.
2) Test the actual operation through the redis-CLI command
Iii. Save/backup
Data backup can be achieved through regular backup of this file.
Because redis writes data to the disk asynchronously, if you want to write data in the memory to the hard disk immediately, run the following command:
Redis-cli save or redis-cli-P 6380 save (specified port)
Note that the preceding deployment operations require certain permissions, such as copying and setting kernel parameters.
When executing the redis-benchmark command, the memory data is also written to the hard disk.
4. enable port number
1) Open/etc/sysconfig/iptables,
2) After-[A input-p tcp-M state -- state new-m tcp -- dport 22-J accept, add-A input-p tcp-M state -- state new-m tcp -- dport 6379-J accept. // here, 6379 is the default port number of redis.
3) Save and restart the firewall:/etc/init. d/iptables restart
Redis Optimization Configuration and redis. conf description