一、环境搭建准备(3台机器)
服务器三台:
127.0.0.1
127.0.0.2
127.0.0.3
将redis-3.2.9.tar.gz压缩包分别上传到各自机器上
二、安装
1、解压redis安装包:tar -zxvf redis-3.2.9.tar.gz
2、编译:
cd redis-3.2.9
make
3、安装:
make install PREFIX=/usr/local/redis
最后,查看Redis是否安装成功,进入/usr/local/redis
使用ll命令,可以看到bin文件夹,说明Redis已经安装成功。
三、主从模式配置
在/usr/local/redis/ 中新建redis.conf配置文件:
bind 0.0.0.0protected-mode noport 6379logfile "/root/redis/redis.log" #数据文件pidfile "redis.pid"masterauth "123456789" #密码requirepass "123456789"tcp-backlog 511timeout 0tcp-keepalive 300daemonize yes supervised nologlevel noticedatabases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdir "/home/oas/cluster2"slave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100appendonly noappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes
使用如下命令启动redis服务:
redis-server /usr/local/redis/redis.conf
动态改变主从关系,成为127.0.0.1的slave:
登录127.0.0.2机器:redis-cli -h 127.0.0.2 -p 6379127.0.0.2:6379> slaveof 127.0.0.1 6379登录127.0.0.3机器:redis-cli -h 127.0.0.3 -p 6379127.0.0.3:6379> slaveof 127.0.0.1 6379
设置完成后开通防火墙端口:
登录127.0.0.1机器:redis-cli -h 127.0.0.1 -p 6379127.0.0.2:6379> info #查看主从关系
四、sentinel模式集群管理配置
到/usr/local/redis/ 中创建sentinel.conf文件:
port 26379daemonize yeslogfile "sentinel.log"dir "/root/redis"protected-mode nosentinel monitor mymaster 127.0.0.1 6379 1sentinel auth-pass mymaster 123456789
使用如下命令启动sentinel模式:
redis-sentinel sentinel.conf