Redis optimized configuration and redis.conf instructions

Source: Internet
Author: User
Tags benchmark

Redis optimized configuration and redis.conf description time the-Ten- in  on: on: -CSDN Blog Original http://blog.csdn.net/luozhonghua2014/article/details/40568707Topic Redis1. redis.conf configuration parameters: #是否作为守护进程运行daemonize yes# Run as a later process, you need to specify a PID, which defaults to/var/run/Redis.pidpidfile redis.pid# binds the host IP, the default value is 127.0.0.1#bind127.0.0.1#Redis默认监听端口port6379#客户端闲置多少秒后, disconnect, default 300 (seconds) Timeout -#日志记录等级, there are 4 optional values, Debug,verbose (default), Notice,warningloglevel verbose# Specifies the file name of the log output, the default value is stdout, or it can be set to/dev/NULL masking log logfile stdout# number of available databases, default is 16, default database is 0databases -#保存数据到disk的策略 # When one of the keys data is changed, 900 seconds to disk once save the 1#当有10条Keys数据被改变时, 300 seconds to disk once save - Ten#当有1w条keys数据被改变时, 60 seconds to disk once save - 10000#当dump the. Rdb database, whether to compress the data object rdbcompression yes# The local database file name, the default value is dump.rdbdbfilename dump.rdb# Local database storage path, the default value is./dir/var/lib/redis/########### Replication ##################### #Redis的复制配置 # slaveof<masterip> <masterport>set the IP and port # Masterauth of the Master service when this machine is from service<master-password>Set the connection password # connection password # Requirepass foobared# Maximum number of client connections for the primary service when this machine is from service, the default is no Limit # maxclients -#最大内存使用设置, when the maximum memory setting is reached, Redis attempts to clear the expired or expiring key first, and when this method is processed, the maximum memory setting is reached and no further write operations can be made. # maxmemory<bytes>#是否在每次更新操作后进行日志记录, if not turned on, may result in loss of data 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. The default value is noappendonly no# update log file name, the default value is appendonly.aof#appendfilename# update log condition, there are 3 optional values. No indicates that the data cache of the operating system is synchronized to disk, always means that the data is written to disk manually after each update operation, and EVERYSEC is synchronized once per second (the default value). # appendfsync Alwaysappendfsync everysec# appendfsync no################ VIRTUAL MEMORY ########### #是否开启VM功能, default value is NOVM -enabled no# VMS-enabled yes# virtual memory file path, default value is/tmp/Redis.swap, you cannot share VMS with multiple Redis instances-swap-file/tmp/redis.swap# will all be larger than the VM-max-memory data into virtual memory, regardless of the vm-max-memory settings, all index data is memory stored (REDIS index data is keys), that is, when vm-max-when memory is set to 0, all value is actually present on the disk. The default value is 0. VMS-max-memory0VMS-page-size +VMS-pages134217728VMS-max-threads4############# Advanced CONFIG ############## #glueoutputbuf Yeshash-max-zipmap-entries -Hash-max-zipmap-value +#是否重置Hash表activerehashing Yes Note: The Redis official documentation makes some suggestions for using VMS: When your key is small and the value is large, the effect of using a VM is better. Because this saves more memory. When your key is not hour , consider using some very important methods to turn a large key into a large value, such as you might consider combining key,value into a new value. It is best to use Linux ext3 to support a better file system for sparse files to save your swap files. 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 number of cores of the machine. If set to 0, then all operations on swap files are serial. This can result in a long delay, but with good assurance of data integrity.2. Adjusting the kernel parameters of the system if the memory situation is tense, you need to set the kernel parameters: Echo1>/proc/sys/vm/Overcommit_memory here to say what this configuration means:/proc/sys/vm/overcommit_memory This file specifies the kernel's policy for memory allocation, which can be a value of 0,1、2. 0indicates that the kernel will check for sufficient available memory to be used by the process, and if sufficient memory is available, the memory request is allowed; otherwise, the memory request fails and the error is returned to the application process. 1, which means that the kernel allows all physical memory to be allocated regardless of the current state of memory. 2, which means that the kernel allows to allocate more than all of the physical memory and the sum of the swap space. Redis will fork out a sub-process when the dump data, theoretically the child process consumes the same memory as the parent, for example, the parent occupies 8G of memory, This time also to allocate 8G of memory to child, if the memory can not afford, often cause the Redis server down or IO load is too high, inefficient. So the more optimized memory allocation policy here should be set to1(indicates that the kernel allows all physical memory to be allocated regardless of the current state of memory) one, run service # Redis-server/etc/redis/redis.conf Open # Redis-CLI shutdown off second, test1) After you start the Redis service in the background, use the redis-Benchmark Command Test2) by redis-CLI Command actual operation test Three, save/Backup data backups can be implemented by backing up the file on a regular basis. Because Redis is written to disk asynchronously, if you want to have the in-memory data written to the hard disk immediately, you can execute the following command: Redis-cli Save or Redis-cli-p6380Save (Specify port) Note that the above deployment operation requires certain permissions, such as copying and setting kernel parameters. Performing Redis-The benchmark command also writes memory data to the hard disk. Iv. opening the port number1) Open/etc/sysconfig/Iptables,2) in-"A input-p tcp-m State--state new-m TCP--dport A-j ACCEPT "Back, plus"-A input-p tcp-m State--state new-m TCP--dport6379-j ACCEPT "//The 6379 here is the Redis default port number3) Save, restart Firewall:/etc/init.d/iptables restart

Redis optimized configuration and redis.conf instructions

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.