文章
问答
冒泡
centos7 Redis 哨兵模式,一主两从

1、redis 版本

redis-5.0.2.tar.gz

2、三台服务器

10.199.12.30     slave
10.199.12.33     slave
10.199.12.34     master


3、部署目录

/usr/local/redis-5.0.2/下

4、主从搭建,配置文件redis.conf

4.1、30服务器配置

bind 10.199.12.30     #换成本机
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile "/var/run/redis.pid"
loglevel notice
logfile "/var/log/redis/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 "/var/lib/redis"
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
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 "gxE"
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 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
requirepass "wdredis@2020"  #redis连接密码
masterauth "wdredis@2020"  #master主从密码

4.2、33服务器

bind 10.199.11.33
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile "/var/run/redis.pid"
loglevel notice
logfile "/var/log/redis/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 "/var/lib/redis"
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
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 ""
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 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
requirepass "wdredis@2020"
masterauth "wdredis@2020"

4.3、34服务器配置

bind 10.199.11.34
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile "/var/run/redis.pid"
loglevel notice
logfile "/var/log/redis/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 "/var/lib/redis"
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
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 ""
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 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
requirepass "wdredis@2020"
masterauth "wdredis@2020"

5、redis注册为系统服务,配置

vi /etc/systemd/system/redis.service
[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis-5.0.2/src/redis-server /usr/local/redis-5.0.2/redis.conf
ExecStop=/usr/local/redis-5.0.2/src/redis-cli -p 6379 -a wdredis@2020 SHUTDOWN
PrivateTmp=true

[Install]
WantedBy=multi-user.target

6、redis服务启动

systemctl restart redis
systemctl enable redis


7、哨兵模式部署

配置文件:sentinel.conf

7.1、30服务器配置

daemonize no
port 26379
protected-mode no
dir "/var/lib/sentinel"
sentinel myid 4cd15f45397310bab68d4c766b5453136f59dc23
sentinel deny-scripts-reconfig yes
logfile "/var/log/redis/sentinel.log"
# Generated by CONFIG REWRITE
supervised systemd
sentinel monitor redis-master 10.199.11.34 6379 2
sentinel auth-pass redis-master wdredis@2020

7.2、31配置

daemonize no
port 26379
protected-mode no
dir "/var/lib/sentinel"
sentinel myid 900176456f8925989d69be82b1d3d276727e9173
sentinel deny-scripts-reconfig yes
logfile "/var/log/redis/sentinel.log"
# Generated by CONFIG REWRITE
supervised systemd
sentinel monitor redis-master 10.199.11.34 6379 2
sentinel auth-pass redis-master wdredis@2020

7.3、34配置

daemonize no
port 26379
protected-mode no
dir "/var/lib/sentinel"
sentinel myid 1e813d9f7beb013f9a03c4debe19ae5e9cb0cffc
sentinel deny-scripts-reconfig yes
logfile "/var/log/redis/sentinel.log"
# Generated by CONFIG REWRITE
supervised systemd
sentinel monitor redis-master 10.199.11.34 6379 2
sentinel auth-pass redis-master wdredis@2020

8、哨兵模式注册为系统服务配置

vi /etc/systemd/system/redis-sentinel.service
[Unit]
Description=Sentinel for Redis
After=network.target
[Service]
LimitNOFILE=64000
ExecStart=/usr/local/redis-5.0.2/src/redis-sentinel /usr/local/redis-5.0.2/sentinel.conf  --supervised systemd
[Install]
WantedBy=multi-user.target


9、哨兵模式服务启动

systemctl enable redis-sentinel
systemctl start redis-sentinel


10、信息详解



哨兵模式集群名称:redis-master   服务启动端口:26379
redis连接密码:wdredis@2020









关于作者

Wade
No bald man, no god
获得点赞
文章被阅读