# Redis维护管理
# Redis配置
include
include /path/to/local.conf
引入其他配置文件
loadmodule
加载模块
network
bind
绑定host
protected-mode
保护模式,默认redis需要设置管理员账号密码,开启了保护模式,如果第一次使用没有设置管理员,就会出现报错,关闭保护模式即可
port
tcp-backlog
timeout
tcp-keepalive
general
- daemonize
- supervised
- pidfile
- loglevel
- logfile
- databases
- always-show-logo
snapshotting
- save
- stop-writes-on-bgsave-error
- rdbcompression
- rdbchecksum
- dbfilename
- dir
replication
replica-serve-stale-data
replica-read-only
repl-diskless-sync
主将数据写入磁盘文件中传给从还是直接将数据通过网络传给从
- yes 写入磁盘文件再传给从导入
- no 通过网络直接传输
repl-diskless-sync-delay
repl-disable-tcp-nodelay
repl-backlog-size
增量复制
memory mamagement
- maxmemory
- maxmemory-policy
- volatile-lru -> Evict using approximated LRU among the keys with an expire set.
- allkeys-lru -> Evict any key using approximated LRU.(LRU最久没有使用)
- volatile-lfu -> Evict using approximated LFU among the keys with an expire set.(LFU最少使用)
- allkeys-lfu -> Evict any key using approximated LFU.
- volatile-random -> Remove a random key among the ones with an expire set.
- allkeys-random -> Remove a random key, any key.
- volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
- noeviction -> Don't evict anything, just return an error on write operations.
append only mode
appendonly
appendfilename
appendsync
no-appendfsync-on-rewrite
如果redis判断正在执行save或者aof操作向磁盘疯狂写数据时就会走appendsync no 的方式,这样的风险就是丢失数据
最大连接数
最大内存(1G-10G)
# 主从复制
Redis默认是使用异步复制的方法
特点是低延迟和高性能
Redis本身追求的是高性能,会尽量减少其他技术的整合
增量同步
如果一个从故障宕机重启恢复后采用增量同步方式跟主保持一致
主是可以知道有哪些从在追随他,配置的时候都会向主去注册
部署实践
准备
- 三个实例 6379、6380、6381
修改配置文件为非后台运行(daemonize no),以及日志文件控制台输出(注释logfile)
命令配置主从
slaveof host port // Redis 5以前 replicaof host port // Redis 5以后
1
2启动参数配置主从
redis-server ./6381.conf --replicaof 127.0.0.1 6379 redis-server ./6381.conf --replicaof 127.0.0.1 6379 --readonly yes
1
2取消追随
slaveof no one // 取消追随 replicaof no one // 取消追随
1
2
# HA高可用
# Sentinel(哨兵)
监控
主是知道有哪些从追随他的,所以监控主就只有从的信息
Sentinel是如何知道其他Sentinel的呢?
通过发布订阅来获取
psubscribe
Sentinel是会修改配置文件的,比如主故障了,重新推选出主之后会修改配置信息
配置Sentinel
添加配置文件(26379.conf)
port 26379 sentinel monitor mymaster 127.0.0.1 6379 2
1
2启动Sentinel
redis-sentinel /etc/redis/26379.conf redis-server /etc/redis/26379.conf --sentinel
1
2