I. Redis configuration file 1. General configuration
Daemonize No # By default, Redis is not run in daemon form. Daemonize Configuration Items Control the way Redis operates
Pidfile/path/to/redis.pid #当以daemon形式运行时, Redis generates a PID file that is generated by default in/var/run/redis.pid
Bind 192.168.1.2 10.8.4.2 # Specifies the IP of the binding, can have more than one
Port 6379 #指定监听端口
Unixsocket/tmp/redis.sock #也可以监听socket
Unixsocketperm 755 #当监听socket时可以指定权限为755
Timeout 0 #当一个redis-client has not been requested to send to the server side, then the server side has the right to actively shut down the connection, you can set the "Idle Timeout Time" by timeout, 0 means never shut down.
Tcp-keepalive 0 #TCP连接保活策略, can be set by the Tcp-keepalive configuration item, in seconds, if set to 60 seconds, the server side will every 60 seconds to connect to idle clients to initiate an ACK request to check whether the client has been hung off, For unresponsive clients, their connections are closed. If set to 0, keepalive detection is not performed.
LogLevel Notice # Log level, there are four kinds of debug, verbose, notice, warning
LogFile "" #定义日志路径,
Syslog-ident Redis #如果希望日志打印到syslog中, controlled by syslog-enabled. In addition, Syslog-ident allows you to specify log flags in the syslog.
Syslog-facility Local0 # Specifies the syslog device, which can be either user or LOCAL0-LOCAL7
Databases #设置数据库的总数量
2.Redis Snapshot configuration (Rdb persistence)
Save 1 #表示每15分钟且至少有1个key改变 triggers a persistence
Save #表示每5分钟且至少有10个key改变, trigger a persistence
Save 10000 #表示每60秒至少有10000个key改变 to trigger a persistent
Save "" #这样可以禁用rdb持久化
Stop-writes-on-bgsave-error Yes #rdb持久化写入磁盘避免不了会出现失败的情况, Redis stops the write operation as soon as the default fails. If you feel it doesn't matter, then you can use this option to turn this feature off.
Rdbcompression Yes #是否要压缩
Rdbchecksum Yes #是否进行数据校验
Dbfilename Dump.rdb #定义快照文件的名字
Dir./#定义快照文件储存路劲
3.Redis Security-related configuration
Requirepass aminglinux #设置redis-server's password
Rename-command config aminglinux.config #将CONFIG命令更名为aminglinux. config to avoid mis-operation, but it is not recommended to enable this feature if AOF persistence is used
Rename-command config "" #也可以后面定义为空 so that the config command is forbidden
4.Redis Limiting related configurations
MaxClients 10000 #限制最大客户端连接数
MaxMemory <bytes> #设定最大内存使用数, Unit is byte
Maxmemory-policy Volatile-lru #指定内存移除规则
The Maxmemory-samples 3 #LRU算法和最小TTL算法都并非是精确的算法, but the estimated value. So you can set the size of the sample. If Redis checks three keys by default and chooses which one is LRU, then you can change the number of this key sample.
5.Redis aof Persistence-related configuration
AppendOnly no #如果是no, then turn on aof persistence
Appendfilename "appendonly.aof" # Specify AOF file name
Appendfsync everysec #指定fsync () call pattern, there are three kinds of no (do not call Fsync), always (each write will call Fsync), everysec (call once per second Fsync). The first is the fastest, the second data is the safest, but the performance will be worse, the third is this scenario, the default is the third.
No-appendfsync-on-rewrite No # Set Yes to avoid disk IO blocking when write volume is very large
Auto-aof-rewrite-percentage #规定什么情况下会触发aof重写. The value is a scale, and 10 means that the override mechanism is triggered when the AoF file increases by 10%.
Uto-aof-rewrite-min-size 64MB #重写会有一个条件, is not less than 64Mb
6.Redis slow log-related configuration
For slow logs, you can set two parameters, one is the execution length, the unit is microseconds, the other is the length of the slow log. When a new command is written to the log, the oldest one is removed from the command log queue.
Slowlog-log-slower-than 10000 #慢于10000ms则记录日志
Slowlog-max-len #日志长度
Second, Redis master configuration configuration:
Two servers: Master (192.168.31.105) and Slave (192.168.31.112) to install Redis and start them separately, respectively, as described in the previous steps
Master config file does not move
Add a row to the slave configuration file
Slaveof 192.168.31.105 6379
Masterauth passwd//If the Lord sets a password, add this line
Start master and slave, respectively
Test:
Master: Redis-cli>set K1 v1>get K1 "v1"
Slave: Redis-cli>get K1 "v1"
Redis Master-Slave Other related configurations:
Slave-read-only Yes//Let from read-only
Repl-ping-slave-period 10//Set slave the frequency of pings to master, initiated every 10s
Repl-timeout 60//Set slave ping does not pass the master number of S after the timeout
Repl-disable-tcp-nodelay No//open tcp_nodelay, will use less bandwidth, but there will be delay, so it is recommended to close
Repl-backlog-size 1MB//sync Queue Length, Backuplog is a buffer of master, master will write the data to the buffer, slave will synchronize the data from the buffer after the master disconnects.
Repl-backlog-ttl 3600//Master disconnect, buffer expiration, default 1 hours
Slave-priority 100//Multiple Slave can be set priority, the lower the value of the higher priority, applied to the cluster, support slave switch to master, the highest priority will switch
Min-slaves-to-write 3//and used in conjunction with the following, it means that master found that there are more than 3 slave latency higher than 10s, then master will temporarily stop the write operation. If either of these values is 0, the function is turned off, and the default first value is 0.
Min-slaves-max-lag 10
Linux-nosql's Redis (ii)