1
|
master |
10.80.39.140 |
|
|
slave1/sentinel1 |
10.80.39.141 |
|
|
slave2/sentinel2 |
10.80.39.142 |
|
|
slave3/sentinel3 |
10.80.39.143 |
配置主从
Step 1
cd /opt yum install -y gcc-c++ tar -zxvf redis-5.0.9.tar.bz cd redis make make install PREFIX=/opt/redis mkdir /opt/redis/data
Step 2
vim /etc/profile #行尾添加 export REDIS_HOME=/opt/redis export PATH=$PATH:$REDIS_HOME/bin source /etc/profile
Step 3
vim redis.conf #内容解析redis配置里面有讲 bind 127.0.0.1 10.80.39.140 protected-mode yes port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 60 daemonize yes supervised no pidfile "/var/run/redis_6379.pid" loglevel notice logfile "/var/log/redis.log" databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename "dump.rdb" dir "/opt/redis/data" masterauth "abc123," replica-serve-stale-data yes replica-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no replica-priority 100 requirepass "abc123," appendonly no appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes lua-time-limit 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "xE" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit replica 1gb 128mb 120 client-output-buffer-limit pubsub 32mb 8mb 60 repl-backlog-size 4mb hz 10 aof-rewrite-incremental-fsync yes #slaveof 192.168.1.19 6379
bind 127.0.0.1 10.80.39.141/142/143 protected-mode no port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 60 daemonize yes supervised no pidfile "/var/run/redis_6379.pid" loglevel notice logfile "/var/log/redis.log" databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename "dump.rdb" dir "/opt/redis/data" masterauth "abc123," replica-serve-stale-data yes replica-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no replica-priority 100 requirepass "abc123," appendonly no appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes lua-time-limit 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "xE" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit replica 1gb 128mb 120 client-output-buffer-limit pubsub 32mb 8mb 60 repl-backlog-size 4mb hz 10 aof-rewrite-incremental-fsync yes replicaof 10.80.39.140 6379
cat /etc/systemd/system/redis-server.service [Unit] Description=The redis-server Process Manager After=syslog.target network.target [Service] Type=forking PIDFile=/var/run/redis_6379.pid ExecStartPost=/bin/sleep 0.1 ExecStart=/opt/redis/bin/redis-server /opt/redis/redis.conf #这里要注意 配置文件路径 ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target systemctl daemon-reload systemctl start redis-server.service systemctl enable redis-server.service
Step 4
master: redis-cli -h 10.80.39.140 -p 6379 -a abc123, info replication Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Replication role:master connected_slaves:3 slave0:ip=10.80.39.143,port=6379,state=online,offset=381286,lag=0 slave1:ip=10.80.39.142,port=6379,state=online,offset=381147,lag=1 slave2:ip=10.80.39.141,port=6379,state=online,offset=381147,lag=1 master_replid:578dd7db87ab4c5023bffdaf1c914d429a2eeb24 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:381286 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:4194304 repl_backlog_first_byte_offset:1 repl_backlog_histlen:381286
配置哨兵
Step 1
vim sentinel.conf # 指定监控的主节点IP和端口 sentinel myid 573285c8f5feb43b00ac295d80690b06bb187c5a # # # 指定哨兵之间进行通信的端口 port 26379 # # # 指定哨兵之间进行通信的密码 sentinel deny-scripts-reconfig yes # # # 设定哨兵之间的心跳超时时间和哨兵主观下线超时时间 sentinel monitor mymaster 10.80.39.140 6379 2 sentinel down-after-milliseconds mymaster 5000 # # # 设置哨兵投票超时时间(默认30秒) sentinel auth-pass mymaster abc123, # # # 设置日志级别 loglevel notice # # # 设置日志文件位置 logfile "/var/log/sentinel.log" protected-mode no daemonize yes dir "/opt/redis/data" pidfile "/var/run/sentinel_26379.pid"
# 指定监控的主节点IP和端口 sentinel myid 573285c8f5feb43b00ac295d80690b06bb187c5a # # # 指定哨兵之间进行通信的端口 port 26379 # # # 指定哨兵之间进行通信的密码 sentinel deny-scripts-reconfig yes # # # 设定哨兵之间的心跳超时时间和哨兵主观下线超时时间 sentinel monitor mymaster 10.80.39.140 6379 2 sentinel down-after-milliseconds mymaster 5000 # # # 设置哨兵投票超时时间(默认30秒) sentinel auth-pass mymaster abc123, # # # 设置日志级别 loglevel notice # # # 设置日志文件位置 logfile "/var/log/sentinel.log" protected-mode no daemonize yes dir "/opt/redis/data" pidfile "/var/run/sentinel_26379.pid"
Step 2
redis-cli -c -h 10.80.39.140 -p 26379 -a abc123, sentinel master mymaster Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 1) "name" 2) "mymaster" 3) "ip" 4) "10.80.39.140" 5) "port" 6) "6379" 7) "runid" 8) "33986e5962ac8a61627768a7158f8627d3850e61" 9) "flags" 10) "master" 11) "link-pending-commands" 12) "0" 13) "link-refcount" 14) "1" 15) "last-ping-sent" 16) "0" 17) "last-ok-ping-reply" 18) "1" 19) "last-ping-reply" 20) "1" 21) "down-after-milliseconds" 22) "5000" 23) "info-refresh" 24) "8793" 25) "role-reported" 26) "master" 27) "role-reported-time" 28) "1745130" 29) "config-epoch" 30) "0" 31) "num-slaves" 32) "3" 33) "num-other-sentinels" 34) "2" 35) "quorum" 36) "2" 37) "failover-timeout" 38) "180000" 39) "parallel-syncs" 40) "1"
redis-cli -c -h 10.80.39.140 -p 26379 -a abc123, sentinel slaves mymaster
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
1) 1) "name"
2) "10.80.39.143:6379"
3) "ip"
4) "10.80.39.143"
5) "port"
6) "6379"
7) "runid"
8) "35218febbb092ad1d76304c169aa425ea2d2453b"
9) "flags"
10) "slave"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "345"
19) "last-ping-reply"
20) "345"
21) "down-after-milliseconds"
22) "5000"
23) "info-refresh"
24) "6002"
25) "role-reported"
26) "slave"
27) "role-reported-time"
28) "1872899"
29) "master-link-down-time"
30) "0"
31) "master-link-status"
32) "ok"
33) "master-host"
34) "10.80.39.140"
35) "master-port"
36) "6379"
37) "slave-priority"
38) "100"
39) "slave-repl-offset"
40) "509824"
2) 1) "name"
2) "10.80.39.141:6379"
3) "ip"
4) "10.80.39.141"
5) "port"
6) "6379"
7) "runid"
8) "ef217189a3e8432b90e9487198fea03ef13e0645"
9) "flags"
10) "slave"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "345"
19) "last-ping-reply"
20) "345"
21) "down-after-milliseconds"
22) "5000"
23) "info-refresh"
24) "6002"
25) "role-reported"
26) "slave"
27) "role-reported-time"
28) "1872899"
29) "master-link-down-time"
30) "0"
31) "master-link-status"
32) "ok"
33) "master-host"
34) "10.80.39.140"
35) "master-port"
36) "6379"
37) "slave-priority"
38) "100"
39) "slave-repl-offset"
40) "509824"
3) 1) "name"
2) "10.80.39.142:6379"
3) "ip"
4) "10.80.39.142"
5) "port"
6) "6379"
7) "runid"
8) "4415a11c40eca3aae21e41012508926be499bd1f"
9) "flags"
10) "slave"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "345"
19) "last-ping-reply"
20) "345"
21) "down-after-milliseconds"
22) "5000"
23) "info-refresh"
24) "6002"
25) "role-reported"
26) "slave"
27) "role-reported-time"
28) "1872899"
29) "master-link-down-time"
30) "0"
31) "master-link-status"
32) "ok"
33) "master-host"
34) "10.80.39.140"
35) "master-port"
36) "6379"
37) "slave-priority"
38) "100"
39) "slave-repl-offset"
40) "509824"
Step 3 至此四台机器 一主三从 三哨兵配置完毕
redis-cli -c -h 10.80.39.140 -p 26379 -a abc123, info sentinel Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Sentinel sentinel_masters:1 sentinel_tilt:0 sentinel_running_scripts:0 sentinel_scripts_queue_length:0 sentinel_simulate_failure_flags:0 master0:name=mymaster,status=ok,address=10.80.39.140:6379,slaves=3,sentinels=3
浙公网安备 33010602011771号