1. redis.conf Configuration parameters:
#是否作为守护进程运行
Daemonize Yes
#如以后台进程运行, you need to specify a PID, which defaults to/var/run/redis.pid
Pidfile Redis.pid
#绑定主机IP, the default value is 127.0.0.1
#bind 127.0.0.1
#Redis默认监听端口
Port 6379
#客户端闲置多少秒后, disconnect, defaults to 300 (sec)
Timeout 300
#日志记录等级, there are 4 optional values, Debug,verbose (default), notice,warning
LogLevel verbose
#指定日志输出的文件名, the default value is stdout, or it can be set to/dev/null screen log
LogFile stdout
#可用数据库数, the default value is 16, the default database is 0
Databases 16
#保存数据到disk的策略
#当有一条Keys数据被改变是, refresh to disk once in 900 seconds
Save 900 1
#当有10条Keys数据被改变时, refresh to disk once in 300 seconds
Save 300 10
#当有1w条keys数据被改变时, refresh to disk once in 60 seconds
Save 60 10000
Whether to compress data Objects #当dump. Rdb Database
Rdbcompression Yes
#本地数据库文件名, the default value is Dump.rdb
Dbfilename Dump.rdb
#本地数据库存放路径, the default value is./
dir/var/lib/redis/
########### Replication #####################
#Redis的复制配置
# slaveof <masterip> <masterport> Set the IP and port of the primary service when this machine is from service
# Masterauth <master-password> Set the connection password for the primary service when this machine is from service
#连接密码
# Requirepass Foobared
#最大客户端连接数, default does not limit
# maxclients 128
#最大内存使用设置, when the maximum memory setting is reached, Redis attempts to clear the key that has expired or is about to expire, and when this method is processed, the maximum memory setting is reached and no more writes can be made.
# maxmemory <bytes>
#是否在每次更新操作后进行日志记录, if it is not turned on, it may result in loss of data over time during a power outage. Because the Redis itself synchronizes data files according to the above save condition, some data will only exist in memory for a period of time. The default value is no
AppendOnly No
#更新日志文件名, the default value is Appendonly.aof
#appendfilename
#更新日志条件, there are 3 optional values. No means that the operating system synchronizes the data cache to disk, and always indicates that Fsync () is manually invoked after each update operation to write the data to disk, Everysec is synchronized every second (the default).
# Appendfsync Always
Appendfsync everysec
# Appendfsync No
################ VIRTUAL MEMORY ###########
#是否开启VM功能, the default value is no
Vm-enabled No
# vm-enabled Yes
#虚拟内存文件路径, the default value is/tmp/redis.swap, not multiple Redis instance sharing
Vm-swap-file/tmp/redis.swap
# store all data larger than vm-max-memory into virtual memory, regardless of how small the vm-max-memory is set, all index data is stored in memory (Redis index data is the keys), that is, when the vm-max-memory is set to 0, In fact, all of the value exists 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
#是否重置Hash表
activerehashing Yes
Note: The Redis official documentation gives some suggestions for the use of VMS:
When your key is small and value is large, using a VM will be better. Because this saves a lot of memory.
When your key is not an hour, consider using some very good methods to turn a large key into a large value, for example, you might consider combining key,value into a new value.
It is best to save your swap file using Linux ext3 and other file systems that are better than sparse file support.
Vm-max-threads This parameter, you can set the number of threads to access the swap file, and it is best not to exceed the machine's kernel count. If set to 0, all operations to the swap file are serial. It can be a long delay, but there is a good guarantee of data integrity.
2. Adjust system kernel Parameters
If the memory situation is more stressful, you need to set kernel parameters:
Echo 1 >/proc/sys/vm/overcommit_memory
Here's what this configuration means:/proc/sys/vm/overcommit_memory
This file specifies the kernel's policy for memory allocation, which can be 0, 1, and 2.
0 indicates that the kernel will check if there is enough available memory to use the process, and if there is enough memory available, the memory request is allowed, otherwise the memory request fails and the error is returned to the application process.
1 indicates that the kernel allows all physical memory to be allocated regardless of the current state of memory.
2, which indicates that the kernel allows to allocate more memory than the sum of all physical memory and swap space
Redis in the dump data, will fork a child process, in theory, the memory occupied by the children process and parent is the same, such as the memory used by parent is 8G, this time also to allocate 8G memory to child, if the memory can not afford, Will often cause the Redis server down machine or IO load too high, inefficient. So here the more optimized memory allocation policy should be set to 1 (indicating that the kernel allows all physical memory to be allocated regardless of current memory state)
First, the operation of services
# redis-server/etc/redis/redis.conf Open
# REDIS-CLI shutdown off
Second, testing
1 can start Redis service in the background, test with redis-benchmark command
2 The actual operation of the test through the REDIS-CLI command
Third, save/backup
A data backup can be implemented by backing up the file on a regular basis.
Because Redis is written to disk asynchronously, if you want the data in memory to be written to the hard disk immediately, you can execute the following command:
Redis-cli Save or Redis-cli-p 6380 Save (Specify port)
Note that the above deployment operations require certain permissions, such as copying and setting kernel parameters.
The memory data is also written to the hard disk when the Redis-benchmark command is executed.
Four, open the port number
1) Open/etc/sysconfig/iptables,
2) After the-"a input-p tcp-m state--state new-m TCP--dport 22-j ACCEPT", plus "-a input-p tcp-m state--state new-m TCP- -dport 6379-j ACCEPT "//Here's 6379 is the Redis default port number
3) Save, restart Firewall:/etc/init.d/iptables restart