Vi/etc/redis/6501.conf (Redis_master) Daemonize Yes #启用守护进程 Port 6501 #监听的端口号 Timeout 0 #当客户端闲置多长时间后关闭连接, if specified as 0, to turn off the feature Tcp-keepalive #表示将周期性使用SO_KEEPALIVE检测客户端是否还处于健康状态, per second LogLevel Notice #指定日志记录级别, Redis supports a total of four levels: Debug, verbose, notice, warning Logfile/var/log/redis_6501.log #指定日志路径 Databases 8 #设置数据库的数量 Save 900 1 #表示900秒 (15 minutes) with 1 changes, saving data to disk Save #300秒 (5 minutes) has 10 changes Save 10000 #60秒内有10000个更改 # slaveof 192.168.240.78 6501 This line is added to the redis_backup above Stop-writes-on-bgsave-error Yes #当持久化出现错误之后, continue to provide write service Rdbcompression Yes #在进行镜像备份时, whether to compress Rdbchecksum Yes #读取和写入的时候是否支持CRC64校检 Dbfilename Dump.rdb #指定本地数据库文件名, the default value is Dump.rdb dir/var/lib/redis/6501 #指定本地数据库存放目录 Slave-serve-stale-data Yes #当slave服务器和master服务器失去连接后, or if the value of this parameter is set to "yes" when the data is being replicated, the slave server can continue to accept requests from the client, otherwise The requested client is returned with the following information "SYNC with Master in progress" Slave-read-only Yes #是否允许slave服务器节点只提供读服务 Repl-disable-tcp-nodelay no #指定向slave同步数据时, disable the No_delay option for the socket. If you configure Yes to disable No_delay, the TCP stack will combine packet forwarding to reduce the number of packets between the master and slave nodes and save bandwidth, but increase the time that data is synchronized to slave. If configured to "No" to indicate that No_delay is enabled, the TCP stack does not delay the sending of packets, so that the latency of data synchronization decreases, but requires greater bandwidth. In general, you should configure No to reduce synchronization latency, but you can configure it to Yes if the network load between the master and slave nodes is already high. Slave-priority #指定slave优先级 AppendOnly Yes #开启append only mode, Redis appends each write request received to the Appendonly.aof file, and restores the previous state from the file when Redis restarts. But this will cause appendonly.aof file is too large, so Redis also support the bgrewriteaof instructions, appendonly.aof to reorganize. Default is not turned on. Appendfilename appendonly.aof #默认为appendonly. aof Appendfsync everysec #设置aof的同步频率, there are three choices always, everysec, no, the default is everysec means sync every second No-appendfsync-on-rewrite no #指定是否在后台aof文件rewrite期间调用fsync, defaults to No Auto-aof-rewrite-percentage #指定Redis重写aof文件的条件, which defaults to 100, indicates that the current AOF file growth exceeds 100% of the last Afo file size compared to the last rewrite aof file size. Will trigger background rewrite. If configured to 0, automatic rewrite is disabled Auto-aof-rewrite-min-size 64MB #指定触发rewrite的aof文件大小. If the aof file is less than this value, automatic rewrite is not triggered even if the current file's increment ratio reaches the Auto-aof-rewrite-percentage configuration value. That is, when both of these configuration items are satisfied, the rewrite is triggered Lua-time-limit 5000 Slowlog-log-slower-than 10000 Slowlog-max-len 128 Hash-max-ziplist-entries 512 Hash-max-ziplist-value 64 List-max-ziplist-entries 512 List-max-ziplist-value 64 Set-max-intset-entries 512 Zset-max-ziplist-entries 128 Zset-max-ziplist-value 64 activerehashing Yes Client-output-buffer-limit Normal 0 0 0 Client-output-buffer-limit slave 256MB 64MB 60 Client-output-buffer-limit pubsub 32MB 8MB 60 Hz 10 Aof-rewrite-incremental-fsync Yes #aof The rewrite process, whether to take an incremental file synchronization policy, default to "Yes". Rewrite process, a file synchronization per 32M data, which reduces the number of aof large file writes to the disk ####################### #4. Configure Redis_slave (same as two configurations) ################################# Vi/etc/redis/6501.conf Daemonize Yes Pidfile/var/run/redis_6501.pid Port 6501 Timeout 0 Tcp-keepalive 60 LogLevel Notice Logfile/var/log/redis_6501.log Databases 8 Stop-writes-on-bgsave-error Yes Rdbcompression Yes Rdbchecksum Yes Dbfilename Dump.rdb dir/var/lib/redis/6501 Slaveof 192.168.240.89 6501 Slave-serve-stale-data Yes Slave-read-only Yes Repl-disable-tcp-nodelay No Slave-priority 100 MaxClients 20000 AppendOnly No #slave不写入到磁盘 Appendfsync everysec No-appendfsync-on-rewrite No Auto-aof-rewrite-percentage 100 Auto-aof-rewrite-min-size 64MB Lua-time-limit 5000 Slowlog-log-slower-than 10000 Slowlog-max-len 128 Hash-max-ziplist-entries 512 Hash-max-ziplist-value 64 List-max-ziplist-entries 512 List-max-ziplist-value 64 Set-max-intset-entries 512 Zset-max-ziplist-entries 128 Zset-max-ziplist-value 64 activerehashing Yes Client-output-buffer-limit Normal 0 0 0 Client-output-buffer-limit slave 256MB 64MB 60 Client-output-buffer-limit pubsub 32MB 8MB 60 Hz 10 Aof-rewrite-incremental-fsync Yes #################### #5. Write Redis monitoring Scripts redis_master############################## VI check_redis.sh #!/bin/sh While: Todo Redis-cli-p 6501 Info &>/dev/null If [$?-ne 0]; then Sleep 2 Redis-cli-p 6501 Info &>/dev/null If [$?-ne 0]; then Service keepalived Stop Fi Fi Sleep 10 Done Nohup check_redis.sh & #后台运行 #################### #6. Write Redis_backup monitoring Scripts ##################################### # VI check_redis.sh #!/bin/sh While: Todo Redis-cli-p 6501 Info &>/dev/null If [$?-ne 0]; then Sleep 2 Redis-cli-p 6501 Info &>/dev/null If [$?-ne 0]; then Service keepalived Stop Fi Else IP a|grep 192.168.240.89 If [$?-eq 0]; then grep "^slaveof"/etc/redis/6501.conf If [$?-eq 0]; Then Sed-i ' s/^slaveof/#&/'/etc/redis/6501.conf Service Redis Stop Sleep 1 Service Redis Start Fi Fi Fi Sleep 10 Done Nohup check_redis.sh & #后台运行 |