RedisÊÇÒ»¸öÖ§³Ö³Ö¾Ã»¯µÄÄÚ´æÊý¾Ý¿â£¬Ò²¾ÍÊÇ˵redisÐèÒª¾³£½«ÄÚ´æÖеÄÊý¾Ýͬ²½µ½´ÅÅÌÀ´±£Ö¤³Ö¾Ã»¯¡£redisÖ§³ÖËÄÖֳ־û¯·½Ê½£¬Ò»ÊÇ Snapshotting£¨¿ìÕÕ£©Ò²ÊÇĬÈÏ·½Ê½£»¶þÊÇAppend-only file£¨Ëõдaof£©µÄ·½Ê½£»ÈýÊÇÐéÄâÄڴ淽ʽ£»ËÄÊÇdiskstore·½Ê½¡£
Ò»¡¢RBD(¿ìÕÕ)
ÔÀí
ÔÚij¸öʱ¼äµã½«ÄÚ´æÖеÄÊý¾ÝдÈëÒ»¸ö´ÅÅ̵ÄÁÙʱÎļþ£¬³Ö¾Ã»¯½áÊøºó£¬ÓÃÕâ¸öÁÙʱÎļþÌæ»»Éϴγ־û¯µÄÎļþ¡£
ÅäÖÃÎļþ
save 900 1 # ÔÚ900ÃëÄÚÈç¹û¼üÖµÐ޸Ĺý1´Î¾Í¿ìÕÕ save 300 10 # ÔÚ300ÃëÄÚÈç¹û¼üÖµÐ޸Ĺý10´Î¾Í¿ìÕÕ save 60 10000 # ÔÚ60ÃëÄÚ¼üÖµÐ޸Ĺý10000´Î¾Í¿ìÕÕ stop-writes-on-bgsave-error yes # ºǫ́±¸·Ý³ö´íʱ£¬ÊÇ·ñ½ûֹеÄдÈë²Ù×÷£¿ Èç¹û²»½ûÖ¹ÈÝÒ×Ôì³ÉÊý¾Ý²»Ò»Ö rdbcompression yes # µ¼³öµÄrdbÎļþÊÇ·ñѹËõ rdbchecksum yes # »Ö¸´Ê±µ¼ÈërdbÎļþÊÇ·ñ¼ìÑéÍêÕûÐÔ¡¢ÊÇ·ñ¼ìÑé°æ±¾ÊÇ·ñÒ»Ö dbfilename dump.rdb # µ¼³öÀ´µÃrdbÎļþÃû dir /var/lib/redis # rdbµÄ´æ·Å·¾¶
¶þ¡¢AOF
ÔÀí
ͨ¹ý½«·¢Ë͵½·þÎñÆ÷µÄд²Ù×÷ÃüÁî¼Ç¼ÏÂÀ´£¬ÐγÉAOFÎļþ£¬´ËÎļþÖ»Ðí×·¼Ó²»ÄÜÐ޸ģ¬RedisÆô¶¯Ê±»á¶ÁÈ¡AOFÎļþºóÖع¹Êý¾Ý(ÖØÐÂÖ´ÐÐÒ»±é)¡£ÎļþĬÈÏÃû³ÆÊÇappendonly.aof
ÅäÖÃÎļþ
appendonly no # ÊÇ·ñ¿ªÆôaof¹¦ÄÜ appendfilename "appendonly.aof" # ÎļþÃû appendfsync always # Ö»ÒªÒ»Ð޸ľÍͬ²½ÖÁ»º³åÇø£¬²¢Í¬²½ÖÁ´ÅÅÌ appendfsync everysec # ÿÃ뽫Êý¾Ýͬ²½ÖÁ»º³åÇø£¬²¢Í¬²½ÖÁ´ÅÅÌ appendfsync no # redis²»É趨ͬ²½²ßÂÔ£¬ÓÉÄÚºËÉ趨µÄ²ÎÊý¾ö¶¨ÊÇ·ñͬ²½ no-appendfsync-on-rewrite no # appendfsyncÉ趨Ϊalways»òeverysecµÄ»°£¬»¹Òª²»ÒªÍ¬²½´ÅÅÌ auto-aof-rewrite-percentage 100 # ÿ¸ô¶à¾ÃÖع¹aofÎļþ£¬µ¥Î»Ãë auto-aof-rewrite-min-size 64mb # aofÎļþ×îСΪ¶àÉÙʱÖع¹Ò»´ÎaofÎļþ¡£´îÅäÉÏÒ»ÌõʹÓà aof-load-truncated yes # ±ÀÀ£ÐÞ¸´ºó×Ô¶¯½øÐÐÈ«±¸
aofÖØд¡¢Öع¹
½«´óÁ¿Öظ´µÄÃüÁîºÏ²¢³ÉÒ»ÌõÃüÁ¶ø²»±ØƵ·±µÄÈ¥ÖØÐÂÖ´ÐÐÿһÌõÃüÁî.
Èý¡¢AOF¶Ô±ÈRDB
AOF¸ü¼Ó°²È«£¬¿ÉÒÔ½«Êý¾Ý¼´Ê±Í¬²½µ½ÎļþÖУ¬µ«ÊÇÏûºÄ´ÅÅÌI/O£¬Ð§ÂʵÍ
Snapshot¸ü¸ßЧ£¬ËüÊÇ·þÎñÆ÷ÔÚÕý³£ÔËÐÐÇé¿öÏÂÊý¾Ýͬ²½×î¼ÑÊֶΣ¬Îļþ³ß´çС£¬Ð§Âʸߣ¬°²È«ÐÔµÍ
×¢£ºRDBÓëAOFͬʱ¿ªÆô ĬÈÏʹÓÃAOFÀ´»Ö¸´Êý¾Ý
ËÄ¡¢³£Óüܹ¹
¼Ü¹¹Á¼ºÃµÄ»·¾³ÖУºMasterʹÓÃAOF£¬SlaveʹÓÃsnapshot¡£ÔÒòÊÇÖ÷Ҫȷ±£Êý¾ÝÍêÕû£¬´ÓÒªËٶȿ졣
ÍøÂç»·¾³½Ï²î£º½¨ÒéʹÓÃmasterÓëslaveͬʱʹÓÃAOF¸ü¼Ó°²È«
ÍøÂçÁ¼ºÃ¡¢ÐèÒªÊÕÃܼ¯ÐÍд²Ù×÷£º½¨ÒéMaster²ÉÓÃsnapshot£¬Slave²ÉÓÃAOF
ÔÎÄÀ´×Ô£ºhttps://www.linuxprobe.com/redis-persistent-storage.html
Ãâ·ÑÌṩ×îÐÂLinux¼¼Êõ½Ì³ÌÊé¼®£¬Îª¿ªÔ´¼¼Êõ°®ºÃÕßŬÁ¦×öµÃ¸ü¶à¸üºÃ£¬¿ªÔ´Õ¾µã£ºhttps://www.linuxprobe.com/