Redis 6.0多机数据库

Redis Master Slave+Sentinel

奇数台redis服务+同等数量的redis 哨兵服务,【云服务器需要考虑安全组是否允许服务间的通信】

shell> cd /tmp
shell> wget https://nchc.dl.sourceforge.net/project/tcl/Tcl/8.6.1/tcl8.6.1-src.tar.gz
shell> tar zxvf tcl8.6.1-src.tar.gz -C /usr/local
shell> cd /usr/local/tcl8.6.1/unix/
shell> ./configure
shell> make && make install

shell> cd /tmp
shell> wget http://download.redis.io/releases/redis-6.0.4.tar.gz
shell> tar zxvf redis-6.0.4.tar.gz
shell> cd redis-6.0.4/
shell> make
shell> make install prefix=/usr/local/redis
shell> mkdit /usr/local/redis/etc
shell> cp /tmp/redis-6.0.4/redis.conf /usr/local/redis/etc/
shell> vim /usr/local/redis/etc/redis.conf
daemonize yes # 守护进程
bind 本机在局域网中的ip # 监听本机
dir  "/var/redis/"
logfile "/var/log/redis.log"
requirepass 123456
# 从服务还需要配置以下参数
replicaof 主服务ip 6379  # 主服务的监听地址
masterauth 123456 # 配置主服务的密码
shell> redis-server /usr/local/redis/etc/redis.conf
shell> redis-sentinel /usr/local/redis/etc/sentinel.conf

依次启动,主服务->从服务,接下来配置哨兵

shell> cp /tmp/redis-6.0.4/sentinel.conf /usr/local/redis/etc/
bind 本机ID地址
daemonize yes # 守护进程
logfile "/var/log/sentinel.log"
sentinel monitor mymaster 主服务IP 6379 2
sentinel auth-pass mymaster 123456 # 配置主服务的密码

Redis Cluster

# 修改配置文件,由于这是在同一个机器上,所以需要多个不同的配置
port 7000
pidfile /var/run/redis_7000.pid
logfile "/Users/kendo/Desktop/program/redis-cluster/7000/redis.log"
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 15000
dir /Users/kendo/Desktop/program/redis-cluster/7000/
appendonly yes
# 创建集群 5.0+开始用这种方式
shell> redis-cli --cluster  create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1
# 创建集群代理,6.0新增
shell> redis-cluster-proxy 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

# 也可以使用redis自带命令生成集群
shell> create-cluster start
shell> create-cluster create

注意事项

配置主从时,记得删除redis.conf里的最后的旧配置,user default on xxx ~* +@all