配置过程概述
- 配置开启主从节点;
- 配置开启 sentinel 监控主节点(sentinel 是特殊的 redis);
- 实际应该是多台机器,试验只在一台机器;
一主两从集群配置
[root@redis3_0_7 redis]# cd /opt/soft/redis/config/
[root@redis3_0_7 redis]# vim redis-7000.conf
port 7000
daemonize yes
pidfile /var/run/redis-7000.pid
logfile "7000.log"
dir "/opt/soft/redis/redis/data/"
[root@redis3_0_7 config]# sed "s/7000/7001/g" redis-7000.conf > redis-7001.conf
[root@redis3_0_7 config]# sed "s/7000/7002/g" redis-7000.conf > redis-7002.conf
[root@redis3_0_7 config]# echo "slaveof 127.0.0.1 7000" >> redis-7001.conf
[root@redis3_0_7 config]# echo "slaveof 127.0.0.1 7000" >> redis-7002.conf
[root@redis3_0_7 config]# redis-server redis-7000.conf
[root@redis3_0_7 config]# redis-cli -p 7000 ping
PONG
[root@redis3_0_7 config]# redis-server redis-7001.conf
[root@redis3_0_7 config]# redis-server redis-7002.conf
[root@redis3_0_7 config]# ps -ef|grep redis
root 155 1 0 13:09 ? 00:00:00 redis-server *:7000
root 160 1 0 13:10 ? 00:00:00 redis-server *:7001
root 165 1 0 13:10 ? 00:00:00 redis-server *:7002
root 170 7 0 13:11 pts/1 00:00:00 grep --color=auto redis
[root@redis3_0_7 config]# redis-cli -p 7000 info replication
# Replication
role:master
connected_slaves:2
slave0:ip=127.0.0.1,port=7001,state=online,offset=183,lag=0
slave1:ip=127.0.0.1,port=7002,state=online,offset=183,lag=0
master_repl_offset:183
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:182
sentinel 集群配置
[root@redis3_0_7 redis]# cd /opt/soft/redis/
[root@redis3_0_7 redis]# cp sentinel.conf config/
[root@redis3_0_7 redis]# cd config/
[root@redis3_0_7 config]# cat sentinel.conf | grep -v "#" | grep -v "^$" > redis-sentinel-26379.conf
[root@redis3_0_7 config]# vim redis-sentinel-26379.conf
port 26379
daemonize yes
dir /opt/soft/redis/redis/data/
logfile "26379.log"
sentinel monitor mymaster 127.0.0.1 7000 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
[root@redis3_0_7 config]# redis-sentinel redis-sentinel-26379.conf
[root@redis3_0_7 config]# ps -ef|grep redis-sentinel
root 186 1 0 13:29 ? 00:00:00 redis-sentinel *:26379 [sentinel]
root 190 7 0 13:29 pts/1 00:00:00 grep --color=auto redis-sentinel
[root@redis3_0_7 config]# redis-cli -p 26379
127.0.0.1:26379> info
# Server
redis_version:3.0.7
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:d709ac81eddea5b3
redis_mode:sentinel
os:Linux 4.9.87-linuxkit-aufs x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:186
run_id:062369301ceb8135b780a48b2a579f041ebd03b0
tcp_port:26379
uptime_in_seconds:105
uptime_in_days:0
hz:11
lru_clock:14509577
config_file:/opt/soft/redis-3.0.7/config/redis-sentinel-26379.conf
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master0:name=mymaster,status=ok,address=127.0.0.1:7000,slaves=2,sentinels=1
127.0.0.1:26379> exit
[root@redis3_0_7 config]# cat redis-sentinel-26379.conf
port 26379
daemonize yes
dir "/opt/soft/redis-3.0.7/redis/data"
logfile "26379.log"
sentinel monitor mymaster 127.0.0.1 7000 2
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 127.0.0.1 7002
# Generated by CONFIG REWRITE
sentinel known-slave mymaster 127.0.0.1 7001
sentinel current-epoch 0
[root@redis3_0_7 config]# sed "s/26379/26380/g" redis-sentinel-26379.conf > redis-sentinel-26380.conf
[root@redis3_0_7 config]# sed "s/26379/26381/g" redis-sentinel-26379.conf > redis-sentinel-26381.conf
[root@redis3_0_7 config]# redis-sentinel redis-sentinel-26380.conf
[root@redis3_0_7 config]# redis-sentinel redis-sentinel-26381.conf
[root@redis3_0_7 config]# ps -ef | grep redis-sentinel
root 186 1 0 13:29 ? 00:00:01 redis-sentinel *:26379 [sentinel]
root 198 1 0 13:43 ? 00:00:00 redis-sentinel *:26380 [sentinel]
root 202 1 0 13:43 ? 00:00:00 redis-sentinel *:26381 [sentinel]
root 206 7 0 13:43 pts/1 00:00:00 grep --color=auto redis-sentinel
[root@redis3_0_7 config]# redis-cli -p 26381
127.0.0.1:26381> info
# Server
redis_version:3.0.7
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:d709ac81eddea5b3
redis_mode:sentinel
os:Linux 4.9.87-linuxkit-aufs x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:202
run_id:0120cece7bbd3c8c6ae3f7c8530e7608efda863e
tcp_port:26381
uptime_in_seconds:62
uptime_in_days:0
hz:16
lru_clock:14510388
config_file:/opt/soft/redis-3.0.7/config/redis-sentinel-26381.conf
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master0:name=mymaster,status=ok,address=127.0.0.1:7000,slaves=2,sentinels=3
[root@redis3_0_7 config]# redis-cli -p 26380 info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master0:name=mymaster,status=ok,address=127.0.0.1:7000,slaves=2,sentinels=3
版权声明:本文为weixin_33669968原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。